Browse Source

Tests fixed.

pull/355/head
Sebastian Stehle 7 years ago
parent
commit
073d630d88
  1. 2
      src/Squidex/app/features/administration/pages/restore/restore-page.component.ts
  2. 2
      src/Squidex/app/features/administration/state/users.state.spec.ts
  3. 2
      src/Squidex/app/features/schemas/pages/schema/schema-preview-urls-form.component.ts
  4. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  5. 2
      src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts
  6. 2
      src/Squidex/app/features/settings/pages/patterns/pattern.component.ts
  7. 2
      src/Squidex/app/features/settings/pages/roles/role.component.ts
  8. 2
      src/Squidex/app/features/settings/pages/roles/roles-page.component.ts
  9. 7
      src/Squidex/app/framework/state.ts
  10. 2
      src/Squidex/app/shared/components/comments.component.ts
  11. 7
      src/Squidex/app/shared/services/app-languages.service.spec.ts
  12. 11
      src/Squidex/app/shared/services/app-languages.service.ts
  13. 2
      src/Squidex/app/shared/services/plans.service.spec.ts
  14. 52
      src/Squidex/app/shared/state/_test-helpers.ts
  15. 28
      src/Squidex/app/shared/state/assets.state.spec.ts
  16. 14
      src/Squidex/app/shared/state/backups.state.spec.ts
  17. 19
      src/Squidex/app/shared/state/clients.state.spec.ts
  18. 46
      src/Squidex/app/shared/state/comments.state.spec.ts
  19. 41
      src/Squidex/app/shared/state/contributors.state.spec.ts
  20. 4
      src/Squidex/app/shared/state/filter.state.spec.ts
  21. 29
      src/Squidex/app/shared/state/languages.state.spec.ts
  22. 12
      src/Squidex/app/shared/state/languages.state.ts
  23. 21
      src/Squidex/app/shared/state/patterns.state.spec.ts
  24. 33
      src/Squidex/app/shared/state/plans.state.spec.ts
  25. 19
      src/Squidex/app/shared/state/roles.state.spec.ts
  26. 14
      src/Squidex/app/shared/state/rule-events.state.spec.ts
  27. 40
      src/Squidex/app/shared/state/rules.state.spec.ts
  28. 36
      src/Squidex/app/shared/state/schemas.state.spec.ts
  29. 22
      src/Squidex/app/shared/state/ui.state.spec.ts

2
src/Squidex/app/features/administration/pages/restore/restore-page.component.ts

