diff --git a/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts index d7bae11a51..1b20a2889b 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts @@ -1,14 +1,122 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { ConfigStateService } from '../services/config-state.service'; import { ConfigState } from '../states'; import { Store } from '@ngxs/store'; +import { Config } from '../models/config'; + +const CONFIG_STATE_DATA = { + environment: { + production: false, + application: { + name: 'MyProjectName', + }, + oAuthConfig: { + issuer: 'https://localhost:44305', + }, + apis: { + default: { + url: 'https://localhost:44305', + }, + other: { + url: 'https://localhost:44306', + }, + }, + localization: { + defaultResourceName: 'MyProjectName', + }, + }, + requirements: { + layouts: [null, null, null], + }, + routes: [ + { + name: '::Menu:Home', + path: '', + children: [], + url: '/', + }, + { + name: 'AbpAccount::Menu:Account', + path: 'account', + invisible: true, + layout: 'application', + children: [ + { + path: 'login', + name: 'AbpAccount::Login', + order: 1, + url: '/account/login', + }, + ], + url: '/account', + }, + ], + flattedRoutes: [ + { + name: '::Menu:Home', + path: '', + children: [], + url: '/', + }, + { + name: '::Menu:Identity', + path: 'identity', + children: [], + url: '/identity', + }, + ], + localization: { + values: { + MyProjectName: { + "'{0}' and '{1}' do not match.": "'{0}' and '{1}' do not match.", + }, + AbpIdentity: { + Identity: 'identity', + }, + }, + languages: [ + { + cultureName: 'cs', + uiCultureName: 'cs', + displayName: 'Čeština', + flagIcon: null, + }, + ], + }, + auth: { + policies: { + 'AbpIdentity.Roles': true, + }, + grantedPolicies: { + 'Abp.Identity': false, + }, + }, + setting: { + values: { + 'Abp.Localization.DefaultLanguage': 'en', + }, + }, + currentUser: { + isAuthenticated: false, + id: null, + tenantId: null, + userName: null, + }, + features: { + values: {}, + }, +} as Config.State; + describe('ConfigStateService', () => { let service: ConfigStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: ConfigStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); test('should have the all ConfigState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; @@ -16,6 +124,20 @@ describe('ConfigStateService', () => { .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = ConfigState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + ConfigState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(ConfigState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(ConfigState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts index 4cd7016aca..3732d8000c 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts @@ -1,14 +1,17 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { ProfileStateService } from '../services/profile-state.service'; import { ProfileState } from '../states/profile.state'; import { Store } from '@ngxs/store'; describe('ProfileStateService', () => { let service: ProfileStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: ProfileStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); test('should have the all ProfileState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; @@ -16,6 +19,20 @@ describe('ProfileStateService', () => { .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = ProfileState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + ProfileState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(ProfileState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(ProfileState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts index aa76e9fccf..40664f29b5 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts @@ -1,14 +1,17 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { SessionStateService } from '../services/session-state.service'; import { SessionState } from '../states/session.state'; import { Store } from '@ngxs/store'; describe('SessionStateService', () => { let service: SessionStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: SessionStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); test('should have the all SessionState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; @@ -16,6 +19,20 @@ describe('SessionStateService', () => { .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = SessionState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + SessionState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(SessionState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(SessionState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts b/npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts index 0463fccf8f..9e04806b7e 100644 --- a/npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts +++ b/npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts @@ -1,4 +1,4 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { Store } from '@ngxs/store'; import { FeatureManagementStateService } from '../services/feature-management-state.service'; import { FeatureManagementState } from '../states'; @@ -6,17 +6,35 @@ import { FeatureManagementState } from '../states'; describe('FeatureManagementStateService', () => { let service: FeatureManagementStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: FeatureManagementStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); + test('should have the all FeatureManagementState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; FeatureManagementState.toString() .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = FeatureManagementState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + FeatureManagementState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(FeatureManagementState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(FeatureManagementState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts b/npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts index 393aaeabf5..6d78aa950f 100644 --- a/npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts +++ b/npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts @@ -1,21 +1,39 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { IdentityStateService } from '../services/identity-state.service'; import { IdentityState } from '../states/identity.state'; import { Store } from '@ngxs/store'; describe('IdentityStateService', () => { let service: IdentityStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: IdentityStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); + test('should have the all IdentityState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; IdentityState.toString() .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = IdentityState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + IdentityState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(IdentityState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(IdentityState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts b/npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts index 190e670b8e..65df916a0f 100644 --- a/npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts +++ b/npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts @@ -1,14 +1,18 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { PermissionManagementStateService } from '../services/permission-management-state.service'; import { PermissionManagementState } from '../states/permission-management.state'; import { Store } from '@ngxs/store'; + describe('PermissionManagementStateService', () => { let service: PermissionManagementStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: PermissionManagementStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); test('should have the all PermissionManagementState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; @@ -16,6 +20,20 @@ describe('PermissionManagementStateService', () => { .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = PermissionManagementState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + PermissionManagementState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(PermissionManagementState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(PermissionManagementState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts b/npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts index 1b45597075..c5b40fb54b 100644 --- a/npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts +++ b/npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts @@ -1,21 +1,39 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { TenantManagementStateService } from '../services/tenant-management-state.service'; import { TenantManagementState } from '../states/tenant-management.state'; import { Store } from '@ngxs/store'; describe('TenantManagementStateService', () => { let service: TenantManagementStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: TenantManagementStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); + test('should have the all TenantManagementState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; TenantManagementState.toString() .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = TenantManagementState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + TenantManagementState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(TenantManagementState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(TenantManagementState[fnName]); + } }); }); }); diff --git a/npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts b/npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts index ccdb512c65..2a88a93f47 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts @@ -1,21 +1,39 @@ -import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest'; +import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; import { LayoutStateService } from '../services/layout-state.service'; import { LayoutState } from '../states/layout.state'; import { Store } from '@ngxs/store'; describe('LayoutStateService', () => { let service: LayoutStateService; let spectator: SpectatorService; + let store: SpyObject; + const createService = createServiceFactory({ service: LayoutStateService, mocks: [Store] }); beforeEach(() => { spectator = createService(); service = spectator.service; + store = spectator.get(Store); }); + test('should have the all LayoutState static methods', () => { const reg = /(?<=static )(.*)(?=\()/gm; LayoutState.toString() .match(reg) .forEach(fnName => { expect(service[fnName]).toBeTruthy(); + + const spy = jest.spyOn(store, 'selectSnapshot'); + spy.mockClear(); + + const isDynamicSelector = LayoutState[fnName].name !== 'memoized'; + + if (isDynamicSelector) { + LayoutState[fnName] = jest.fn((...args) => args); + service[fnName]('test', 0, {}); + expect(LayoutState[fnName]).toHaveBeenCalledWith('test', 0, {}); + } else { + service[fnName](); + expect(spy).toHaveBeenCalledWith(LayoutState[fnName]); + } }); }); });