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-19 11:40:18 +00:00
|
|
|
import { AppComponent } from '@/app/app.component';
|
2020-10-22 10:48:23 +00:00
|
|
|
import { CoreEvents } from '@singletons/events';
|
2021-02-02 17:41:58 +00:00
|
|
|
import { CoreLang, CoreLangProvider } from '@services/lang';
|
2020-10-26 12:20:00 +00:00
|
|
|
|
2021-02-02 17:41:58 +00:00
|
|
|
import { mockSingleton, renderComponent } from '@/testing/utils';
|
2021-01-21 14:24:45 +00:00
|
|
|
import { CoreNavigator, CoreNavigatorService } from '@services/navigator';
|
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;
|
2021-01-21 14:24:45 +00:00
|
|
|
let navigator: CoreNavigatorService;
|
2020-10-22 10:34:00 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-01-21 14:24:45 +00:00
|
|
|
navigator = mockSingleton(CoreNavigator, ['navigate']);
|
2021-02-02 17:41:58 +00:00
|
|
|
langProvider = mockSingleton(CoreLang, ['clearCustomStrings']);
|
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 () => {
|
2021-02-02 17:41:58 +00:00
|
|
|
const fixture = await renderComponent(AppComponent);
|
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 () => {
|
2021-02-02 17:41:58 +00:00
|
|
|
const fixture = await renderComponent(AppComponent);
|
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();
|
2021-01-21 14:24:45 +00:00
|
|
|
expect(navigator.navigate).toHaveBeenCalledWith('/login/sites', { reset: true });
|
2020-10-22 10:34:00 +00:00
|
|
|
});
|
|
|
|
|
2020-10-06 07:44:27 +00:00
|
|
|
});
|