@@ -52,6 +52,7 @@ import { Node, NodeEntry, SiteBodyCreate, SiteEntry, UserInfo, VersionPaging } f
5252import {
5353 DocumentListService ,
5454 FileModel ,
55+ LibraryDialogComponent ,
5556 NewVersionUploaderDataAction ,
5657 NewVersionUploaderDialogData ,
5758 NewVersionUploaderService ,
@@ -62,6 +63,7 @@ import {
6263import { FolderInformationComponent } from '../dialogs/folder-details/folder-information.component' ;
6364import { provideEffects } from '@ngrx/effects' ;
6465import { ActivatedRoute , Router } from '@angular/router' ;
66+ import { EventEmitter } from '@angular/core' ;
6567
6668describe ( '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' ) ;
0 commit comments