From 59dcc646da2517b3debc818ef6d5ea60ea2c17ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ja=C5=9Bkowski?= <138671284+g-jaskowski@users.noreply.github.com> Date: Fri, 7 Nov 2025 09:07:50 +0100 Subject: [PATCH] [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 --- .../content-management.service.spec.ts | 56 +++++++++++++++++++ .../services/content-management.service.ts | 1 + 2 files changed, 57 insertions(+) diff --git a/projects/aca-content/src/lib/services/content-management.service.spec.ts b/projects/aca-content/src/lib/services/content-management.service.spec.ts index 686d49656..488f43507 100644 --- a/projects/aca-content/src/lib/services/content-management.service.spec.ts +++ b/projects/aca-content/src/lib/services/content-management.service.spec.ts @@ -52,6 +52,7 @@ import { Node, NodeEntry, SiteBodyCreate, SiteEntry, UserInfo, VersionPaging } f import { DocumentListService, FileModel, + LibraryDialogComponent, NewVersionUploaderDataAction, NewVersionUploaderDialogData, NewVersionUploaderService, @@ -62,6 +63,7 @@ import { import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component'; import { provideEffects } from '@ngrx/effects'; import { ActivatedRoute, Router } from '@angular/router'; +import { EventEmitter } from '@angular/core'; describe('ContentManagementService', () => { let dialog: MatDialog; @@ -1867,6 +1869,60 @@ describe('ContentManagementService', () => { }); }); + describe('createLibrary', () => { + let dialogRefMock: jasmine.SpyObj>; + + beforeEach(() => { + dialogRefMock = jasmine.createSpyObj>('MatDialogRef', ['afterClosed'], { + componentInstance: { error: new EventEmitter() } as LibraryDialogComponent + }); + }); + + it('should open LibraryDialogComponent with autoFocus set to false', () => { + dialogRefMock.afterClosed.and.returnValue(of(null)); + spyOn(dialog, 'open').and.returnValue(dialogRefMock); + contentManagementService.createLibrary(); + + expect(dialog.open).toHaveBeenCalledWith(LibraryDialogComponent, jasmine.objectContaining({ autoFocus: false })); + }); + + it('should show library creation error notifications', () => { + dialogRefMock.afterClosed.and.returnValue(of(null)); + spyOn(dialog, 'open').and.returnValue(dialogRefMock); + contentManagementService.createLibrary(); + dialogRefMock.componentInstance.error.emit('Library creation error'); + + expect(showErrorSpy).toHaveBeenCalled(); + }); + + it('should emit guid, call libraryCreated hook and focus when site is created', (done) => { + const mockSiteEntry = new SiteEntry({ entry: { guid: 'guid', id: 'id', visibility: 'PUBLIC', title: 'title' } }); + const button = document.createElement('button'); + dialogRefMock.afterClosed.and.returnValue(of(mockSiteEntry)); + spyOn(dialog, 'open').and.returnValue(dialogRefMock); + spyOn(appHookService.libraryCreated, 'next'); + spyOn(document, 'querySelector').and.returnValue(button); + spyOn(button, 'focus'); + + contentManagementService.createLibrary().subscribe((guid) => { + expect(guid).toBe('guid'); + expect(appHookService.libraryCreated.next).toHaveBeenCalledWith(mockSiteEntry); + expect(button.focus).toHaveBeenCalled(); + done(); + }); + }); + + it('should emit null when node is missing guid', (done) => { + dialogRefMock.afterClosed.and.returnValue(of(null)); + spyOn(dialog, 'open').and.returnValue(dialogRefMock); + + contentManagementService.createLibrary().subscribe((guid) => { + expect(guid).toBeNull(); + done(); + }); + }); + }); + describe('folderInformationDialog', () => { it('should open folder information dialog', () => { spyOn(dialog, 'open'); diff --git a/projects/aca-content/src/lib/services/content-management.service.ts b/projects/aca-content/src/lib/services/content-management.service.ts index 1c2f3faaf..b0a2ab08f 100644 --- a/projects/aca-content/src/lib/services/content-management.service.ts +++ b/projects/aca-content/src/lib/services/content-management.service.ts @@ -281,6 +281,7 @@ export class ContentManagementService { createLibrary(): Observable { const dialogInstance = this.dialogRef.open(LibraryDialogComponent, { + autoFocus: false, width: '400px' });