diff --git a/src/Squidex/app/features/administration/pages/restore/restore-page.component.ts b/src/Squidex/app/features/administration/pages/restore/restore-page.component.ts index e23671154..32437b609 100644 --- a/src/Squidex/app/features/administration/pages/restore/restore-page.component.ts +++ b/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(() => { diff --git a/src/Squidex/app/features/administration/state/users.state.spec.ts b/src/Squidex/app/features/administration/state/users.state.spec.ts index 53bd4f3e3..cc7939542 100644 --- a/src/Squidex/app/features/administration/state/users.state.spec.ts +++ b/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!); }); diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-preview-urls-form.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-preview-urls-form.component.ts index 9f8574a04..72a59074e 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-preview-urls-form.component.ts +++ b/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() { diff --git a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts b/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts index 8650792c5..75d6d9b30 100644 --- a/src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts +++ b/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(); } } } diff --git a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts b/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts index 4bf0a1b52..498cd0b5f 100644 --- a/src/Squidex/app/features/settings/pages/contributors/contributors-page.component.ts +++ b/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.'); diff --git a/src/Squidex/app/features/settings/pages/patterns/pattern.component.ts b/src/Squidex/app/features/settings/pages/patterns/pattern.component.ts index 4a64c1f4d..e1a45b953 100644 --- a/src/Squidex/app/features/settings/pages/patterns/pattern.component.ts +++ b/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); }); diff --git a/src/Squidex/app/features/settings/pages/roles/role.component.ts b/src/Squidex/app/features/settings/pages/roles/role.component.ts index 7c02be173..78e77aa06 100644 --- a/src/Squidex/app/features/settings/pages/roles/role.component.ts +++ b/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(); } } diff --git a/src/Squidex/app/features/settings/pages/roles/roles-page.component.ts b/src/Squidex/app/features/settings/pages/roles/roles-page.component.ts index 843b92360..edad41b92 100644 --- a/src/Squidex/app/features/settings/pages/roles/roles-page.component.ts +++ b/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); }); diff --git a/src/Squidex/app/framework/state.ts b/src/Squidex/app/framework/state.ts index 1319ad555..5a9faa7cc 100644 --- a/src/Squidex/app/framework/state.ts +++ b/src/Squidex/app/framework/state.ts @@ -82,12 +82,7 @@ export class Form { 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) { diff --git a/src/Squidex/app/shared/components/comments.component.ts b/src/Squidex/app/shared/components/comments.component.ts index cb493d69a..5fe06b302 100644 --- a/src/Squidex/app/shared/components/comments.component.ts +++ b/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(); } } diff --git a/src/Squidex/app/shared/services/app-languages.service.spec.ts b/src/Squidex/app/shared/services/app-languages.service.spec.ts index 5fd7d0cab..273a57ba4 100644 --- a/src/Squidex/app/shared/services/app-languages.service.spec.ts +++ b/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, [])); })); diff --git a/src/Squidex/app/shared/services/app-languages.service.ts b/src/Squidex/app/shared/services/app-languages.service.ts index 5a83f059e..3f35b6ebd 100644 --- a/src/Squidex/app/shared/services/app-languages.service.ts +++ b/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 { constructor( public readonly languages: AppLanguageDto[], @@ -39,6 +41,15 @@ export class AppLanguageDto extends Model { ) { 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 { diff --git a/src/Squidex/app/shared/services/plans.service.spec.ts b/src/Squidex/app/shared/services/plans.service.spec.ts index 35396170d..27cb2f149 100644 --- a/src/Squidex/app/shared/services/plans.service.spec.ts +++ b/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); diff --git a/src/Squidex/app/shared/state/_test-helpers.ts b/src/Squidex/app/shared/state/_test-helpers.ts new file mode 100644 index 000000000..69d6e55ce --- /dev/null +++ b/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.setup(x => x.appName) + .returns(() => app); + +appsState.setup(x => x.selectedApp) + .returns(() => of({ name: app })); + +const authService = Mock.ofType(); + +authService.setup(x => x.user) + .returns(() => { id: modifier, token: modifier }); + +export const TestValues = { + app, + appsState, + authService, + creation, + creator, + modified, + modifier, + now, + newVersion, + userId: modifier, + version +}; \ No newline at end of file diff --git a/src/Squidex/app/shared/state/assets.state.spec.ts b/src/Squidex/app/shared/state/assets.state.spec.ts index aa32d70f3..702954a2f 100644 --- a/src/Squidex/app/shared/state/assets.state.spec.ts +++ b/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; - let appsState: IMock; let assetsService: IMock; let assetsState: AssetsState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - assetsService = Mock.ofType(); assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) diff --git a/src/Squidex/app/shared/state/backups.state.spec.ts b/src/Squidex/app/shared/state/backups.state.spec.ts index a82eeba7a..46d1119b1 100644 --- a/src/Squidex/app/shared/state/backups.state.spec.ts +++ b/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; - let appsState: IMock; let backupsService: IMock; let backupsState: BackupsState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - backupsService = Mock.ofType(); backupsService.setup(x => x.getBackups(app)) diff --git a/src/Squidex/app/shared/state/clients.state.spec.ts b/src/Squidex/app/shared/state/clients.state.spec.ts index 6462f20b7..82971fc19 100644 --- a/src/Squidex/app/shared/state/clients.state.spec.ts +++ b/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; - let appsState: IMock; let clientsService: IMock; let clientsState: ClientsState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - clientsService = Mock.ofType(); clientsService.setup(x => x.getClients(app)) diff --git a/src/Squidex/app/shared/state/comments.state.spec.ts b/src/Squidex/app/shared/state/comments.state.spec.ts index 7a101a793..ad1d1347d 100644 --- a/src/Squidex/app/shared/state/comments.state.spec.ts +++ b/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; - let appsState: IMock; let commentsService: IMock; let commentsState: CommentsState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - commentsService = Mock.ofType(); 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()); diff --git a/src/Squidex/app/shared/state/contributors.state.spec.ts b/src/Squidex/app/shared/state/contributors.state.spec.ts index b98051959..8d217321a 100644 --- a/src/Squidex/app/shared/state/contributors.state.spec.ts +++ b/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; - let appsState: IMock; - let authService: IMock; let contributorsService: IMock; let contributorsState: ContributorsState; beforeEach(() => { dialogs = Mock.ofType(); - authService = Mock.ofType(); - - authService.setup(x => x.user) - .returns(() => { id: 'id2' }); - - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - contributorsService = Mock.ofType(); - 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(newVersion, { contributorId: '123', isCreated: true }))); + .returns(() => of(new Versioned(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(newVersion, { contributorId: '123', isCreated: true }))); + .returns(() => of(new Versioned(newVersion, response))); contributorsState.assign(request).subscribe(); diff --git a/src/Squidex/app/shared/state/filter.state.spec.ts b/src/Squidex/app/shared/state/filter.state.spec.ts index 381420547..24840bdaf 100644 --- a/src/Squidex/app/shared/state/filter.state.spec.ts +++ b/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(() => { diff --git a/src/Squidex/app/shared/state/languages.state.spec.ts b/src/Squidex/app/shared/state/languages.state.spec.ts index 97ab66264..56f98080b 100644 --- a/src/Squidex/app/shared/state/languages.state.spec.ts +++ b/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; - let appsState: IMock; let allLanguagesService: IMock; let languagesService: IMock; let languagesState: LanguagesState; @@ -46,11 +48,6 @@ describe('LanguagesState', () => { beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - allLanguagesService = Mock.ofType(); 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(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([ { diff --git a/src/Squidex/app/shared/state/languages.state.ts b/src/Squidex/app/shared/state/languages.state.ts index 9910fe399..74210b669 100644 --- a/src/Squidex/app/shared/state/languages.state.ts +++ b/src/Squidex/app/shared/state/languages.state.ts @@ -132,13 +132,13 @@ export class LanguagesState extends State { public update(language: AppLanguageDto, request: UpdateAppLanguageDto): Observable { 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; } }); diff --git a/src/Squidex/app/shared/state/patterns.state.spec.ts b/src/Squidex/app/shared/state/patterns.state.spec.ts index 60d6d5653..94863afd3 100644 --- a/src/Squidex/app/shared/state/patterns.state.spec.ts +++ b/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; - let appsState: IMock; let patternsService: IMock; let patternsState: PatternsState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - patternsService = Mock.ofType(); 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); diff --git a/src/Squidex/app/shared/state/plans.state.spec.ts b/src/Squidex/app/shared/state/plans.state.spec.ts index e30c52238..e1555e27e 100644 --- a/src/Squidex/app/shared/state/plans.state.spec.ts +++ b/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; - let appsState: IMock; - let authService: IMock; let plansService: IMock; let plansState: PlansState; beforeEach(() => { dialogs = Mock.ofType(); - authService = Mock.ofType(); - - authService.setup(x => x.user) - .returns(() => { id: 'id3' }); - - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - plansService = Mock.ofType(); plansService.setup(x => x.getPlans(app)) @@ -102,8 +93,10 @@ describe('PlansState', () => { it('should redirect when returning url', () => { plansState.window = { location: {} }; + const result = { redirectUri: 'http://url' }; + plansService.setup(x => x.putPlan(app, It.isAny(), version)) - .returns(() => of(new Versioned(newVersion, { redirectUri: 'http://url' }))); + .returns(() => of(new Versioned(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); }); diff --git a/src/Squidex/app/shared/state/roles.state.spec.ts b/src/Squidex/app/shared/state/roles.state.spec.ts index 69391e2dc..ce0786c92 100644 --- a/src/Squidex/app/shared/state/roles.state.spec.ts +++ b/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; - let appsState: IMock; let rolesService: IMock; let rolesState: RolesState; beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - rolesService = Mock.ofType(); rolesService.setup(x => x.getRoles(app)) diff --git a/src/Squidex/app/shared/state/rule-events.state.spec.ts b/src/Squidex/app/shared/state/rule-events.state.spec.ts index acc4eee03..50ca944f0 100644 --- a/src/Squidex/app/shared/state/rule-events.state.spec.ts +++ b/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; let dialogs: IMock; let rulesService: IMock; let ruleEventsState: RuleEventsState; @@ -34,11 +37,6 @@ describe('RuleEventsState', () => { beforeEach(() => { dialogs = Mock.ofType(); - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - rulesService = Mock.ofType(); rulesService.setup(x => x.getEvents(app, 10, 0)) diff --git a/src/Squidex/app/shared/state/rules.state.spec.ts b/src/Squidex/app/shared/state/rules.state.spec.ts index 5181981ab..6fd8c7cbe 100644 --- a/src/Squidex/app/shared/state/rules.state.spec.ts +++ b/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; - let appsState: IMock; - let authService: IMock; let rulesService: IMock; let rulesState: RulesState; beforeEach(() => { dialogs = Mock.ofType(); - authService = Mock.ofType(); - - authService.setup(x => x.user) - .returns(() => { id: '1', token: modifier }); - - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - rulesService = Mock.ofType(); 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(i => true), version)) + rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is(() => true), version)) .returns(() => of(new Versioned(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(i => true), version)) + rulesService.setup(x => x.putRule(app, oldRules[0].id, It.is(() => true), version)) .returns(() => of(new Versioned(newVersion, {}))); rulesState.updateTrigger(oldRules[0], newTrigger, modified).subscribe(); diff --git a/src/Squidex/app/shared/state/schemas.state.spec.ts b/src/Squidex/app/shared/state/schemas.state.spec.ts index 2624f51b8..067b022a5 100644 --- a/src/Squidex/app/shared/state/schemas.state.spec.ts +++ b/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; - let appsState: IMock; - let authService: IMock; let schemasService: IMock; let schemasState: SchemasState; beforeEach(() => { dialogs = Mock.ofType(); - authService = Mock.ofType(); - - authService.setup(x => x.user) - .returns(() => { id: '1', token: modifier }); - - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - schemasService = Mock.ofType(); schemasService.setup(x => x.getSchemas(app)) diff --git a/src/Squidex/app/shared/state/ui.state.spec.ts b/src/Squidex/app/shared/state/ui.state.spec.ts index 171a4e3a5..8ca7da532 100644 --- a/src/Squidex/app/shared/state/ui.state.spec.ts +++ b/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; let uiService: IMock; let uiState: UIState; beforeEach(() => { - appsState = Mock.ofType(); - - appsState.setup(x => x.appName) - .returns(() => app); - - appsState.setup(x => x.selectedApp) - .returns(() => of({ name: app })); - uiService = Mock.ofType(); uiService.setup(x => x.getSettings(app))