[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
This commit is contained in:
Wiktor Danielewski 2023-11-29 17:40:50 +01:00 committed by GitHub
parent 500c5581f6
commit 8a184efc6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 10 deletions

View File

@ -38,7 +38,8 @@ describe('AttachFileWidgetDialogComponent', () => {
actionName: 'Choose', actionName: 'Choose',
currentFolderId: '-my-', currentFolderId: '-my-',
selected: new EventEmitter<any>(), selected: new EventEmitter<any>(),
ecmHost: 'http://fakeUrl.com' ecmHost: 'https://fakeUrl.com',
isSelectionValid: (entry: Node) => entry.isFile
}; };
let element: HTMLInputElement; let element: HTMLInputElement;
let basicAlfrescoAuthService: BasicAlfrescoAuthService; let basicAlfrescoAuthService: BasicAlfrescoAuthService;
@ -104,13 +105,13 @@ describe('AttachFileWidgetDialogComponent', () => {
expect(element.querySelector('#attach-file-login-panel')).not.toBeNull(); expect(element.querySelector('#attach-file-login-panel')).not.toBeNull();
expect(element.querySelector('#username')).not.toBeNull(); expect(element.querySelector('#username')).not.toBeNull();
expect(element.querySelector('#password')).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) => { it('should be able to login', (done) => {
spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'})); spyOn(basicAlfrescoAuthService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket'}));
isLogged = true; 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 usernameInput: HTMLInputElement = element.querySelector('#username');
const passwordInput: HTMLInputElement = element.querySelector('#password'); const passwordInput: HTMLInputElement = element.querySelector('#password');
usernameInput.value = 'fakse-user'; usernameInput.value = 'fakse-user';
@ -121,8 +122,8 @@ describe('AttachFileWidgetDialogComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(element.querySelector('#attach-file-content-node')).not.toBeNull(); expect(element.querySelector('#attach-file-content-node')).not.toBeNull();
loginButton = element.querySelector('button[data-automation-id="attach-file-dialog-actions-login"]'); loginButton = element.querySelector('[data-automation-id="attach-file-dialog-actions-login"]');
const chooseButton = element.querySelector('button[data-automation-id="attach-file-dialog-actions-choose"]'); const chooseButton = element.querySelector('[data-automation-id="attach-file-dialog-actions-choose"]');
expect(loginButton).toBeNull(); expect(loginButton).toBeNull();
expect(chooseButton).not.toBeNull(); expect(chooseButton).not.toBeNull();
done(); done();
@ -144,10 +145,10 @@ describe('AttachFileWidgetDialogComponent', () => {
expect(element.querySelector('#attach-file-content-node')).not.toBeNull(); expect(element.querySelector('#attach-file-content-node')).not.toBeNull();
expect(element.querySelector('#username')).toBeNull(); expect(element.querySelector('#username')).toBeNull();
expect(element.querySelector('#password')).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[]) => { data.selected.subscribe((nodeList: Node[]) => {
expect(nodeList[0].id).toBe('fake'); expect(nodeList[0].id).toBe('fake');
expect(nodeList[0].isFile).toBeTruthy(); expect(nodeList[0].isFile).toBeTruthy();
@ -157,11 +158,23 @@ describe('AttachFileWidgetDialogComponent', () => {
contentNodePanel.componentInstance.select.emit([fakeNode]); contentNodePanel.componentInstance.select.emit([fakeNode]);
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { 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(); 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', () => { it('should update the title when a site is selected', () => {
const fakeSiteTitle = 'My fake site'; const fakeSiteTitle = 'My fake site';
contentNodePanel.componentInstance.siteChange.emit(fakeSiteTitle); contentNodePanel.componentInstance.siteChange.emit(fakeSiteTitle);
@ -186,7 +199,7 @@ describe('AttachFileWidgetDialogComponent', () => {
it('should close the dialog once user loggedIn', () => { it('should close the dialog once user loggedIn', () => {
fixture.detectChanges(); fixture.detectChanges();
isLogged = true; isLogged = true;
const loginButton = element.querySelector<HTMLButtonElement>('button[data-automation-id="attach-file-dialog-actions-login"]'); const loginButton = element.querySelector<HTMLButtonElement>('[data-automation-id="attach-file-dialog-actions-login"]');
const usernameInput = element.querySelector<HTMLInputElement>('#username'); const usernameInput = element.querySelector<HTMLInputElement>('#username');
const passwordInput = element.querySelector<HTMLInputElement>('#password'); const passwordInput = element.querySelector<HTMLInputElement>('#password');
usernameInput.value = 'fake-user'; usernameInput.value = 'fake-user';

View File

@ -21,12 +21,14 @@ import { AttachFileWidgetDialogService } from './attach-file-widget-dialog.servi
import { Subject, of } from 'rxjs'; import { Subject, of } from 'rxjs';
import { ProcessTestingModule } from '../../../testing/process.testing.module'; import { ProcessTestingModule } from '../../../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { AlfrescoEndpointRepresentation } from '@alfresco/js-api';
describe('AttachFileWidgetDialogService', () => { describe('AttachFileWidgetDialogService', () => {
let service: AttachFileWidgetDialogService; let service: AttachFileWidgetDialogService;
let materialDialog: MatDialog; let materialDialog: MatDialog;
let spyOnDialogOpen: jasmine.Spy; let spyOnDialogOpen: jasmine.Spy;
let mockRepository: AlfrescoEndpointRepresentation;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
@ -44,10 +46,11 @@ describe('AttachFileWidgetDialogService', () => {
error: new Subject<any>() error: new Subject<any>()
} }
} as any); } 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', () => { 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(); expect(spyOnDialogOpen).toHaveBeenCalled();
}); });
@ -56,4 +59,16 @@ describe('AttachFileWidgetDialogService', () => {
service.close(); service.close();
expect(materialDialog.closeAll).toHaveBeenCalled(); 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);
});
}); });