diff --git a/src/app/app.component.test.ts b/src/app/app.component.test.ts index dd2ac8283..ad9cbd815 100644 --- a/src/app/app.component.test.ts +++ b/src/app/app.component.test.ts @@ -12,13 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { createComponent, prepareComponentTest } from '@/tests/utils'; +import { createComponent, createMock, prepareComponentTest } from '@/tests/utils'; import { AppComponent } from '@app/app.component'; +import { CoreLangProvider } from '@services/lang'; +import { CoreEvents, CoreEventsProvider } from '@services/events'; describe('App component', () => { - beforeEach(() => prepareComponentTest(AppComponent)); + let langProvider: CoreLangProvider; + + beforeEach(() => { + langProvider = createMock(['clearCustomStrings']); + + CoreEvents.setInstance(new CoreEventsProvider()); + prepareComponentTest(AppComponent, [ + { provide: CoreLangProvider, useValue: langProvider }, + ]); + }); it('should render', () => { const fixture = createComponent(AppComponent); @@ -27,4 +38,13 @@ describe('App component', () => { expect(fixture.nativeElement.querySelector('ion-router-outlet')).toBeTruthy(); }); + it('clears custom strings on logout', async () => { + const fixture = createComponent(AppComponent); + + fixture.componentInstance.ngOnInit(); + CoreEvents.instance.trigger(CoreEventsProvider.LOGOUT); + + expect(langProvider.clearCustomStrings).toHaveBeenCalled(); + }); + }); diff --git a/src/app/core/login/tests/init.page.test.ts b/src/app/core/login/tests/init.page.test.ts index fad3fed51..f5ddfce3c 100644 --- a/src/app/core/login/tests/init.page.test.ts +++ b/src/app/core/login/tests/init.page.test.ts @@ -38,13 +38,13 @@ describe('CoreLogin Init Page', () => { expect(fixture.nativeElement.querySelector('ion-spinner')).toBeTruthy(); }); - it('navigates to site page after loading', async () => { + it('navigates to sites page after loading', async () => { const fixture = createComponent(CoreLoginInitPage); fixture.componentInstance.ngOnInit(); await CoreInit.instance.ready(); - expect(mocks.router.navigate).toHaveBeenCalledWith(['/login/site']); + expect(mocks.navController.navigateRoot).toHaveBeenCalledWith('/login/sites'); }); }); diff --git a/src/app/singletons/logger.ts b/src/app/singletons/logger.ts index 0c49642f0..fab03132b 100644 --- a/src/app/singletons/logger.ts +++ b/src/app/singletons/logger.ts @@ -56,10 +56,12 @@ export class CoreLogger { * @return Instance. */ static getInstance(className: string): CoreLogger { - // Disable log on production. - if (CoreConstants.BUILD.isProduction) { - // eslint-disable-next-line no-console - console.warn('Log is disabled in production app'); + // Disable log on production and testing. + if (CoreConstants.BUILD.isProduction || CoreConstants.BUILD.isTesting) { + if (CoreConstants.BUILD.isProduction) { + // eslint-disable-next-line no-console + console.warn('Log is disabled in production app'); + } // eslint-disable-next-line @typescript-eslint/no-empty-function const muted = () => {}; diff --git a/src/tests/utils.ts b/src/tests/utils.ts index 6747a41df..9adc3bdd6 100644 --- a/src/tests/utils.ts +++ b/src/tests/utils.ts @@ -14,7 +14,7 @@ import { CUSTOM_ELEMENTS_SCHEMA, Type } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; +import { NavController } from '@ionic/angular'; import { CoreSingletonClass } from '@app/classes/singletons-factory'; export interface ComponentTestMocks { @@ -22,7 +22,7 @@ export interface ComponentTestMocks { }; export interface PageTestMocks extends ComponentTestMocks { - router: Router; + navController: NavController; } export function createMock(methods: string[] = [], properties: Record = {}): T { @@ -57,12 +57,12 @@ export async function prepareComponentTest(component: Type, providers: unk export async function preparePageTest(component: Type, providers: unknown[] = []): Promise { const mocks = { - router: createMock(['navigate']), + navController: createMock(['navigateRoot']), }; const componentTestMocks = await prepareComponentTest(component, [ ...providers, - { provide: Router, useValue: mocks.router }, + { provide: NavController, useValue: mocks.navController }, ]); return { diff --git a/src/types/global.d.ts b/src/types/global.d.ts index 82c412499..26369b55c 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -69,8 +69,9 @@ declare global { }; BUILD: { - environment: string; isProduction: boolean; + isTesting: boolean; + isDevelopment: boolean; lastCommitHash: string; compilationTime: number; };