diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts index 2c50237ad2..88e19e99fd 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts @@ -142,12 +142,6 @@ describe('ContentNodeDialogService', () => { expect(spyOnDialogOpen).toHaveBeenCalled(); })); - it('should be able to close the material dialog', () => { - spyOn(materialDialog, 'closeAll'); - service.close(); - expect(materialDialog.closeAll).toHaveBeenCalled(); - }); - describe('for the copy/move dialog', () => { const siteNode: Node = { id: 'site-node-id', diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts index 87f5f4fe44..841df27b70 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts @@ -143,9 +143,6 @@ export class ContentNodeDialogService { if (this.contentService.hasAllowableOperations(contentEntry, permission)) { const select = new Subject(); - select.subscribe({ - complete: this.close.bind(this) - }); const data: ContentNodeSelectorComponentData = { title: this.getTitleTranslation(action, contentEntry.name), @@ -186,9 +183,6 @@ export class ContentNodeDialogService { */ openUploadFolderDialog(action: NodeAction, contentEntry: Node): Observable { const select = new Subject(); - select.subscribe({ - complete: this.close.bind(this) - }); const data: ContentNodeSelectorComponentData = { title: this.getTitleTranslation(action, this.translation.instant('DROPDOWN.MY_FILES_OPTION')), @@ -214,9 +208,6 @@ export class ContentNodeDialogService { */ openUploadFileDialog(action: NodeAction, contentEntry: Node, showFilesInResult = false): Observable { const select = new Subject(); - select.subscribe({ - complete: this.close.bind(this) - }); const data: ContentNodeSelectorComponentData = { title: this.getTitleTranslation(action, this.translation.instant('DROPDOWN.MY_FILES_OPTION')), @@ -273,9 +264,4 @@ export class ContentNodeDialogService { return !!entry.guid || entry.nodeType === 'st:site' || entry.nodeType === 'st:sites'; } - /** Closes the currently open dialog. */ - close() { - this.dialog.closeAll(); - } - } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts index cd06e99455..25ff92d81e 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts @@ -37,6 +37,7 @@ describe('ContentNodeSelectorComponent', () => { let fixture: ComponentFixture; let data: any; let uploadService: UploadService; + let dialog: MatDialogRef; beforeEach(() => { data = { @@ -73,6 +74,7 @@ describe('ContentNodeSelectorComponent', () => { const documentListService = TestBed.inject(DocumentListService); const sitesService: SitesService = TestBed.inject(SitesService); + dialog = TestBed.inject(MatDialogRef); uploadService = TestBed.inject(UploadService); spyOn(documentListService, 'getFolder').and.callThrough(); @@ -193,6 +195,23 @@ describe('ContentNodeSelectorComponent', () => { const closeButton = fixture.debugElement.query(By.css('[content-node-selector-actions-cancel]')); expect(closeButton).toBeNull(); }); + + it('should close the dialog', () => { + let cancelButton; + data.select.subscribe( + () => { + }, + () => { + }, + () => { + cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]')); + expect(cancelButton).not.toBeNull(); + }); + + cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]')); + cancelButton.triggerEventHandler('click', {}); + expect(dialog.close).toHaveBeenCalled(); + }); }); describe('Action button for the chosen node', () => { @@ -227,6 +246,16 @@ describe('ContentNodeSelectorComponent', () => { expect(actionButtonWithoutNodeSelected.nativeElement.disabled).toBe(true); }); + + it('should close the dialog when action button is clicked', async () => { + component.onSelect([new Node({ id: 'fake' })]); + fixture.detectChanges(); + + const actionButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-choose"]')); + await actionButton.nativeElement.click(); + + expect(dialog.close).toHaveBeenCalled(); + }); }); describe('Title', () => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts index 12f29ab5d5..6203b80b9a 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts @@ -77,6 +77,7 @@ export class ContentNodeSelectorComponent implements OnInit { close() { this.data.select.complete(); + this.dialog.close(); } onSelect(nodeList: Node[]) { @@ -94,7 +95,7 @@ export class ContentNodeSelectorComponent implements OnInit { onClick(): void { this.data.select.next(this.chosenNode); - this.data.select.complete(); + this.close(); } updateTitle(siteTitle: string) {