Skip to content

Commit 59dcc64

Browse files
authored
[ACS-10196] other a11y all libraries error message not provided for name and library id fields (#4883)
* [ACS-10196] prevent instant error validation on create library dialog opening * [ACS-10196] add unit tests * [ACS-10196] review fix
1 parent 71eee98 commit 59dcc64

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

projects/aca-content/src/lib/services/content-management.service.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { Node, NodeEntry, SiteBodyCreate, SiteEntry, UserInfo, VersionPaging } f
5252
import {
5353
DocumentListService,
5454
FileModel,
55+
LibraryDialogComponent,
5556
NewVersionUploaderDataAction,
5657
NewVersionUploaderDialogData,
5758
NewVersionUploaderService,
@@ -62,6 +63,7 @@ import {
6263
import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component';
6364
import { provideEffects } from '@ngrx/effects';
6465
import { ActivatedRoute, Router } from '@angular/router';
66+
import { EventEmitter } from '@angular/core';
6567

6668
describe('ContentManagementService', () => {
6769
let dialog: MatDialog;
@@ -1867,6 +1869,60 @@ describe('ContentManagementService', () => {
18671869
});
18681870
});
18691871

1872+
describe('createLibrary', () => {
1873+
let dialogRefMock: jasmine.SpyObj<MatDialogRef<LibraryDialogComponent, SiteEntry | null>>;
1874+
1875+
beforeEach(() => {
1876+
dialogRefMock = jasmine.createSpyObj<MatDialogRef<LibraryDialogComponent, SiteEntry | null>>('MatDialogRef', ['afterClosed'], {
1877+
componentInstance: { error: new EventEmitter<string>() } as LibraryDialogComponent
1878+
});
1879+
});
1880+
1881+
it('should open LibraryDialogComponent with autoFocus set to false', () => {
1882+
dialogRefMock.afterClosed.and.returnValue(of(null));
1883+
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
1884+
contentManagementService.createLibrary();
1885+
1886+
expect(dialog.open).toHaveBeenCalledWith(LibraryDialogComponent, jasmine.objectContaining({ autoFocus: false }));
1887+
});
1888+
1889+
it('should show library creation error notifications', () => {
1890+
dialogRefMock.afterClosed.and.returnValue(of(null));
1891+
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
1892+
contentManagementService.createLibrary();
1893+
dialogRefMock.componentInstance.error.emit('Library creation error');
1894+
1895+
expect(showErrorSpy).toHaveBeenCalled();
1896+
});
1897+
1898+
it('should emit guid, call libraryCreated hook and focus when site is created', (done) => {
1899+
const mockSiteEntry = new SiteEntry({ entry: { guid: 'guid', id: 'id', visibility: 'PUBLIC', title: 'title' } });
1900+
const button = document.createElement('button');
1901+
dialogRefMock.afterClosed.and.returnValue(of(mockSiteEntry));
1902+
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
1903+
spyOn(appHookService.libraryCreated, 'next');
1904+
spyOn(document, 'querySelector').and.returnValue(button);
1905+
spyOn(button, 'focus');
1906+
1907+
contentManagementService.createLibrary().subscribe((guid) => {
1908+
expect(guid).toBe('guid');
1909+
expect(appHookService.libraryCreated.next).toHaveBeenCalledWith(mockSiteEntry);
1910+
expect(button.focus).toHaveBeenCalled();
1911+
done();
1912+
});
1913+
});
1914+
1915+
it('should emit null when node is missing guid', (done) => {
1916+
dialogRefMock.afterClosed.and.returnValue(of(null));
1917+
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
1918+
1919+
contentManagementService.createLibrary().subscribe((guid) => {
1920+
expect(guid).toBeNull();
1921+
done();
1922+
});
1923+
});
1924+
});
1925+
18701926
describe('folderInformationDialog', () => {
18711927
it('should open folder information dialog', () => {
18721928
spyOn(dialog, 'open');

projects/aca-content/src/lib/services/content-management.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export class ContentManagementService {
281281

282282
createLibrary(): Observable<string> {
283283
const dialogInstance = this.dialogRef.open(LibraryDialogComponent, {
284+
autoFocus: false,
284285
width: '400px'
285286
});
286287

0 commit comments

Comments
 (0)