app.component.spec.ts 2.83 KB
Newer Older
1 2
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {TestBed, async} from '@angular/core/testing';
3

4 5 6
import {MenuController, Platform} from '@ionic/angular';
import {SplashScreen} from '@ionic-native/splash-screen/ngx';
import {StatusBar} from '@ionic-native/status-bar/ngx';
7

8 9 10 11 12 13 14
import {AppComponent} from './app.component';
import {HttpClientModule} from '@angular/common/http';
import {IonicStorageModule} from '@ionic/storage';
import {AppRoutingModule} from './app-routing.module';
import {TranslateTestingModule} from './translate-testing/translate-testing.module';
import {APP_BASE_HREF} from '@angular/common';
import {Subscription} from 'rxjs';
15 16
import {HelperService} from './helper.service';
import MockMC from './models/mock';
17 18

describe('AppComponent', () => {
19 20 21 22 23 24 25
    class PlatformStub {
        backButton = {
            subscribeWithPriority(priority: number, callback: () => (Promise<any> | void)): Subscription {
                return Subscription.EMPTY;
            }
        };
        wasReadyCalled = false;
26

27 28 29 30 31 32
        public ready(): Promise<any> {
            this.wasReadyCalled = true;
            return Promise.resolve();
        }
    }

33
    let statusBarSpy, splashScreenSpy, platformReadySpy, fixture;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    beforeEach(async(() => {
        platformReadySpy = Promise.resolve();
        statusBarSpy = jasmine.createSpyObj('StatusBar', ['styleDefault']);
        splashScreenSpy = jasmine.createSpyObj('SplashScreen', ['hide']);
        TestBed.configureTestingModule({
            declarations: [AppComponent],
            imports: [
                AppRoutingModule,
                HttpClientModule,
                IonicStorageModule.forRoot({name: 'mc_db', driverOrder: ['indexeddb', 'websql', 'localstorage']}),
                TranslateTestingModule
            ],
            schemas: [CUSTOM_ELEMENTS_SCHEMA],
            providers: [
                {provide: StatusBar, useValue: statusBarSpy},
                {provide: SplashScreen, useValue: splashScreenSpy},
                {provide: Platform, useClass: PlatformStub},
                {provide: APP_BASE_HREF, useValue: '/'},
                {provide: MenuController}
            ],
        }).compileComponents();
55 56
        spyOn(HelperService, 'makeGetRequest').and.returnValue(Promise.resolve(MockMC.apiResponseCorporaGet));
        fixture = TestBed.createComponent(AppComponent);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    }));

    it('should create the app', () => {
        const app = fixture.debugElement.componentInstance;
        expect(app).toBeTruthy();
    });

    it('should initialize the app', async () => {
        const platformStub: PlatformStub = TestBed.get(Platform);
        expect(platformStub.wasReadyCalled).toBeTruthy();
        await platformReadySpy;
        expect(statusBarSpy.styleDefault).toHaveBeenCalled();
        expect(splashScreenSpy.hide).toHaveBeenCalled();
    });

    // TODO: add more tests!
73 74

});