2020-10-06 07:44:27 +00:00
|
|
|
// (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';
|
|
|
|
|
2020-10-06 07:44:27 +00:00
|
|
|
import { AppComponent } from '@app/app.component';
|
2020-10-22 10:48:23 +00:00
|
|
|
import { CoreEvents } from '@singletons/events';
|
2020-10-26 12:20:00 +00:00
|
|
|
import { CoreLangProvider } from '@services/lang';
|
2020-11-18 12:17:30 +00:00
|
|
|
import { Network, Platform, NgZone } from '@singletons/core.singletons';
|
2020-10-26 12:20:00 +00:00
|
|
|
|
2020-11-18 12:17:30 +00:00
|
|
|
import { mock, mockSingleton, renderComponent, RenderConfig } from '@/tests/utils';
|
2020-10-06 07:44:27 +00:00
|
|
|
|
2020-10-26 15:54:14 +00:00
|
|
|
describe('AppComponent', () => {
|
2020-10-06 07:44:27 +00:00
|
|
|
|
2020-10-22 10:34:00 +00:00
|
|
|
let langProvider: CoreLangProvider;
|
2020-10-26 15:54:14 +00:00
|
|
|
let navController: NavController;
|
2020-10-26 12:20:00 +00:00
|
|
|
let config: Partial<RenderConfig>;
|
2020-10-22 10:34:00 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2020-11-18 12:17:30 +00:00
|
|
|
mockSingleton(Network, { onChange: () => new Observable() });
|
|
|
|
mockSingleton(Platform, { ready: () => Promise.resolve() });
|
|
|
|
mockSingleton(NgZone, { run: jest.fn() });
|
|
|
|
|
2020-10-26 12:20:00 +00:00
|
|
|
langProvider = mock<CoreLangProvider>(['clearCustomStrings']);
|
2020-10-26 15:54:14 +00:00
|
|
|
navController = mock<NavController>(['navigateRoot']);
|
2020-10-26 12:20:00 +00:00
|
|
|
config = {
|
|
|
|
providers: [
|
|
|
|
{ provide: CoreLangProvider, useValue: langProvider },
|
2020-10-26 15:54:14 +00:00
|
|
|
{ provide: NavController, useValue: navController },
|
2020-10-26 12:20:00 +00:00
|
|
|
],
|
|
|
|
};
|
2020-10-22 10:34:00 +00:00
|
|
|
});
|
2020-10-06 07:44:27 +00:00
|
|
|
|
2020-10-26 12:20:00 +00:00
|
|
|
it('should render', async () => {
|
|
|
|
const fixture = await renderComponent(AppComponent, config);
|
2020-10-06 07:44:27 +00:00
|
|
|
|
|
|
|
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 () => {
|
2020-10-26 12:20:00 +00:00
|
|
|
const fixture = await renderComponent(AppComponent, config);
|
2020-10-22 10:34:00 +00:00
|
|
|
|
|
|
|
fixture.componentInstance.ngOnInit();
|
2020-10-22 10:48:23 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2020-11-02 12:58:18 +00:00
|
|
|
it.todo('shows loading while app isn\'t ready');
|
|
|
|
|
2020-10-06 07:44:27 +00:00
|
|
|
});
|