Vmeda.Online/src/app/app.component.test.ts

68 lines
2.4 KiB
TypeScript
Raw Normal View History

// (C) Copyright 2015 Moodle Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-11-18 12:17:30 +00:00
import { Observable } from 'rxjs';
2020-10-26 15:54:14 +00:00
import { NavController } from '@ionic/angular';
import { AppComponent } from '@/app/app.component';
2020-11-24 09:35:15 +00:00
import { CoreApp } from '@services/app';
import { CoreEvents } from '@singletons/events';
import { CoreLangProvider } from '@services/lang';
import { Network, Platform, NgZone } from '@singletons';
import { mock, mockSingleton, renderComponent, RenderConfig } from '@/testing/utils';
2020-10-26 15:54:14 +00:00
describe('AppComponent', () => {
2020-10-22 10:34:00 +00:00
let langProvider: CoreLangProvider;
2020-10-26 15:54:14 +00:00
let navController: NavController;
let config: Partial<RenderConfig>;
2020-10-22 10:34:00 +00:00
beforeEach(() => {
2020-11-24 09:35:15 +00:00
mockSingleton(CoreApp, { setStatusBarColor: jest.fn() });
2020-11-18 12:17:30 +00:00
mockSingleton(Network, { onChange: () => new Observable() });
mockSingleton(Platform, { ready: () => Promise.resolve() });
mockSingleton(NgZone, { run: jest.fn() });
langProvider = mock<CoreLangProvider>(['clearCustomStrings']);
2020-10-26 15:54:14 +00:00
navController = mock<NavController>(['navigateRoot']);
config = {
providers: [
{ provide: CoreLangProvider, useValue: langProvider },
2020-10-26 15:54:14 +00:00
{ provide: NavController, useValue: navController },
],
};
2020-10-22 10:34:00 +00:00
});
it('should render', async () => {
const fixture = await renderComponent(AppComponent, config);
expect(fixture.debugElement.componentInstance).toBeTruthy();
expect(fixture.nativeElement.querySelector('ion-router-outlet')).toBeTruthy();
});
2020-10-26 15:54:14 +00:00
it('cleans up on logout', async () => {
const fixture = await renderComponent(AppComponent, config);
2020-10-22 10:34:00 +00:00
fixture.componentInstance.ngOnInit();
CoreEvents.trigger(CoreEvents.LOGOUT);
2020-10-22 10:34:00 +00:00
expect(langProvider.clearCustomStrings).toHaveBeenCalled();
2020-10-26 15:54:14 +00:00
expect(navController.navigateRoot).toHaveBeenCalledWith('/login/sites');
2020-10-22 10:34:00 +00:00
});
it.todo('shows loading while app isn\'t ready');
});