From 8a184efc6cf96f70dc53ed448d22d4244d09a53c Mon Sep 17 00:00:00 2001 From: Wiktor Danielewski <63188869+wiktord2000@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:40:50 +0100 Subject: [PATCH] [AAE-8556] Convert attach file manual test case to unit test (#9108) * [AAE-8556] Update attach file dialog service * [AAE-8556] Update attach file dialog * [AAE-8556] Align with remarks * [AAE-8556] Switch to https --- ...ttach-file-widget-dialog.component.spec.ts | 31 +++++++++++++------ .../attach-file-widget-dialog.service.spec.ts | 17 +++++++++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts index d7a2270f11..5c674c8c61 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.component.spec.ts @@ -38,7 +38,8 @@ describe('AttachFileWidgetDialogComponent', () => { actionName: 'Choose', currentFolderId: '-my-', selected: new EventEmitter(), - ecmHost: 'http://fakeUrl.com' + ecmHost: 'https://fakeUrl.com', + isSelectionValid: (entry: Node) => entry.isFile }; let element: HTMLInputElement; let basicAlfrescoAuthService: BasicAlfrescoAuthService; @@ -104,13 +105,13 @@ describe('AttachFileWidgetDialogComponent', () => { expect(element.querySelector('#attach-file-login-panel')).not.toBeNull(); expect(element.querySelector('#username')).not.toBeNull(); expect(element.querySelector('#password')).not.toBeNull(); - expect(element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]')).not.toBeNull(); + expect(element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]')).not.toBeNull(); }); it('should be able to login', (done) => { spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); isLogged = true; - let loginButton: HTMLButtonElement = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); + let loginButton: HTMLButtonElement = element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]'); const usernameInput: HTMLInputElement = element.querySelector('#username'); const passwordInput: HTMLInputElement = element.querySelector('#password'); usernameInput.value = 'fakse-user'; @@ -121,8 +122,8 @@ describe('AttachFileWidgetDialogComponent', () => { fixture.detectChanges(); fixture.whenStable().then(() => { expect(element.querySelector('#attach-file-content-node')).not.toBeNull(); - loginButton = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); - const chooseButton = element.querySelector('button[data-automation-id="attach-file-dialog-actions-choose"]'); + loginButton = element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]'); + const chooseButton = element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]'); expect(loginButton).toBeNull(); expect(chooseButton).not.toBeNull(); done(); @@ -144,10 +145,10 @@ describe('AttachFileWidgetDialogComponent', () => { expect(element.querySelector('#attach-file-content-node')).not.toBeNull(); expect(element.querySelector('#username')).toBeNull(); expect(element.querySelector('#password')).toBeNull(); - expect(element.querySelector('button[data-automation-id="attach-file-dialog-actions-choose"]')).not.toBeNull(); + expect(element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]')).not.toBeNull(); }); - it('should be able to select a file', (done) => { + it('should be able to choose a file', (done) => { data.selected.subscribe((nodeList: Node[]) => { expect(nodeList[0].id).toBe('fake'); expect(nodeList[0].isFile).toBeTruthy(); @@ -157,11 +158,23 @@ describe('AttachFileWidgetDialogComponent', () => { contentNodePanel.componentInstance.select.emit([fakeNode]); fixture.detectChanges(); fixture.whenStable().then(() => { - const chooseButton: HTMLButtonElement = element.querySelector('button[data-automation-id="attach-file-dialog-actions-choose"]'); + const chooseButton: HTMLButtonElement = element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]'); chooseButton.click(); }); }); + it('[C594015] should not be able to choose a folder', () => { + spyOn(widget,'onSelect'); + const fakeFolderNode: Node = new Node({ id: 'fakeFolder', isFile: false, isFolder: true}); + + contentNodePanel.componentInstance.onCurrentSelection([ { entry: fakeFolderNode }]); + fixture.detectChanges(); + + const chooseButton: HTMLButtonElement = element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]'); + expect(chooseButton.disabled).toBe(true); + expect(widget.onSelect).toHaveBeenCalledOnceWith([]); + }); + it('should update the title when a site is selected', () => { const fakeSiteTitle = 'My fake site'; contentNodePanel.componentInstance.siteChange.emit(fakeSiteTitle); @@ -186,7 +199,7 @@ describe('AttachFileWidgetDialogComponent', () => { it('should close the dialog once user loggedIn', () => { fixture.detectChanges(); isLogged = true; - const loginButton = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); + const loginButton = element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]'); const usernameInput = element.querySelector('#username'); const passwordInput = element.querySelector('#password'); usernameInput.value = 'fake-user'; diff --git a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts index fc8e39146c..744b120236 100644 --- a/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts +++ b/lib/process-services/src/lib/form/widgets/content-widget/attach-file-widget-dialog.service.spec.ts @@ -21,12 +21,14 @@ import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.servi import { Subject, of } from 'rxjs'; import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { AlfrescoEndpointRepresentation } from '@alfresco/js-api'; describe('AttachFileWidgetDialogService', () => { let service: AttachFileWidgetDialogService; let materialDialog: MatDialog; let spyOnDialogOpen: jasmine.Spy; + let mockRepository: AlfrescoEndpointRepresentation; beforeEach(() => { TestBed.configureTestingModule({ @@ -44,10 +46,11 @@ describe('AttachFileWidgetDialogService', () => { error: new Subject() } } as any); + mockRepository = { id: 1, name: 'fake-title', repositoryUrl: 'https://fakeurl.com/alfresco' }; }); it('should be able to open the dialog when node has permission', () => { - service.openLogin({ id: 1, name: 'fake-title', repositoryUrl: 'http://fakeurl.com/alfresco' }, 'fake-action'); + service.openLogin(mockRepository, 'fake-action'); expect(spyOnDialogOpen).toHaveBeenCalled(); }); @@ -56,4 +59,16 @@ describe('AttachFileWidgetDialogService', () => { service.close(); expect(materialDialog.closeAll).toHaveBeenCalled(); }); + + it('should attach predicate on dialog opening which accepts only file nodes', () => { + const spyOnOpenLoginDialog = spyOn((service as any), 'openLoginDialog'); + + service.openLogin(mockRepository, 'fake-action'); + + expect(spyOnOpenLoginDialog).toHaveBeenCalledTimes(1); + const actualIsSelectionValid = (spyOnOpenLoginDialog.calls.mostRecent().args[0] as any).isSelectionValid; + + expect(actualIsSelectionValid({ isFile: true, isFolder: false })).toBe(true); + expect(actualIsSelectionValid({ isFile: false, isFolder: true })).toBe(false); + }); });