mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACS-10222] Fixed reaching visibility dropdown for libraries using Tab key (#4897)
This commit is contained in:
+11
-4
@@ -5,9 +5,9 @@
|
|||||||
<mat-form-field floatLabel="auto" data-automation-id="library-name-properties-wrapper" class="app-library-metadata-form-field">
|
<mat-form-field floatLabel="auto" data-automation-id="library-name-properties-wrapper" class="app-library-metadata-form-field">
|
||||||
<mat-label class="app-library-metadata-form-field-label">{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}</mat-label>
|
<mat-label class="app-library-metadata-form-field-label">{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}</mat-label>
|
||||||
<input
|
<input
|
||||||
|
#libraryNameInput
|
||||||
|
data-automation-id="app-library-metadata-form-name-input"
|
||||||
matInput
|
matInput
|
||||||
[cdkTrapFocusAutoCapture]="form.enabled"
|
|
||||||
[cdkTrapFocus]="form.enabled"
|
|
||||||
required
|
required
|
||||||
placeholder="{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}"
|
placeholder="{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}"
|
||||||
formControlName="title"
|
formControlName="title"
|
||||||
@@ -54,14 +54,21 @@
|
|||||||
@if (canUpdateLibrary) {
|
@if (canUpdateLibrary) {
|
||||||
<mat-card-actions align="end">
|
<mat-card-actions align="end">
|
||||||
@if (form.enabled) {
|
@if (form.enabled) {
|
||||||
<button mat-button (click)="cancel()">
|
<button
|
||||||
|
data-automation-id="app-library-metadata-form-cancel-button"
|
||||||
|
mat-button
|
||||||
|
(click)="cancel()">
|
||||||
{{ 'LIBRARY.DIALOG.CANCEL' | translate }}
|
{{ 'LIBRARY.DIALOG.CANCEL' | translate }}
|
||||||
</button>
|
</button>
|
||||||
<button mat-button color="primary" [disabled]="form.invalid || form.pristine" (click)="update()">
|
<button mat-button color="primary" [disabled]="form.invalid || form.pristine" (click)="update()">
|
||||||
{{ 'LIBRARY.DIALOG.UPDATE' | translate }}
|
{{ 'LIBRARY.DIALOG.UPDATE' | translate }}
|
||||||
</button>
|
</button>
|
||||||
} @else {
|
} @else {
|
||||||
<button mat-button color="primary" (click)="toggleEdit()">
|
<button
|
||||||
|
mat-button
|
||||||
|
color="primary"
|
||||||
|
(click)="toggleEdit()"
|
||||||
|
data-automation-id="app-library-metadata-form-edit-button">
|
||||||
{{ 'LIBRARY.DIALOG.EDIT' | translate }}
|
{{ 'LIBRARY.DIALOG.EDIT' | translate }}
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-6
@@ -31,6 +31,8 @@ import { AppTestingModule } from '../../../testing/app-testing.module';
|
|||||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { Site, SiteBodyCreate, SiteEntry, SitePaging } from '@alfresco/js-api';
|
import { Site, SiteBodyCreate, SiteEntry, SitePaging } from '@alfresco/js-api';
|
||||||
import { of, Subject } from 'rxjs';
|
import { of, Subject } from 'rxjs';
|
||||||
|
import { UnitTestingUtils } from '@alfresco/adf-core';
|
||||||
|
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
|
||||||
|
|
||||||
describe('LibraryMetadataFormComponent', () => {
|
describe('LibraryMetadataFormComponent', () => {
|
||||||
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
|
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
|
||||||
@@ -38,6 +40,11 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
let store: Store<any>;
|
let store: Store<any>;
|
||||||
let siteEntryModel: SiteBodyCreate;
|
let siteEntryModel: SiteBodyCreate;
|
||||||
let appHookService: AppHookService;
|
let appHookService: AppHookService;
|
||||||
|
let unitTestingUtils: UnitTestingUtils;
|
||||||
|
|
||||||
|
const getNameInput = (): HTMLInputElement => unitTestingUtils.getInputByDataAutomationId('app-library-metadata-form-name-input');
|
||||||
|
|
||||||
|
const clickEditButton = (): Promise<void> => unitTestingUtils.clickMatButtonByDataAutomationId('app-library-metadata-form-edit-button');
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -77,6 +84,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
...siteEntryModel
|
...siteEntryModel
|
||||||
} as Site
|
} as Site
|
||||||
};
|
};
|
||||||
|
unitTestingUtils = new UnitTestingUtils(fixture.debugElement, TestbedHarnessEnvironment.loader(fixture));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should initialize form with node data', () => {
|
it('should initialize form with node data', () => {
|
||||||
@@ -159,7 +167,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
component.node.entry.role = Site.RoleEnum.SiteManager;
|
component.node.entry.role = Site.RoleEnum.SiteManager;
|
||||||
siteEntryModel.title = ' some title ';
|
siteEntryModel.title = ' some title ';
|
||||||
component.node.entry.title = siteEntryModel.title;
|
component.node.entry.title = siteEntryModel.title;
|
||||||
component.ngOnInit();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
|
|
||||||
component.update();
|
component.update();
|
||||||
@@ -176,7 +184,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
it('should call markAsPristine on form when updating valid form and has permission to update', () => {
|
it('should call markAsPristine on form when updating valid form and has permission to update', () => {
|
||||||
component.node.entry.role = Site.RoleEnum.SiteManager;
|
component.node.entry.role = Site.RoleEnum.SiteManager;
|
||||||
spyOn(component.form, 'markAsPristine');
|
spyOn(component.form, 'markAsPristine');
|
||||||
component.ngOnInit();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
|
|
||||||
component.update();
|
component.update();
|
||||||
@@ -209,7 +217,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
it('should not call markAsPristine on form when updating valid form but has not permission to update', () => {
|
it('should not call markAsPristine on form when updating valid form but has not permission to update', () => {
|
||||||
component.node.entry.role = Site.RoleEnum.SiteConsumer;
|
component.node.entry.role = Site.RoleEnum.SiteConsumer;
|
||||||
spyOn(component.form, 'markAsPristine');
|
spyOn(component.form, 'markAsPristine');
|
||||||
component.ngOnInit();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
|
|
||||||
component.update();
|
component.update();
|
||||||
@@ -233,7 +241,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
component.node.entry.role = Site.RoleEnum.SiteManager;
|
component.node.entry.role = Site.RoleEnum.SiteManager;
|
||||||
spyOn(component.form, 'markAsPristine');
|
spyOn(component.form, 'markAsPristine');
|
||||||
spyOnProperty(component.form, 'valid').and.returnValue(false);
|
spyOnProperty(component.form, 'valid').and.returnValue(false);
|
||||||
component.ngOnInit();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
|
|
||||||
component.update();
|
component.update();
|
||||||
@@ -250,7 +258,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should enable form without id field after calling toggleEdit if form was disabled', () => {
|
it('should enable form without id field after calling toggleEdit if form was disabled', () => {
|
||||||
component.toggleEdit();
|
fixture.detectChanges();
|
||||||
spyOn(component.form, 'enable');
|
spyOn(component.form, 'enable');
|
||||||
spyOn(component.form.controls.id, 'disable');
|
spyOn(component.form.controls.id, 'disable');
|
||||||
|
|
||||||
@@ -261,6 +269,27 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
expect(component.form.controls.id.disable).toHaveBeenCalled();
|
expect(component.form.controls.id.disable).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call focus on name input after clicking on edit button', async () => {
|
||||||
|
component.node.entry.role = Site.RoleEnum.SiteManager;
|
||||||
|
fixture.detectChanges();
|
||||||
|
const nameInput = getNameInput();
|
||||||
|
spyOn(nameInput, 'focus');
|
||||||
|
|
||||||
|
await clickEditButton();
|
||||||
|
expect(nameInput.focus).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not call focus on name input after clicking on cancel button', async () => {
|
||||||
|
component.node.entry.role = Site.RoleEnum.SiteManager;
|
||||||
|
fixture.detectChanges();
|
||||||
|
await clickEditButton();
|
||||||
|
const nameInput = getNameInput();
|
||||||
|
spyOn(nameInput, 'focus');
|
||||||
|
|
||||||
|
await unitTestingUtils.clickMatButtonByDataAutomationId('app-library-metadata-form-cancel-button');
|
||||||
|
expect(nameInput.focus).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should cancel from changes', () => {
|
it('should cancel from changes', () => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
@@ -348,7 +377,7 @@ describe('LibraryMetadataFormComponent', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should set proper titleErrorTranslationKey when there is error for empty title', () => {
|
it('should set proper titleErrorTranslationKey when there is error for empty title', () => {
|
||||||
component.ngOnInit();
|
fixture.detectChanges();
|
||||||
component.toggleEdit();
|
component.toggleEdit();
|
||||||
|
|
||||||
component.form.controls.title.setValue(' ');
|
component.form.controls.title.setValue(' ');
|
||||||
|
|||||||
+4
-3
@@ -22,7 +22,7 @@
|
|||||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, DestroyRef, inject, Input, OnChanges, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, DestroyRef, ElementRef, inject, Input, OnChanges, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
FormControl,
|
FormControl,
|
||||||
FormGroupDirective,
|
FormGroupDirective,
|
||||||
@@ -47,7 +47,6 @@ import { TranslatePipe } from '@ngx-translate/core';
|
|||||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
import { MatSelectModule } from '@angular/material/select';
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
import { MatInputModule } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { A11yModule } from '@angular/cdk/a11y';
|
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
import { NgForOf } from '@angular/common';
|
import { NgForOf } from '@angular/common';
|
||||||
@@ -69,7 +68,6 @@ export class InstantErrorStateMatcher implements ErrorStateMatcher {
|
|||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
MatOptionModule,
|
MatOptionModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
A11yModule,
|
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
NgForOf
|
NgForOf
|
||||||
],
|
],
|
||||||
@@ -113,6 +111,8 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges {
|
|||||||
canUpdateLibrary = false;
|
canUpdateLibrary = false;
|
||||||
isAdmin = false;
|
isAdmin = false;
|
||||||
|
|
||||||
|
@ViewChild('libraryNameInput')
|
||||||
|
private readonly libraryNameInput: ElementRef<HTMLInputElement>;
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -131,6 +131,7 @@ export class LibraryMetadataFormComponent implements OnInit, OnChanges {
|
|||||||
emitEvent: false
|
emitEvent: false
|
||||||
});
|
});
|
||||||
this.form.controls.id.disable();
|
this.form.controls.id.disable();
|
||||||
|
this.libraryNameInput.nativeElement.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user