tests: cover state services

pull/2019/head
mehmet-erim 5 years ago
parent 690b18debf
commit 0d650cfccd

@ -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<ConfigStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<ProfileStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<SessionStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<FeatureManagementStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<IdentityStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<PermissionManagementStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<TenantManagementStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

@ -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<LayoutStateService>;
let store: SpyObject<Store>;
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]);
}
});
});
});

Loading…
Cancel
Save