diff --git a/e2e/playwright/actions/src/tests/create-library.spec.ts b/e2e/playwright/actions/src/tests/create-library.spec.ts index 3b9b00a67..25f702135 100644 --- a/e2e/playwright/actions/src/tests/create-library.spec.ts +++ b/e2e/playwright/actions/src/tests/create-library.spec.ts @@ -145,10 +145,10 @@ test.describe('Create Libraries ', () => { await expect(libraryTable.getCellLinkByName(randomLibraryName).and(myLibrariesPage.page.getByTitle(randomLibraryDescription))).toBeVisible(); await libraryTable.getRowByName(randomLibraryName).click(); await libraryViewDetails.click(); - await expect(libraryDetails.getNameField('Name').getByText(randomLibraryName)).toBeVisible(); - await expect(libraryDetails.getIdField('Library ID').getByText(randomLibraryId)).toBeVisible(); - await expect(libraryDetails.getVisibilityField('Visibility').getByText(publicVisibility)).toBeVisible(); - await expect(libraryDetails.getDescriptionField(libraryDescriptionLabel).getByText(randomLibraryDescription)).toBeVisible(); + expect(await libraryDetails.getNameField('Name').locator('input').inputValue()).toBe(randomLibraryName); + expect(await libraryDetails.getIdField('Library ID').locator('input').inputValue()).toBe(randomLibraryId); + await expect(libraryDetails.getVisibilityField('Visibility').locator('.mat-select-value').getByText(publicVisibility)).toBeVisible(); + expect(await libraryDetails.getDescriptionField.inputValue()).toBe(randomLibraryDescription); await apiClientFactory.sites.deleteSite(randomLibraryId, { permanent: true }); }); diff --git a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.html b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.html index 220221205..7d80a4127 100644 --- a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.html +++ b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.html @@ -1,90 +1,11 @@ - - - - - - - - {{ 'LIBRARY.DIALOG.FORM.NAME' | translate }} - - - - - {{ form.controls.title.value }} - - - - - - - - - - - - - {{ 'LIBRARY.DIALOG.FORM.SITE_ID' | translate }} - - - - - {{ form.controls.id.value }} - - - - - - - - - - - - - {{ 'LIBRARY.DIALOG.FORM.VISIBILITY' | translate }} - - - - - {{ visibilityLabel | translate }} - - - - - - - - - - - - - {{ 'LIBRARY.DIALOG.FORM.DESCRIPTION' | translate }} - - - - - {{ form.controls.description?.value }} - - - - - - - - - - {{ 'LIBRARY.DIALOG.EDIT' | translate }} - - - - + - + - + - + {{ type.label | translate }} @@ -108,7 +29,7 @@ - + - - - {{ 'LIBRARY.DIALOG.CANCEL' | translate }} - - - {{ 'LIBRARY.DIALOG.UPDATE' | translate }} + + + + {{ 'LIBRARY.DIALOG.CANCEL' | translate }} + + + {{ 'LIBRARY.DIALOG.UPDATE' | translate }} + + + + {{ 'LIBRARY.DIALOG.EDIT' | translate }} diff --git a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.spec.ts b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.spec.ts index 80881c92e..b36dabb0d 100644 --- a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.spec.ts +++ b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.spec.ts @@ -77,6 +77,7 @@ describe('LibraryMetadataFormComponent', () => { it('should initialize form with node data', () => { fixture.detectChanges(); + component.toggleEdit(); expect(component.form.value).toEqual(siteEntryModel); }); @@ -89,6 +90,7 @@ describe('LibraryMetadataFormComponent', () => { }; fixture.detectChanges(); + component.toggleEdit(); expect(component.form.value).toEqual(siteEntryModel); @@ -161,6 +163,7 @@ describe('LibraryMetadataFormComponent', () => { component.node.entry.role = Site.RoleEnum.SiteManager; fixture.detectChanges(); + component.toggleEdit(); component.update(); @@ -172,6 +175,7 @@ describe('LibraryMetadataFormComponent', () => { siteEntryModel.title = ' some title '; component.node.entry.title = siteEntryModel.title; component.ngOnInit(); + component.toggleEdit(); component.update(); expect(store.dispatch).toHaveBeenCalledWith( @@ -186,6 +190,7 @@ describe('LibraryMetadataFormComponent', () => { component.node.entry.role = Site.RoleEnum.SiteManager; spyOn(component.form, 'markAsPristine'); component.ngOnInit(); + component.toggleEdit(); component.update(); expect(component.form.markAsPristine).toHaveBeenCalled(); @@ -195,6 +200,7 @@ describe('LibraryMetadataFormComponent', () => { component.node.entry.role = Site.RoleEnum.SiteConsumer; fixture.detectChanges(); + component.toggleEdit(); component.update(); @@ -205,6 +211,7 @@ describe('LibraryMetadataFormComponent', () => { component.node.entry.role = Site.RoleEnum.SiteConsumer; spyOn(component.form, 'markAsPristine'); component.ngOnInit(); + component.toggleEdit(); component.update(); expect(component.form.markAsPristine).not.toHaveBeenCalled(); @@ -214,6 +221,7 @@ describe('LibraryMetadataFormComponent', () => { component.node.entry.role = Site.RoleEnum.SiteManager; fixture.detectChanges(); + component.toggleEdit(); component.form.controls['title'].setErrors({ maxlength: true }); @@ -227,23 +235,36 @@ describe('LibraryMetadataFormComponent', () => { spyOn(component.form, 'markAsPristine'); spyOnProperty(component.form, 'valid').and.returnValue(false); component.ngOnInit(); + component.toggleEdit(); component.update(); expect(component.form.markAsPristine).not.toHaveBeenCalled(); }); - it('should toggle edit mode', () => { - component.edit = false; + it('should disable form after calling toggleEdit if form was enabled', () => { + spyOn(component.form, 'disable'); component.toggleEdit(); - expect(component.edit).toBe(true); + expect(component.form.disable).toHaveBeenCalledWith({ + emitEvent: false + }); + }); + + it('should enable form without id field after calling toggleEdit if form was disabled', () => { + component.toggleEdit(); + spyOn(component.form, 'enable'); + spyOn(component.form.controls.id, 'disable'); component.toggleEdit(); - expect(component.edit).toBe(false); + expect(component.form.enable).toHaveBeenCalledWith({ + emitEvent: false + }); + expect(component.form.controls.id.disable).toHaveBeenCalled(); }); it('should cancel from changes', () => { fixture.detectChanges(); + component.toggleEdit(); expect(component.form.value).toEqual(siteEntryModel); @@ -252,6 +273,7 @@ describe('LibraryMetadataFormComponent', () => { expect(component.form.value.title).toBe('libraryTitle-edit'); component.cancel(); + component.toggleEdit(); expect(component.form.value).toEqual(siteEntryModel); }); @@ -328,6 +350,7 @@ describe('LibraryMetadataFormComponent', () => { it('should set proper titleErrorTranslationKey when there is error for empty title', () => { component.ngOnInit(); + component.toggleEdit(); component.form.controls.title.setValue(' '); expect(component.titleErrorTranslationKey).toBe('LIBRARY.ERRORS.ONLY_SPACES'); diff --git a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts index d44316896..5f67a8f5b 100644 --- a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts +++ b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts @@ -101,7 +101,6 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro @Input() node: SiteEntry; - edit: boolean; libraryTitleExists = false; libraryType = [ @@ -119,17 +118,22 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro matcher = new InstantErrorStateMatcher(); canUpdateLibrary = false; - visibilityLabel = ''; onDestroy$: Subject = new Subject(); constructor(private alfrescoApiService: AlfrescoApiService, protected store: Store, private actions$: Actions) {} - getVisibilityLabel(value: string) { - return this.libraryType.find((type) => type.value === value).label; - } toggleEdit() { - this.edit = !this.edit; + if (this.form.enabled) { + this.form.disable({ + emitEvent: false + }); + } else { + this.form.enable({ + emitEvent: false + }); + this.form.controls.id.disable(); + } } cancel() { @@ -139,6 +143,7 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro } ngOnInit() { + this.toggleEdit(); this.updateForm(this.node); this.form.controls.title.statusChanges .pipe(takeUntil(this.onDestroy$)) @@ -168,7 +173,6 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestro } }); this.canUpdateLibrary = this.node?.entry?.role === 'SiteManager'; - this.visibilityLabel = this.libraryType.find((type) => type.value === this.form.controls['visibility'].value).label; this.handleUpdatingEvent(SnackbarActionTypes.Info, 'LIBRARY.SUCCESS.LIBRARY_UPDATED', () => Object.assign(this.node.entry, this.form.value) ); diff --git a/projects/aca-playwright-shared/src/page-objects/components/adf-info-drawer.component.ts b/projects/aca-playwright-shared/src/page-objects/components/adf-info-drawer.component.ts index 0e859048e..b6fe6d5bc 100644 --- a/projects/aca-playwright-shared/src/page-objects/components/adf-info-drawer.component.ts +++ b/projects/aca-playwright-shared/src/page-objects/components/adf-info-drawer.component.ts @@ -35,5 +35,5 @@ export class AdfInfoDrawerComponent extends BaseComponent { public getNameField = (labelText: string) => this.getChild('[data-automation-id="library-name-properties-wrapper"]', { hasText: labelText }); public getIdField = (labelText: string) => this.getChild('[data-automation-id="library-id-properties-wrapper"]', { hasText: labelText }); public getVisibilityField = (labelText: string) => this.getChild('[data-automation-id="library-visibility-properties-wrapper"]', { hasText: labelText }); - public getDescriptionField = (labelText: string) => this.getChild('[data-automation-id="library-description-properties-wrapper"]', { hasText: labelText }); + public getDescriptionField = this.getChild('[data-automation-id="library-description-properties-wrapper"] textarea'); } diff --git a/projects/aca-testing-shared/src/components/info-drawer/info-drawer-metadata-library.ts b/projects/aca-testing-shared/src/components/info-drawer/info-drawer-metadata-library.ts index 158e2256b..ac71e3ba8 100755 --- a/projects/aca-testing-shared/src/components/info-drawer/info-drawer-metadata-library.ts +++ b/projects/aca-testing-shared/src/components/info-drawer/info-drawer-metadata-library.ts @@ -32,6 +32,8 @@ export class LibraryMetadata extends Component { visibilityPublic = this.byCssText('.mat-option .mat-option-text', 'Public', browser); visibilityPrivate = this.byCssText('.mat-option .mat-option-text', 'Private', browser); visibilityModerated = this.byCssText('.mat-option .mat-option-text', 'Moderated', browser); + visibilityValue = this.byCss('[data-automation-id="library-visibility-properties-wrapper"] .mat-select'); + hint = this.byCss('.mat-hint'); error = this.byCss('.mat-error'); @@ -57,7 +59,7 @@ export class LibraryMetadata extends Component { } private async getValueOfField(fieldName: string) { - return this.getFieldByName(fieldName).getText(); + return this.getFieldByName(fieldName).getAttribute('value'); } private async enterTextInInput(fieldName: string, text: string) { @@ -140,11 +142,11 @@ export class LibraryMetadata extends Component { } async isVisibilityDisplayed() { - return this.isFieldDisplayed('Visibility'); + return browser.isElementPresent(this.visibilityValue); } async getVisibility(): Promise { - return this.getValueOfField('Visibility'); + return this.visibilityValue.getText(); } async setVisibility(visibility: string) {