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(); const value = this.restoreForm.submit();
if (value) { if (value) {
this.restoreForm.submitCompleted({ url: '' }); this.restoreForm.submitCompleted();
this.backupsService.postRestore(value) this.backupsService.postRestore(value)
.subscribe(() => { .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); const user_1 = usersState.snapshot.users.at(0);
expect(user_1.user.email).toEqual(request.email); 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.user.permissions).toEqual(request.permissions);
expect(user_1).toBe(usersState.snapshot.selectedUser!); 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() { public cancelAdd() {
this.addForm.submitCompleted({ name: '', url: '' }); this.addForm.submitCompleted();
} }
public add() { 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 { try {
this.schemasState.addCategory(value.name); this.schemasState.addCategory(value.name);
} finally { } 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) this.contributorsState.assign(requestDto)
.subscribe(isCreated => { .subscribe(isCreated => {
this.assignContributorForm.submitCompleted({ user: '' }); this.assignContributorForm.submitCompleted();
if (isCreated) { if (isCreated) {
this.dialogs.notifyInfo('A new user with the entered email address has been created and assigned as contributor.'); 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 { } else {
this.patternsState.create(value) this.patternsState.create(value)
.subscribe(() => { .subscribe(() => {
this.editForm.submitCompleted({ pattern: '', name: '' }); this.editForm.submitCompleted();
}, error => { }, error => {
this.editForm.submitFailed(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) { if (value) {
this.editForm.add(value.permission); this.editForm.add(value.permission);
this.addPermissionForm.submitCompleted({ permission: '' }); this.addPermissionForm.submitCompleted();
this.addPermissionInput.focus(); 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) { if (value) {
this.rolesState.add(value) this.rolesState.add(value)
.subscribe(() => { .subscribe(() => {
this.addRoleForm.submitCompleted({ name: '' }); this.addRoleForm.submitCompleted();
}, error => { }, error => {
this.addRoleForm.submitFailed(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.state.next(_ => ({ submitted: false, error: null }));
this.enable(); this.enable();
this.setValue(newValue);
if (newValue) {
this.setValue(newValue);
} else {
this.form.markAsPristine();
}
} }
public submitFailed(error?: string | ErrorDto) { 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) { if (value) {
this.state.create(value.text).pipe(onErrorResumeNext()).subscribe(); 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.method).toEqual('POST');
expect(req.request.headers.get('If-Match')).toEqual(version.value); 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, [])); 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 Versioned
} from '@app/framework'; } from '@app/framework';
import { LanguageDto } from './languages.service';
export class AppLanguagesDto extends Model<AppLanguagesDto> { export class AppLanguagesDto extends Model<AppLanguagesDto> {
constructor( constructor(
public readonly languages: AppLanguageDto[], public readonly languages: AppLanguageDto[],
@ -39,6 +41,15 @@ export class AppLanguageDto extends Model<AppLanguageDto> {
) { ) {
super(); 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 { 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'); 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.method).toEqual('PUT');
expect(req.request.headers.get('If-Match')).toBe(version.value); 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
AssetDto, AssetDto,
AssetsDto, AssetsDto,
AssetsService, AssetsService,
AssetsState, AssetsState,
DateTime,
DialogService, DialogService,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('AssetsState', () => { describe('AssetsState', () => {
const app = 'my-app'; const {
const creation = DateTime.today(); app,
const creator = 'not-me'; appsState,
const modified = DateTime.now(); creation,
const modifier = 'me'; creator,
const version = new Version('1'); modified,
const newVersion = new Version('2'); modifier,
newVersion,
version
} = TestValues;
const oldAssets = [ const oldAssets = [
new AssetDto('id1', creator, creator, creation, creation, 'name1', 'hash1', 'type1', 1, 1, 'mime1', false, false, null, null, 'slug1', ['tag1', 'shared'], 'url1', version), 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 dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let assetsService: IMock<AssetsService>; let assetsService: IMock<AssetsService>;
let assetsState: AssetsState; let assetsState: AssetsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
assetsService = Mock.ofType<AssetsService>(); assetsService = Mock.ofType<AssetsService>();
assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
BackupDto, BackupDto,
BackupsService, BackupsService,
BackupsState, BackupsState,
@ -18,8 +17,13 @@ import {
DialogService DialogService
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('BackupsState', () => { describe('BackupsState', () => {
const app = 'my-app'; const {
app,
appsState
} = TestValues;
const oldBackups = [ const oldBackups = [
new BackupDto('id1', DateTime.now(), null, 1, 1, 'Started'), new BackupDto('id1', DateTime.now(), null, 1, 1, 'Started'),
@ -27,18 +31,12 @@ describe('BackupsState', () => {
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let backupsService: IMock<BackupsService>; let backupsService: IMock<BackupsService>;
let backupsState: BackupsState; let backupsState: BackupsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
backupsService = Mock.ofType<BackupsService>(); backupsService = Mock.ofType<BackupsService>();
backupsService.setup(x => x.getBackups(app)) 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
ClientDto, ClientDto,
ClientsDto, ClientsDto,
ClientsService, ClientsService,
ClientsState, ClientsState,
DialogService, DialogService,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('ClientsState', () => { describe('ClientsState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
newVersion,
version
} = TestValues;
const oldClients = [ const oldClients = [
new ClientDto('id1', 'name1', 'secret1'), new ClientDto('id1', 'name1', 'secret1'),
@ -30,18 +33,12 @@ describe('ClientsState', () => {
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let clientsService: IMock<ClientsService>; let clientsService: IMock<ClientsService>;
let clientsState: ClientsState; let clientsState: ClientsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
clientsService = Mock.ofType<ClientsService>(); clientsService = Mock.ofType<ClientsService>();
clientsService.setup(x => x.getClients(app)) 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
CommentDto, CommentDto,
CommentsDto, CommentsDto,
CommentsService, CommentsService,
CommentsState, CommentsState,
DateTime,
DialogService, DialogService,
ImmutableArray, ImmutableArray,
Version Version
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('CommentsState', () => { describe('CommentsState', () => {
const app = 'my-app'; const {
app,
appsState,
creator,
now
} = TestValues;
const commentsId = 'my-comments'; const commentsId = 'my-comments';
const now = DateTime.today();
const user = 'not-me';
const oldComments = new CommentsDto([ const oldComments = new CommentsDto([
new CommentDto('1', now, 'text1', user), new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2', user) new CommentDto('2', now, 'text2', creator)
], [], [], new Version('1')); ], [], [], new Version('1'));
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let commentsService: IMock<CommentsService>; let commentsService: IMock<CommentsService>;
let commentsState: CommentsState; let commentsState: CommentsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
commentsService = Mock.ofType<CommentsService>(); commentsService = Mock.ofType<CommentsService>();
commentsService.setup(x => x.getComments(app, commentsId, new Version('-1'))) commentsService.setup(x => x.getComments(app, commentsId, new Version('-1')))
@ -55,9 +53,9 @@ describe('CommentsState', () => {
it('should load and merge comments', () => { it('should load and merge comments', () => {
const newComments = new CommentsDto([ 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')); ], ['1'], new Version('2'));
commentsService.setup(x => x.getComments(app, commentsId, new Version('1'))) commentsService.setup(x => x.getComments(app, commentsId, new Version('1')))
@ -67,15 +65,15 @@ describe('CommentsState', () => {
expect(commentsState.snapshot.isLoaded).toBeTruthy(); expect(commentsState.snapshot.isLoaded).toBeTruthy();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('2', now, 'text2_2', user), new CommentDto('2', now, 'text2_2', creator),
new CommentDto('3', now, 'text3', user) new CommentDto('3', now, 'text3', creator)
])); ]));
commentsService.verify(x => x.getComments(app, commentsId, It.isAny()), Times.exactly(2)); commentsService.verify(x => x.getComments(app, commentsId, It.isAny()), Times.exactly(2));
}); });
it('should add comment to snapshot when created', () => { 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' }; const request = { text: 'text3' };
@ -85,9 +83,9 @@ describe('CommentsState', () => {
commentsState.create('text3').subscribe(); commentsState.create('text3').subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', user), new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2', user), new CommentDto('2', now, 'text2', creator),
new CommentDto('3', now, 'text3', user) new CommentDto('3', now, 'text3', creator)
])); ]));
}); });
@ -100,8 +98,8 @@ describe('CommentsState', () => {
commentsState.update('2', 'text2_2', now).subscribe(); commentsState.update('2', 'text2_2', now).subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([
new CommentDto('1', now, 'text1', user), new CommentDto('1', now, 'text1', creator),
new CommentDto('2', now, 'text2_2', user) new CommentDto('2', now, 'text2_2', creator)
])); ]));
commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once()); commentsService.verify(x => x.putComment(app, commentsId, '2', request), Times.once());
@ -114,7 +112,7 @@ describe('CommentsState', () => {
commentsState.delete('2').subscribe(); commentsState.delete('2').subscribe();
expect(commentsState.snapshot.comments).toEqual(ImmutableArray.of([ 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()); 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
AuthService,
ContributorAssignedDto, ContributorAssignedDto,
ContributorDto, ContributorDto,
ContributorsDto, ContributorsDto,
ContributorsService, ContributorsService,
ContributorsState, ContributorsState,
DialogService, DialogService,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('ContributorsState', () => { describe('ContributorsState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
authService,
newVersion,
userId,
version
} = TestValues;
const oldContributors = [ const oldContributors = [
new ContributorDto('id1', 'Developer'), new ContributorDto('id1', 'Developer'),
new ContributorDto('id2', 'Developer') new ContributorDto(userId, 'Developer')
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let contributorsService: IMock<ContributorsService>; let contributorsService: IMock<ContributorsService>;
let contributorsState: ContributorsState; let contributorsState: ContributorsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); 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 = Mock.ofType<ContributorsService>();
contributorsService.setup(x => x.getContributors(app)) contributorsService.setup(x => x.getContributors(app))
.returns(() => of(new ContributorsDto(oldContributors, 3, version))); .returns(() => of(new ContributorsDto(oldContributors, 3, version)));
@ -83,10 +74,11 @@ describe('ContributorsState', () => {
it('should add contributor to snapshot when assigned', () => { it('should add contributor to snapshot when assigned', () => {
const newContributor = new ContributorDto('id3', 'Developer'); 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)) 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(); contributorsState.assign(request).subscribe();
@ -101,12 +93,13 @@ describe('ContributorsState', () => {
}); });
it('should update contributor in snapshot when assigned and already added', () => { 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 request = { ...newContributor };
const response = { contributorId: newContributor.contributorId, isCreated: true };
contributorsService.setup(x => x.postContributor(app, request, version)) 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(); contributorsState.assign(request).subscribe();

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

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

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

@ -12,20 +12,23 @@ import {
AppLanguageDto, AppLanguageDto,
AppLanguagesDto, AppLanguagesDto,
AppLanguagesService, AppLanguagesService,
AppsState,
DialogService, DialogService,
ImmutableArray, ImmutableArray,
LanguageDto, LanguageDto,
LanguagesService, LanguagesService,
LanguagesState, LanguagesState,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('LanguagesState', () => { describe('LanguagesState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
newVersion,
version
} = TestValues;
const languageDE = new LanguageDto('de', 'German'); const languageDE = new LanguageDto('de', 'German');
const languageEN = new LanguageDto('en', 'English'); const languageEN = new LanguageDto('en', 'English');
@ -33,12 +36,11 @@ describe('LanguagesState', () => {
const languageES = new LanguageDto('es', 'Spanish'); const languageES = new LanguageDto('es', 'Spanish');
const oldLanguages = [ const oldLanguages = [
new AppLanguageDto(languageEN.iso2Code, languageEN.englishName, true, false, []), AppLanguageDto.fromLanguage(languageEN, true),
new AppLanguageDto(languageDE.iso2Code, languageDE.englishName, false, true, [languageEN.iso2Code]) AppLanguageDto.fromLanguage(languageDE, false, true, [languageEN.iso2Code])
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let allLanguagesService: IMock<LanguagesService>; let allLanguagesService: IMock<LanguagesService>;
let languagesService: IMock<AppLanguagesService>; let languagesService: IMock<AppLanguagesService>;
let languagesState: LanguagesState; let languagesState: LanguagesState;
@ -46,11 +48,6 @@ describe('LanguagesState', () => {
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
allLanguagesService = Mock.ofType<LanguagesService>(); allLanguagesService = Mock.ofType<LanguagesService>();
allLanguagesService.setup(x => x.getLanguages()) allLanguagesService.setup(x => x.getLanguages())
@ -120,15 +117,15 @@ describe('LanguagesState', () => {
}); });
it('should update language in snapshot when updated', () => { 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)) languagesService.setup(x => x.putLanguage(app, oldLanguages[1].iso2Code, request, version))
.returns(() => of(new Versioned<any>(newVersion, {}))); .returns(() => of(new Versioned<any>(newVersion, {})));
languagesState.update(oldLanguages[1], request).subscribe(); languagesState.update(oldLanguages[1], request).subscribe();
const newLanguage1 = new AppLanguageDto(languageDE.iso2Code, languageDE.englishName, true, false, []); const newLanguage1 = AppLanguageDto.fromLanguage(languageDE, true);
const newLanguage2 = new AppLanguageDto(languageEN.iso2Code, languageEN.englishName, false, false, []); const newLanguage2 = AppLanguageDto.fromLanguage(languageEN);
expect(languagesState.snapshot.languages.values).toEqual([ 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> { public update(language: AppLanguageDto, request: UpdateAppLanguageDto): Observable<any> {
return this.appLanguagesService.putLanguage(this.appName, language.iso2Code, request, this.version).pipe( return this.appLanguagesService.putLanguage(this.appName, language.iso2Code, request, this.version).pipe(
tap(dto => { tap(dto => {
const languages = this.snapshot.plainLanguages.map(l => { const languages = this.snapshot.plainLanguages.map(x => {
if (l.iso2Code === language.iso2Code) { if (x.iso2Code === language.iso2Code) {
return update(l, request); return update(x, request);
} else if (l.isMaster && request.isMaster) { } else if (x.isMaster && request.isMaster) {
return update(l, { isMaster: false }); return update(x, { isMaster: false });
} else { } 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
DialogService, DialogService,
PatternDto, PatternDto,
PatternsDto, PatternsDto,
PatternsService, PatternsService,
PatternsState, PatternsState,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('PatternsState', () => { describe('PatternsState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
newVersion,
version
} = TestValues;
const oldPatterns = [ const oldPatterns = [
new PatternDto('id1', 'name1', 'pattern1', ''), new PatternDto('id1', 'name1', 'pattern1', ''),
@ -30,18 +33,12 @@ describe('PatternsState', () => {
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let patternsService: IMock<PatternsService>; let patternsService: IMock<PatternsService>;
let patternsState: PatternsState; let patternsState: PatternsState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
patternsService = Mock.ofType<PatternsService>(); patternsService = Mock.ofType<PatternsService>();
patternsService.setup(x => x.getPatterns(app)) patternsService.setup(x => x.getPatterns(app))
@ -88,7 +85,7 @@ describe('PatternsState', () => {
patternsState.update(oldPatterns[1], request).subscribe(); 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.name).toBe(request.name);
expect(pattern_1.pattern).toBe(request.pattern); 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
AuthService,
DialogService, DialogService,
PlanChangedDto, PlanChangedDto,
PlanDto, PlanDto,
PlansDto, PlansDto,
PlansService, PlansService,
PlansState, PlansState,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('PlansState', () => { describe('PlansState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
authService,
newVersion,
version
} = TestValues;
const oldPlans = const oldPlans =
new PlansDto('id1', 'id2', true, [ new PlansDto('id1', 'id2', true, [
@ -35,24 +38,12 @@ describe('PlansState', () => {
version); version);
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let plansService: IMock<PlansService>; let plansService: IMock<PlansService>;
let plansState: PlansState; let plansState: PlansState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); 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 = Mock.ofType<PlansService>();
plansService.setup(x => x.getPlans(app)) plansService.setup(x => x.getPlans(app))
@ -102,8 +93,10 @@ describe('PlansState', () => {
it('should redirect when returning url', () => { it('should redirect when returning url', () => {
plansState.window = <any>{ location: {} }; plansState.window = <any>{ location: {} };
const result = { redirectUri: 'http://url' };
plansService.setup(x => x.putPlan(app, It.isAny(), version)) 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.load().subscribe();
plansState.change('free').pipe(onErrorResumeNext()).subscribe(); plansState.change('free').pipe(onErrorResumeNext()).subscribe();
@ -112,7 +105,7 @@ describe('PlansState', () => {
{ isSelected: true, isYearlySelected: false, plan: oldPlans.plans[0] }, { isSelected: true, isYearlySelected: false, plan: oldPlans.plans[0] },
{ isSelected: false, isYearlySelected: false, plan: oldPlans.plans[1] } { 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); 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
DialogService, DialogService,
RoleDto, RoleDto,
RolesDto, RolesDto,
RolesService, RolesService,
RolesState, RolesState,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('RolesState', () => { describe('RolesState', () => {
const app = 'my-app'; const {
const version = new Version('1'); app,
const newVersion = new Version('2'); appsState,
newVersion,
version
} = TestValues;
const oldRoles = [ const oldRoles = [
new RoleDto('Role1', 3, 5, ['P1']), new RoleDto('Role1', 3, 5, ['P1']),
@ -30,18 +33,12 @@ describe('RolesState', () => {
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let rolesService: IMock<RolesService>; let rolesService: IMock<RolesService>;
let rolesState: RolesState; let rolesState: RolesState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rolesService = Mock.ofType<RolesService>(); rolesService = Mock.ofType<RolesService>();
rolesService.setup(x => x.getRoles(app)) 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 { IMock, It, Mock, Times } from 'typemoq';
import { import {
AppsState,
DateTime, DateTime,
DialogService, DialogService,
RuleEventDto, RuleEventDto,
@ -18,15 +17,19 @@ import {
RulesService RulesService
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('RuleEventsState', () => { describe('RuleEventsState', () => {
const app = 'my-app'; const {
app,
appsState
} = TestValues;
const oldRuleEvents = [ const oldRuleEvents = [
new RuleEventDto('id1', DateTime.now(), null, 'event1', 'description', 'dump1', 'result1', 'result1', 1), new RuleEventDto('id1', DateTime.now(), null, 'event1', 'description', 'dump1', 'result1', 'result1', 1),
new RuleEventDto('id2', DateTime.now(), null, 'event2', 'description', 'dump2', 'result2', 'result2', 2) new RuleEventDto('id2', DateTime.now(), null, 'event2', 'description', 'dump2', 'result2', 'result2', 2)
]; ];
let appsState: IMock<AppsState>;
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let rulesService: IMock<RulesService>; let rulesService: IMock<RulesService>;
let ruleEventsState: RuleEventsState; let ruleEventsState: RuleEventsState;
@ -34,11 +37,6 @@ describe('RuleEventsState', () => {
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); dialogs = Mock.ofType<DialogService>();
appsState = Mock.ofType<AppsState>();
appsState.setup(x => x.appName)
.returns(() => app);
rulesService = Mock.ofType<RulesService>(); rulesService = Mock.ofType<RulesService>();
rulesService.setup(x => x.getEvents(app, 10, 0)) 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 { RulesState } from './rules.state';
import { import {
AppsState,
AuthService,
DateTime,
DialogService, DialogService,
RuleDto, RuleDto,
RulesService, RulesService,
UpdateRuleDto, UpdateRuleDto,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('RulesState', () => { describe('RulesState', () => {
const app = 'my-app'; const {
const creation = DateTime.today(); app,
const creator = 'not-me'; appsState,
const modified = DateTime.now(); authService,
const modifier = 'me'; creation,
const version = new Version('1'); creator,
const newVersion = new Version('2'); modified,
modifier,
newVersion,
version
} = TestValues;
const oldRules = [ const oldRules = [
new RuleDto('id1', creator, creator, creation, creation, version, false, {}, 'trigger1', {}, 'action1'), new RuleDto('id1', creator, creator, creation, creation, version, false, {}, 'trigger1', {}, 'action1'),
@ -37,24 +39,12 @@ describe('RulesState', () => {
]; ];
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let rulesService: IMock<RulesService>; let rulesService: IMock<RulesService>;
let rulesState: RulesState; let rulesState: RulesState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); 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 = Mock.ofType<RulesService>();
rulesService.setup(x => x.getRules(app)) rulesService.setup(x => x.getRules(app))
@ -95,7 +85,7 @@ describe('RulesState', () => {
it('should update action and update and user info when updated action', () => { it('should update action and update and user info when updated action', () => {
const newAction = {}; 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, {}))); .returns(() => of(new Versioned<any>(newVersion, {})));
rulesState.updateAction(oldRules[0], newAction, modified).subscribe(); 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', () => { it('should update trigger and update and user info when updated trigger', () => {
const newTrigger = {}; 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, {}))); .returns(() => of(new Versioned<any>(newVersion, {})));
rulesState.updateTrigger(oldRules[0], newTrigger, modified).subscribe(); 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 { import {
AddFieldDto, AddFieldDto,
AppsState,
AuthService,
createProperties, createProperties,
CreateSchemaDto, CreateSchemaDto,
DateTime,
DialogService, DialogService,
NestedFieldDto, NestedFieldDto,
RootFieldDto, RootFieldDto,
@ -24,18 +21,23 @@ import {
SchemaDto, SchemaDto,
SchemasService, SchemasService,
UpdateSchemaCategoryDto, UpdateSchemaCategoryDto,
Version,
Versioned Versioned
} from './../'; } from './../';
import { TestValues } from './_test-helpers';
describe('SchemasState', () => { describe('SchemasState', () => {
const app = 'my-app'; const {
const creation = DateTime.today(); app,
const creator = 'not-me'; appsState,
const modified = DateTime.now(); authService,
const modifier = 'me'; creation,
const version = new Version('1'); creator,
const newVersion = new Version('2'); modified,
modifier,
newVersion,
version
} = TestValues;
const oldSchemas = [ const oldSchemas = [
new SchemaDto('id1', 'name1', 'category1', {}, false, false, creation, creator, creation, creator, version), new SchemaDto('id1', 'name1', 'category1', {}, false, false, creation, creator, creation, creator, version),
@ -56,24 +58,12 @@ describe('SchemasState', () => {
[field1, field2]); [field1, field2]);
let dialogs: IMock<DialogService>; let dialogs: IMock<DialogService>;
let appsState: IMock<AppsState>;
let authService: IMock<AuthService>;
let schemasService: IMock<SchemasService>; let schemasService: IMock<SchemasService>;
let schemasState: SchemasState; let schemasState: SchemasState;
beforeEach(() => { beforeEach(() => {
dialogs = Mock.ofType<DialogService>(); 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 = Mock.ofType<SchemasService>();
schemasService.setup(x => x.getSchemas(app)) 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 { of } from 'rxjs';
import { IMock, It, Mock, Times } from 'typemoq'; import { IMock, It, Mock, Times } from 'typemoq';
import { import { UIService, UIState } from './../';
AppsState,
UIService, import { TestValues } from './_test-helpers';
UIState
} from './../';
describe('UIState', () => { describe('UIState', () => {
const app = 'my-app'; const {
app,
appsState
} = TestValues;
const appSettings = { const appSettings = {
mapType: 'GM', mapType: 'GM',
@ -29,19 +30,10 @@ describe('UIState', () => {
canCreateApps: true canCreateApps: true
}; };
let appsState: IMock<AppsState>;
let uiService: IMock<UIService>; let uiService: IMock<UIService>;
let uiState: UIState; let uiState: UIState;
beforeEach(() => { 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 = Mock.ofType<UIService>();
uiService.setup(x => x.getSettings(app)) uiService.setup(x => x.getSettings(app))

Loading…
Cancel
Save