@ -51,7 +51,7 @@ export class RestorePageComponent extends ResourceOwner implements OnInit {
const value = this.restoreForm.submit();
if (value) {
this.restoreForm.submitCompleted({ url: '' });
this.restoreForm.submitCompleted();
this.backupsService.postRestore(value)
.subscribe(() => {

2
src/Squidex/app/features/administration/state/users.state.spec.ts

@ -177,7 +177,7 @@ describe('UsersState', () => {
const user_1 = usersState.snapshot.users.at(0);
expect(user_1.user.email).toEqual(request.email);
expect(user_1.user.displayName).toEqual(request.permissions);
expect(user_1.user.displayName).toEqual(request.displayName);
expect(user_1.user.permissions).toEqual(request.permissions);
expect(user_1).toBe(usersState.snapshot.selectedUser!);
});

2
src/Squidex/app/features/schemas/pages/schema/schema-preview-urls-form.component.ts

@ -46,7 +46,7 @@ export class SchemaPreviewUrlsFormComponent implements OnInit {
}
public cancelAdd() {
this.addForm.submitCompleted({ name: '', url: '' });
this.addForm.submitCompleted();
}
public add() {

2
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -77,7 +77,7 @@ export class SchemasPageComponent extends ResourceOwner implements OnInit {
try {
this.schemasState.addCategory(value.name);
} finally {
this.addCategoryForm.submitCompleted({ name: '' });
this.addCategoryForm.submitCompleted();
}
}
}

2
src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts

@ -99,7 +99,7 @@ export class ContributorsPageComponent implements OnInit {
this.contributorsState.assign(requestDto)
.subscribe(isCreated => {
this.assignContributorForm.submitCompleted({ user: '' });
this.assignContributorForm.submitCompleted();
if (isCreated) {
this.dialogs.notifyInfo('A new user with the entered email address has been created and assigned as contributor.');

2
src/Squidex/app/features/settings/pages/patterns/pattern.component.ts

@ -58,7 +58,7 @@ export class PatternComponent implements OnInit {
} else {
this.patternsState.create(value)
.subscribe(() => {
this.editForm.submitCompleted({ pattern: '', name: '' });
this.editForm.submitCompleted();
}, error => {
this.editForm.submitFailed(error);
});

2
src/Squidex/app/features/settings/pages/roles/role.component.ts

@ -85,7 +85,7 @@ export class RoleComponent implements OnChanges {
if (value) {
this.editForm.add(value.permission);
this.addPermissionForm.submitCompleted({ permission: '' });
this.addPermissionForm.submitCompleted();
this.addPermissionInput.focus();
}
}

2
src/Squidex/app/features/settings/pages/roles/roles-page.component.ts

@ -67,7 +67,7 @@ export class RolesPageComponent implements OnInit {
if (value) {
this.rolesState.add(value)
.subscribe(() => {
this.addRoleForm.submitCompleted({ name: '' });
this.addRoleForm.submitCompleted();
}, error => {
this.addRoleForm.submitFailed(error);
});

7
src/Squidex/app/framework/state.ts

@ -82,12 +82,7 @@ export class Form<T extends AbstractControl, V> {
this.state.next(_ => ({ submitted: false, error: null }));
this.enable();
if (newValue) {
this.setValue(newValue);
} else {
this.form.markAsPristine();
}
this.setValue(newValue);
}
public submitFailed(error?: string | ErrorDto) {

2
src/Squidex/app/shared/components/comments.component.ts

@ -69,7 +69,7 @@ export class CommentsComponent extends ResourceOwner implements OnInit {
if (value) {
this.state.create(value.text).pipe(onErrorResumeNext()).subscribe();
this.commentForm.submitCompleted({ text: '' });
this.commentForm.submitCompleted();
}
}

7
src/Squidex/app/shared/services/app-languages.service.spec.ts

@ -94,7 +94,12 @@ describe('AppLanguagesService', () => {
expect(req.request.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual(version.value);
req.flush({ iso2Code: 'de', englishName: 'German' });
req.flush({
iso2Code: 'de',
isMaster: false,
isOptional: false,
englishName: 'German'
});
expect(language!).toEqual(new AppLanguageDto('de', 'German', false, false, []));
}));

11
src/Squidex/app/shared/services/app-languages.service.ts

@ -20,6 +20,8 @@ import {
Versioned
} from '@app/framework';
import { LanguageDto } from './languages.service';
export class AppLanguagesDto extends Model<AppLanguagesDto> {
constructor(
public readonly languages: AppLanguageDto[],
@ -39,6 +41,15 @@ export class AppLanguageDto extends Model<AppLanguageDto> {
) {
super();
}
public static fromLanguage(language: LanguageDto, isMaster = false, isOptional = false, fallback: string[] = []) {
return new AppLanguageDto(
language.iso2Code,
language.englishName,
isMaster,
isOptional,
fallback);
}
}
export interface AddAppLanguageDto {

2
src/Squidex/app/shared/services/plans.service.spec.ts

@ -110,7 +110,7 @@ describe('PlansService', () => {
const req = httpMock.expectOne('http://service/p/api/apps/my-app/plan');
req.flush({ redirectUri: 'my-url' });
req.flush({ redirectUri: 'http://url' });
expect(req.request.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toBe(version.value);

52
src/Squidex/app/shared/state/_test-helpers.ts

@ -0,0 +1,52 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { of } from 'rxjs';
import { Mock } from 'typemoq';
import {
AppsState,
AuthService,
DateTime,
Version
} from './../';
const app = 'my-app';
const creation = DateTime.today().addDays(-2);
const creator = 'me';
const modified = DateTime.now().addDays(-1);
const modifier = 'now-me';
const now = DateTime.now();
const version = new Version('1');
const newVersion = new Version('2');
const appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
appsState.setup(x => x.selectedApp)
.returns(() => of(<any>{ name: app }));
const authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: modifier, token: modifier });
export const TestValues = {
app,
appsState,
authService,
creation,
creator,
modified,
modifier,
now,
newVersion,
userId: modifier,
version
};

28
src/Squidex/app/shared/state/assets.state.spec.ts

@ -9,25 +9,27 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
AssetDto,
AssetsDto,
AssetsService,
AssetsState,
DateTime,
DialogService,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('AssetsState', () => {
const app = 'my-app';
const creation = DateTime.today();
const creator = 'not-me';
const modified = DateTime.now();
const modifier = 'me';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
creation,
creator,
modified,
modifier,
newVersion,
version
} = TestValues;
const oldAssets = [
new AssetDto('id1', creator, creator, creation, creation, 'name1', 'hash1', 'type1', 1, 1, 'mime1', false, false, null, null, 'slug1', ['tag1', 'shared'], 'url1', version),
@ -35,18 +37,12 @@ describe('AssetsState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let assetsService: IMock<AssetsService>;
let assetsState: AssetsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
assetsService = Mock.ofType<AssetsService>();
assetsService.setup(x => x.getAssets(app, 30, 0, undefined, []))

14
src/Squidex/app/shared/state/backups.state.spec.ts

@ -10,7 +10,6 @@ import { onErrorResumeNext } from 'rxjs/operators';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
BackupDto,
BackupsService,
BackupsState,
@ -18,8 +17,13 @@ import {
DialogService
} from './../';
import { TestValues } from './_test-helpers';
describe('BackupsState', () => {
const app = 'my-app';
const {
app,
appsState
} = TestValues;
const oldBackups = [
new BackupDto('id1', DateTime.now(), null, 1, 1, 'Started'),
@ -27,18 +31,12 @@ describe('BackupsState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let backupsService: IMock<BackupsService>;
let backupsState: BackupsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
backupsService = Mock.ofType<BackupsService>();
backupsService.setup(x => x.getBackups(app))

19
src/Squidex/app/shared/state/clients.state.spec.ts

@ -9,20 +9,23 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
ClientDto,
ClientsDto,
ClientsService,
ClientsState,
DialogService,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('ClientsState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
newVersion,
version
} = TestValues;
const oldClients = [
new ClientDto('id1', 'name1', 'secret1'),
@ -30,18 +33,12 @@ describe('ClientsState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let clientsService: IMock<ClientsService>;
let clientsState: ClientsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
clientsService = Mock.ofType<ClientsService>();
clientsService.setup(x => x.getClients(app))

46
src/Squidex/app/shared/state/comments.state.spec.ts

@ -9,41 +9,39 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
CommentDto,
CommentsDto,
CommentsService,
CommentsState,
DateTime,
DialogService,
ImmutableArray,
Version
} from './../';
import { TestValues } from './_test-helpers';
describe('CommentsState', () => {
const app = 'my-app';
const {
app,
appsState,
creator,
now
} = TestValues;
const commentsId = 'my-comments';
const now = DateTime.today();
const user = 'not-me';
const oldComments = new CommentsDto([
new CommentDto('1', now, 'text1', user),
new CommentDto('2', now, 'text2', user)
new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2', creator)
], [], [], new Version('1'));
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let commentsService: IMock<CommentsService>;
let commentsState: CommentsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
commentsService = Mock.ofType<CommentsService>();
commentsService.setup(x => x.getComments(app, commentsId, new Version('-1')))
@ -55,9 +53,9 @@ describe('CommentsState', () => {
it('should load and merge comments', () => {
const newComments = new CommentsDto([
new CommentDto('3', now, 'text3', user)
new CommentDto('3', now, 'text3', creator)
], [
new CommentDto('2', now, 'text2_2', user)
new CommentDto('2', now, 'text2_2', creator)
], ['1'], new Version('2'));
commentsService.setup(x => x.getComments(app, commentsId, new Version('1')))
@ -67,15 +65,15 @@ describe('CommentsState', () => {
expect(commentsState.snapshot.isLoaded).toBeTruthy();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('2', now, 'text2_2', user),
new CommentDto('3', now, 'text3', user)
new CommentDto('2', now, 'text2_2', creator),
new CommentDto('3', now, 'text3', creator)
]));
commentsService.verify(x => x.getComments(app, commentsId, It.isAny()), Times.exactly(2));
});
it('should add comment to snapshot when created', () => {
const newComment = new CommentDto('3', now, 'text3', user);
const newComment = new CommentDto('3', now, 'text3', creator);
const request = { text: 'text3' };
@ -85,9 +83,9 @@ describe('CommentsState', () => {
commentsState.create('text3').subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', user),
new CommentDto('2', now, 'text2', user),
new CommentDto('3', now, 'text3', user)
new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2', creator),
new CommentDto('3', now, 'text3', creator)
]));
});
@ -100,8 +98,8 @@ describe('CommentsState', () => {
commentsState.update('2', 'text2_2', now).subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', user),
new CommentDto('2', now, 'text2_2', user)
new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2_2', creator)
]));
commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once());
@ -114,7 +112,7 @@ describe('CommentsState', () => {
commentsState.delete('2').subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', user)
new CommentDto('1', now, 'text1', creator)
]));
commentsService.verify(x => x.deleteComment(app, commentsId, '2'), Times.once());

41
src/Squidex/app/shared/state/contributors.state.spec.ts

@ -9,49 +9,40 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
AuthService,
ContributorAssignedDto,
ContributorDto,
ContributorsDto,
ContributorsService,
ContributorsState,
DialogService,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('ContributorsState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
authService,
newVersion,
userId,
version
} = TestValues;
const oldContributors = [
new ContributorDto('id1', 'Developer'),
new ContributorDto('id2', 'Developer')
new ContributorDto(userId, 'Developer')
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let contributorsService: IMock<ContributorsService>;
let contributorsState: ContributorsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: 'id2' });
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
contributorsService = Mock.ofType<ContributorsService>();
contributorsService.setup(x => x.getContributors(app))
.returns(() => of(new ContributorsDto(oldContributors, 3, version)));
@ -83,10 +74,11 @@ describe('ContributorsState', () => {
it('should add contributor to snapshot when assigned', () => {
const newContributor = new ContributorDto('id3', 'Developer');
const request = { contributorId: 'mail2stehle@gmail.com', role: 'Developer' };
const request = { contributorId: 'mail2stehle@gmail.com', role: newContributor.role };
const response = { contributorId: newContributor.contributorId, isCreated: true };
contributorsService.setup(x => x.postContributor(app, request, version))
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, { contributorId: '123', isCreated: true })));
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, response)));
contributorsState.assign(request).subscribe();
@ -101,12 +93,13 @@ describe('ContributorsState', () => {
});
it('should update contributor in snapshot when assigned and already added', () => {
const newContributor = new ContributorDto('id2', 'Owner');
const newContributor = new ContributorDto(userId, 'Owner');
const request = { ...newContributor };
const response = { contributorId: newContributor.contributorId, isCreated: true };
contributorsService.setup(x => x.postContributor(app, request, version))
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, { contributorId: '123', isCreated: true })));
.returns(() => of(new Versioned<ContributorAssignedDto>(newVersion, response)));
contributorsState.assign(request).subscribe();

4
src/Squidex/app/shared/state/filter.state.spec.ts

@ -12,10 +12,10 @@ import {
} from './../';
describe('FilterState', () => {
let filterState: FilterState;
let query: string | undefined;
let filter: string | undefined;
let fullText: string | undefined;
let filterState: FilterState;
let filter: string | undefined;
let order: string | undefined;
beforeEach(() => {

29
src/Squidex/app/shared/state/languages.state.spec.ts

@ -12,20 +12,23 @@ import {
AppLanguageDto,
AppLanguagesDto,
AppLanguagesService,
AppsState,
DialogService,
ImmutableArray,
LanguageDto,
LanguagesService,
LanguagesState,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('LanguagesState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
newVersion,
version
} = TestValues;
const languageDE = new LanguageDto('de', 'German');
const languageEN = new LanguageDto('en', 'English');
@ -33,12 +36,11 @@ describe('LanguagesState', () => {
const languageES = new LanguageDto('es', 'Spanish');
const oldLanguages = [
new AppLanguageDto(languageEN.iso2Code, languageEN.englishName, true, false, []),
new AppLanguageDto(languageDE.iso2Code, languageDE.englishName, false, true, [languageEN.iso2Code])
AppLanguageDto.fromLanguage(languageEN, true),
AppLanguageDto.fromLanguage(languageDE, false, true, [languageEN.iso2Code])
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let allLanguagesService: IMock<LanguagesService>;
let languagesService: IMock<AppLanguagesService>;
let languagesState: LanguagesState;
@ -46,11 +48,6 @@ describe('LanguagesState', () => {
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
allLanguagesService = Mock.ofType<LanguagesService>();
allLanguagesService.setup(x => x.getLanguages())
@ -120,15 +117,15 @@ describe('LanguagesState', () => {
});
it('should update language in snapshot when updated', () => {
const request = { isMaster: true };
const request = { isMaster: true, isOptional: false, fallback: [] };
languagesService.setup(x => x.putLanguage(app, oldLanguages[1].iso2Code, request, version))
.returns(() => of(new Versioned<any>(newVersion, {})));
languagesState.update(oldLanguages[1], request).subscribe();
const newLanguage1 = new AppLanguageDto(languageDE.iso2Code, languageDE.englishName, true, false, []);
const newLanguage2 = new AppLanguageDto(languageEN.iso2Code, languageEN.englishName, false, false, []);
const newLanguage1 = AppLanguageDto.fromLanguage(languageDE, true);
const newLanguage2 = AppLanguageDto.fromLanguage(languageEN);
expect(languagesState.snapshot.languages.values).toEqual([
{

12
src/Squidex/app/shared/state/languages.state.ts

@ -132,13 +132,13 @@ export class LanguagesState extends State<Snapshot> {
public update(language: AppLanguageDto, request: UpdateAppLanguageDto): Observable<any> {
return this.appLanguagesService.putLanguage(this.appName, language.iso2Code, request, this.version).pipe(
tap(dto => {
const languages = this.snapshot.plainLanguages.map(l => {
if (l.iso2Code === language.iso2Code) {
return update(l, request);
} else if (l.isMaster && request.isMaster) {
return update(l, { isMaster: false });
const languages = this.snapshot.plainLanguages.map(x => {
if (x.iso2Code === language.iso2Code) {
return update(x, request);
} else if (x.isMaster && request.isMaster) {
return update(x, { isMaster: false });
} else {
return l;
return x;
}
});

21
src/Squidex/app/shared/state/patterns.state.spec.ts

@ -9,20 +9,23 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
DialogService,
PatternDto,
PatternsDto,
PatternsService,
PatternsState,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('PatternsState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
newVersion,
version
} = TestValues;
const oldPatterns = [
new PatternDto('id1', 'name1', 'pattern1', ''),
@ -30,18 +33,12 @@ describe('PatternsState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let patternsService: IMock<PatternsService>;
let patternsState: PatternsState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
patternsService = Mock.ofType<PatternsService>();
patternsService.setup(x => x.getPatterns(app))
@ -88,7 +85,7 @@ describe('PatternsState', () => {
patternsState.update(oldPatterns[1], request).subscribe();
const pattern_1 = patternsState.snapshot.patterns.at(0);
const pattern_1 = patternsState.snapshot.patterns.at(1);
expect(pattern_1.name).toBe(request.name);
expect(pattern_1.pattern).toBe(request.pattern);

33
src/Squidex/app/shared/state/plans.state.spec.ts

@ -10,22 +10,25 @@ import { onErrorResumeNext } from 'rxjs/operators';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
AuthService,
DialogService,
PlanChangedDto,
PlanDto,
PlansDto,
PlansService,
PlansState,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('PlansState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
authService,
newVersion,
version
} = TestValues;
const oldPlans =
new PlansDto('id1', 'id2', true, [
@ -35,24 +38,12 @@ describe('PlansState', () => {
version);
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let plansService: IMock<PlansService>;
let plansState: PlansState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: 'id3' });
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
plansService = Mock.ofType<PlansService>();
plansService.setup(x => x.getPlans(app))
@ -102,8 +93,10 @@ describe('PlansState', () => {
it('should redirect when returning url', () => {
plansState.window = <any>{ location: {} };
const result = { redirectUri: 'http://url' };
plansService.setup(x => x.putPlan(app, It.isAny(), version))
.returns(() => of(new Versioned<PlanChangedDto>(newVersion, { redirectUri: 'http://url' })));
.returns(() => of(new Versioned<PlanChangedDto>(newVersion, result)));
plansState.load().subscribe();
plansState.change('free').pipe(onErrorResumeNext()).subscribe();
@ -112,7 +105,7 @@ describe('PlansState', () => {
{ isSelected: true, isYearlySelected: false, plan: oldPlans.plans[0] },
{ isSelected: false, isYearlySelected: false, plan: oldPlans.plans[1] }
]);
expect(plansState.window.location.href).toBe('URI');
expect(plansState.window.location.href).toBe(result.redirectUri);
expect(plansState.snapshot.version).toEqual(version);
});

19
src/Squidex/app/shared/state/roles.state.spec.ts

@ -9,20 +9,23 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
DialogService,
RoleDto,
RolesDto,
RolesService,
RolesState,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('RolesState', () => {
const app = 'my-app';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
newVersion,
version
} = TestValues;
const oldRoles = [
new RoleDto('Role1', 3, 5, ['P1']),
@ -30,18 +33,12 @@ describe('RolesState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let rolesService: IMock<RolesService>;
let rolesState: RolesState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rolesService = Mock.ofType<RolesService>();
rolesService.setup(x => x.getRoles(app))

14
src/Squidex/app/shared/state/rule-events.state.spec.ts

@ -9,7 +9,6 @@ import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
DateTime,
DialogService,
RuleEventDto,
@ -18,15 +17,19 @@ import {
RulesService
} from './../';
import { TestValues } from './_test-helpers';
describe('RuleEventsState', () => {
const app = 'my-app';
const {
app,
appsState
} = TestValues;
const oldRuleEvents = [
new RuleEventDto('id1', DateTime.now(), null, 'event1', 'description', 'dump1', 'result1', 'result1', 1),
new RuleEventDto('id2', DateTime.now(), null, 'event2', 'description', 'dump2', 'result2', 'result2', 2)
];
let appsState: IMock<AppsState>;
let dialogs: IMock<DialogService>;
let rulesService: IMock<RulesService>;
let ruleEventsState: RuleEventsState;
@ -34,11 +37,6 @@ describe('RuleEventsState', () => {
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rulesService = Mock.ofType<RulesService>();
rulesService.setup(x => x.getEvents(app, 10, 0))

40
src/Squidex/app/shared/state/rules.state.spec.ts

@ -11,25 +11,27 @@ import { IMock, It, Mock, Times } from 'typemoq';
import { RulesState } from './rules.state';
import {
AppsState,
AuthService,
DateTime,
DialogService,
RuleDto,
RulesService,
UpdateRuleDto,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('RulesState', () => {
const app = 'my-app';
const creation = DateTime.today();
const creator = 'not-me';
const modified = DateTime.now();
const modifier = 'me';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
authService,
creation,
creator,
modified,
modifier,
newVersion,
version
} = TestValues;
const oldRules = [
new RuleDto('id1', creator, creator, creation, creation, version, false, {}, 'trigger1', {}, 'action1'),
@ -37,24 +39,12 @@ describe('RulesState', () => {
];
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let rulesService: IMock<RulesService>;
let rulesState: RulesState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: '1', token: modifier });
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rulesService = Mock.ofType<RulesService>();
rulesService.setup(x => x.getRules(app))
@ -95,7 +85,7 @@ describe('RulesState', () => {
it('should update action and update and user info when updated action', () => {
const newAction = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(i => true), version))
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(() => true), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
rulesState.updateAction(oldRules[0], newAction, modified).subscribe();
@ -109,7 +99,7 @@ describe('RulesState', () => {
it('should update trigger and update and user info when updated trigger', () => {
const newTrigger = {};
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(i => true), version))
rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is<UpdateRuleDto>(() => true), version))
.returns(() => of(new Versioned<any>(newVersion, {})));
rulesState.updateTrigger(oldRules[0], newTrigger, modified).subscribe();

36
src/Squidex/app/shared/state/schemas.state.spec.ts

@ -12,11 +12,8 @@ import { SchemasState } from './schemas.state';
import {
AddFieldDto,
AppsState,
AuthService,
createProperties,
CreateSchemaDto,
DateTime,
DialogService,
NestedFieldDto,
RootFieldDto,
@ -24,18 +21,23 @@ import {
SchemaDto,
SchemasService,
UpdateSchemaCategoryDto,
Version,
Versioned
} from './../';
import { TestValues } from './_test-helpers';
describe('SchemasState', () => {
const app = 'my-app';
const creation = DateTime.today();
const creator = 'not-me';
const modified = DateTime.now();
const modifier = 'me';
const version = new Version('1');
const newVersion = new Version('2');
const {
app,
appsState,
authService,
creation,
creator,
modified,
modifier,
newVersion,
version
} = TestValues;
const oldSchemas = [
new SchemaDto('id1', 'name1', 'category1', {}, false, false, creation, creator, creation, creator, version),
@ -56,24 +58,12 @@ describe('SchemasState', () => {
[field1, field2]);
let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let schemasService: IMock<SchemasService>;
let schemasState: SchemasState;
beforeEach(() => {
dialogs = Mock.ofType<DialogService>();
authService = Mock.ofType<AuthService>();
authService.setup(x => x.user)
.returns(() => <any>{ id: '1', token: modifier });
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
schemasService = Mock.ofType<SchemasService>();
schemasService.setup(x => x.getSchemas(app))

22
src/Squidex/app/shared/state/ui.state.spec.ts

@ -8,14 +8,15 @@
import { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq';
import {
AppsState,
UIService,
UIState
} from './../';
import { UIService, UIState } from './../';
import { TestValues } from './_test-helpers';
describe('UIState', () => {
const app = 'my-app';
const {
app,
appsState
} = TestValues;
const appSettings = {
mapType: 'GM',
@ -29,19 +30,10 @@ describe('UIState', () => {
canCreateApps: true
};
let appsState: IMock<AppsState>;
let uiService: IMock<UIService>;
let uiState: UIState;
beforeEach(() => {
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
appsState.setup(x => x.selectedApp)
.returns(() => of(<any>{ name: app }));
uiService = Mock.ofType<UIService>();
uiService.setup(x => x.getSettings(app))

Loading…
Cancel
Save