Browse Source

test(core): fix testing errors

pull/3821/head
mehmet-erim 7 years ago
parent
commit
91f1b6982b
  1. 12
      npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts
  2. 3
      npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts
  3. 7
      npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts
  4. 4
      npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts

12
npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts

@ -7,6 +7,7 @@ import { ABP } from '../models';
import { Config } from '../models/config'; import { Config } from '../models/config';
import { ApplicationConfigurationService, ConfigStateService } from '../services'; import { ApplicationConfigurationService, ConfigStateService } from '../services';
import { ConfigState } from '../states'; import { ConfigState } from '../states';
import { HttpClient } from '@angular/common/http';
export const CONFIG_STATE_DATA = { export const CONFIG_STATE_DATA = {
environment: { environment: {
@ -136,19 +137,17 @@ describe('ConfigState', () => {
let store: SpyObject<Store>; let store: SpyObject<Store>;
let service: ConfigStateService; let service: ConfigStateService;
let state: ConfigState; let state: ConfigState;
let appConfigService: SpyObject<ApplicationConfigurationService>;
const createService = createServiceFactory({ const createService = createServiceFactory({
service: ConfigStateService, service: ConfigStateService,
mocks: [ApplicationConfigurationService, Store], mocks: [ApplicationConfigurationService, Store, HttpClient],
}); });
beforeEach(() => { beforeEach(() => {
spectator = createService(); spectator = createService();
store = spectator.get(Store); store = spectator.get(Store);
service = spectator.service; service = spectator.service;
appConfigService = spectator.get(ApplicationConfigurationService); state = new ConfigState(spectator.get(HttpClient), store);
state = new ConfigState(spectator.get(ApplicationConfigurationService), store);
}); });
describe('#getAll', () => { describe('#getAll', () => {
@ -283,7 +282,7 @@ describe('ConfigState', () => {
}); });
describe('#GetAppConfiguration', () => { describe('#GetAppConfiguration', () => {
it('should call the getConfiguration of ApplicationConfigurationService and patch the state', done => { it('should call the app-configuration API and patch the state', done => {
let patchStateArg; let patchStateArg;
let dispatchArg; let dispatchArg;
@ -299,7 +298,8 @@ describe('ConfigState', () => {
dispatchArg = a; dispatchArg = a;
return of(a); return of(a);
}); });
appConfigService.getConfiguration.andReturn(res$); const httpClient = spectator.get(HttpClient);
httpClient.get.andReturn(res$);
state.addData({ patchState, dispatch } as any).subscribe(); state.addData({ patchState, dispatch } as any).subscribe();

3
npm/ng-packs/packages/core/src/lib/tests/dynamic-layout.component.spec.ts

@ -7,6 +7,7 @@ import { eLayoutType } from '../enums';
import { ABP } from '../models'; import { ABP } from '../models';
import { ConfigState, ReplaceableComponentsState } from '../states'; import { ConfigState, ReplaceableComponentsState } from '../states';
import { ApplicationConfigurationService } from '../services'; import { ApplicationConfigurationService } from '../services';
import { HttpClient } from '@angular/common/http';
@Component({ @Component({
selector: 'abp-layout-application', selector: 'abp-layout-application',
@ -92,7 +93,7 @@ describe('DynamicLayoutComponent', () => {
component: RouterOutletComponent, component: RouterOutletComponent,
stubsEnabled: false, stubsEnabled: false,
declarations: [DummyComponent, DynamicLayoutComponent], declarations: [DummyComponent, DynamicLayoutComponent],
mocks: [ApplicationConfigurationService], mocks: [ApplicationConfigurationService, HttpClient],
imports: [ imports: [
RouterModule, RouterModule,
DummyLayoutModule, DummyLayoutModule,

7
npm/ng-packs/packages/core/src/lib/tests/localization.service.spec.ts

@ -1,7 +1,7 @@
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store'; import { Store, Actions } from '@ngxs/store';
import { Observable, of } from 'rxjs'; import { Observable, of, Subject } from 'rxjs';
import { LocalizationService } from '../services/localization.service'; import { LocalizationService } from '../services/localization.service';
describe('LocalizationService', () => { describe('LocalizationService', () => {
@ -13,6 +13,7 @@ describe('LocalizationService', () => {
service: LocalizationService, service: LocalizationService,
entryComponents: [], entryComponents: [],
mocks: [Store, Router], mocks: [Store, Router],
providers: [{ provide: Actions, useValue: new Subject() }],
}); });
beforeEach(() => { beforeEach(() => {
@ -74,7 +75,7 @@ describe('LocalizationService', () => {
it('should throw an error message when service have an otherInstance', async () => { it('should throw an error message when service have an otherInstance', async () => {
try { try {
const instance = new LocalizationService(null, null, null, {} as any); const instance = new LocalizationService(new Subject(), null, null, null, {} as any);
} catch (error) { } catch (error) {
expect((error as Error).message).toBe('LocalizationService should have only one instance.'); expect((error as Error).message).toBe('LocalizationService should have only one instance.');
} }

4
npm/ng-packs/packages/core/src/lib/tests/session.state.spec.ts

@ -25,7 +25,7 @@ describe('SessionState', () => {
beforeEach(() => { beforeEach(() => {
spectator = createService(); spectator = createService();
state = new SessionState(spectator.get(LocalizationService), null, null, new Subject()); state = new SessionState(null, null, new Subject());
}); });
describe('#getLanguage', () => { describe('#getLanguage', () => {
@ -49,13 +49,11 @@ describe('SessionState', () => {
dispatchedData = action; dispatchedData = action;
return of({}); return of({});
}); });
const spy = jest.spyOn(spectator.get(LocalizationService), 'registerLocale');
state.setLanguage({ patchState, dispatch } as any, { payload: 'en' }).subscribe(); state.setLanguage({ patchState, dispatch } as any, { payload: 'en' }).subscribe();
expect(patchedData).toEqual({ language: 'en' }); expect(patchedData).toEqual({ language: 'en' });
expect(dispatchedData instanceof GetAppConfiguration).toBeTruthy(); expect(dispatchedData instanceof GetAppConfiguration).toBeTruthy();
expect(spy).toHaveBeenCalledWith('en');
}); });
}); });

Loading…
Cancel
Save