[AAE-10320] Fix Content Service unit tests - 'has no expectations' (#7840)

* fix node action services unit tests

* fix add permission panel units

* fix some upload unit tests

* fix some search unit tests

* remove duplicated unit tests

* [AAE-10320] fix content and document list unit tests

* remove duplicated content node selector  unit test

* fix upload unit test
This commit is contained in:
Tomasz Gnyp
2022-09-30 22:16:07 +02:00
committed by GitHub
parent 4d8195fa82
commit 39a178f653
14 changed files with 275 additions and 387 deletions

View File

@@ -26,6 +26,19 @@ import { ContentTypePropertiesService } from './content-type-property.service';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { PropertyDescriptorsService } from './property-descriptors.service';
const fakeNode: Node = {
name: 'Node',
id: 'fake-id',
isFile: true,
aspectNames: ['exif:exif'],
nodeType: 'fn:fakenode',
createdByUser: {displayName: 'test-user'},
modifiedByUser: {displayName: 'test-user-modified'},
properties: []
} as Node;
const fakeContentNode: Node = { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } as Node;
describe('ContentMetaDataService', () => {
let service: ContentMetadataService;
@@ -74,15 +87,6 @@ describe('ContentMetaDataService', () => {
});
it('should return all the properties of the node', () => {
const fakeNode: Node = {
name: 'Node',
id: 'fake-id',
isFile: true,
aspectNames: ['exif:exif'],
createdByUser: {displayName: 'test-user'},
modifiedByUser: {displayName: 'test-user-modified'}
} as Node;
service.getBasicProperties(fakeNode).subscribe(
(res) => {
expect(res.length).toEqual(10);
@@ -94,16 +98,6 @@ describe('ContentMetaDataService', () => {
});
it('should return the content type property', () => {
const fakeNode: Node = {
name: 'Node',
id: 'fake-id',
isFile: true,
aspectNames: ['exif:exif'],
nodeType: 'fn:fakenode',
createdByUser: {displayName: 'test-user'},
modifiedByUser: {displayName: 'test-user-modified'},
properties: []
} as Node;
spyOn(contentPropertyService, 'getContentTypeCardItem').and.returnValue(of({ label: 'hello i am a weird content type'} as any));
service.getContentTypeProperty(fakeNode).subscribe(
@@ -116,9 +110,9 @@ describe('ContentMetaDataService', () => {
});
it('should trigger the opening of the content type dialog', () => {
spyOn(contentPropertyService, 'openContentTypeDialogConfirm').and.returnValue(of());
spyOn(contentPropertyService, 'openContentTypeDialogConfirm').and.returnValue(of(true));
service.openConfirmDialog('fn:fakenode').subscribe(
service.openConfirmDialog(fakeNode).subscribe(
() => {
expect(contentPropertyService.openContentTypeDialogConfirm).toHaveBeenCalledWith('fn:fakenode');
}
@@ -128,7 +122,6 @@ describe('ContentMetaDataService', () => {
describe('AspectOriented preset', () => {
it('should return response with exif property', (done) => {
const fakeNode: Node = { name: 'Node', id: 'fake-id', isFile: true, aspectNames: ['exif:exif'] } as Node;
setConfig('default', { 'exif:exif': '*' });
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
@@ -146,7 +139,6 @@ describe('ContentMetaDataService', () => {
});
it('should filter the record options for node ', (done) => {
const fakeNode: Node = { name: 'Node', id: 'fake-id', isFile: true, aspectNames: ['exif:exif'] } as Node;
setConfig('default', { 'exif:exif': '*', 'rma:record': '*' });
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
@@ -167,8 +159,6 @@ describe('ContentMetaDataService', () => {
describe('LayoutOriented preset', () => {
it('should return the node property', (done) => {
const fakeNode: Node = { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } as Node;
const customLayoutOrientedScheme = [
{
id: 'app.content.metadata.customGroup2',
@@ -186,7 +176,7 @@ describe('ContentMetaDataService', () => {
setConfig('custom', customLayoutOrientedScheme);
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
service.getGroupedProperties(fakeNode, 'custom').subscribe(
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
(res) => {
expect(res.length).toEqual(1);
expect(res[0].title).toEqual('Properties');
@@ -199,8 +189,6 @@ describe('ContentMetaDataService', () => {
});
it('should filter the exif property', (done) => {
const fakeNode: Node = { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } as Node;
const customLayoutOrientedScheme = [
{
id: 'app.content.metadata.customGroup',
@@ -229,7 +217,7 @@ describe('ContentMetaDataService', () => {
setConfig('custom', customLayoutOrientedScheme);
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
service.getGroupedProperties(fakeNode, 'custom').subscribe(
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
(res) => {
expect(res.length).toEqual(1);
expect(res[0].title).toEqual('Properties');
@@ -242,8 +230,6 @@ describe('ContentMetaDataService', () => {
});
it('should exclude the property if this property is excluded from config', (done) => {
const fakeNode: Node = { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } as Node;
const customLayoutOrientedScheme = [
{
id: 'app.content.metadata.customGroup',
@@ -263,7 +249,7 @@ describe('ContentMetaDataService', () => {
setConfig('custom', customLayoutOrientedScheme);
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
service.getGroupedProperties(fakeNode, 'custom').subscribe(
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
(res) => {
expect(res.length).toEqual(0);
done();
@@ -277,8 +263,6 @@ describe('ContentMetaDataService', () => {
describe('Provided preset config', () => {
it('should create the metadata config on the fly when preset config is provided', (done) => {
const fakeNode: Node = { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } as Node;
const customLayoutOrientedScheme = [
{
id: 'app.content.metadata.customGroup',
@@ -306,7 +290,7 @@ describe('ContentMetaDataService', () => {
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
service.getGroupedProperties(fakeNode, customLayoutOrientedScheme).subscribe(
service.getGroupedProperties(fakeContentNode, customLayoutOrientedScheme).subscribe(
(res) => {
expect(res.length).toEqual(1);
expect(res[0].title).toEqual('Properties');

View File

@@ -468,32 +468,6 @@ describe('ContentNodeSelectorPanelComponent', () => {
component.isSelectionValid = returnHasPermission;
});
it('should NOT be null after selecting node with the necessary permissions', async () => {
hasAllowableOperations = true;
component.documentList.folderNode = entry;
component.select.subscribe((nodes) => {
expect(nodes).toBeDefined();
expect(nodes).not.toBeNull();
expect(component.chosenNode[0]).toBe(entry);
});
component.documentList.ready.emit(nodePage);
});
it('should be null after selecting node without the necessary permissions', async () => {
hasAllowableOperations = false;
component.documentList.folderNode = entry;
component.select.subscribe((nodes) => {
expect(nodes).toBeDefined();
expect(nodes).toBeNull();
expect(component.chosenNode).toBeNull();
});
component.documentList.ready.emit(nodePage);
});
it('should NOT be null after clicking on a node (with the right permissions) in the list (onNodeSelect)', async () => {
hasAllowableOperations = true;

View File

@@ -177,43 +177,19 @@ describe('ContentNodeSelectorComponent', () => {
});
describe('Cancel button', () => {
it('should complete the data stream when user click "CANCEL"', () => {
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', {});
});
it('should not be shown if dialogRef is NOT injected', () => {
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"]'));
let cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]'));
cancelButton.triggerEventHandler('click', {});
expect(dialog.close).toHaveBeenCalled();
fixture.detectChanges();
cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]'));
expect(cancelButton).not.toBeNull();
});
});

View File

@@ -46,11 +46,10 @@ describe('NodeCounterDirective', () => {
fixture.detectChanges();
});
it('should display the counter component', () => {
fixture.whenStable().then(() => {
const counterElement = fixture.debugElement.query(By.css('adf-node-counter'));
expect(counterElement).not.toBeNull();
expect(counterElement.nativeElement.innerText).toBe('NODE_COUNTER.SELECTED_COUNT');
});
it('should display the counter component', async () => {
await fixture.whenStable();
const counterElement = fixture.debugElement.query(By.css('adf-node-counter'));
expect(counterElement).not.toBeNull();
expect(counterElement.nativeElement.innerText).toBe('NODE_COUNTER.SELECTED_COUNT');
});
});

View File

@@ -17,7 +17,7 @@
import { setupTestBed } from '@alfresco/adf-core';
import { DocumentListService } from './document-list.service';
import { TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
@@ -77,7 +77,7 @@ describe('DocumentListService', () => {
jasmine.Ajax.uninstall();
});
it('should return the folder info', () => {
it('should return the folder info', fakeAsync(() => {
service.getFolder('/fake-root/fake-name').subscribe(
(res) => {
expect(res).toBeDefined();
@@ -94,7 +94,7 @@ describe('DocumentListService', () => {
contentType: 'json',
responseText: fakeFolder
});
});
}));
it('should add the includeTypes in the request Node Children if required', () => {
const spyGetNodeInfo = spyOn(service['nodes'], 'listNodeChildren').and.callThrough();
@@ -143,7 +143,7 @@ describe('DocumentListService', () => {
);
});
it('should delete the folder', () => {
it('should delete the folder', fakeAsync(() => {
service.deleteNode('fake-id').subscribe(
(res) => {
expect(res).toBe('');
@@ -154,7 +154,7 @@ describe('DocumentListService', () => {
status: 204,
contentType: 'json'
});
});
}));
it('should copy a node', (done) => {
service.copyNode('node-id', 'parent-id').subscribe(() => done());

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { fakeAsync, TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Node, NodeEntry } from '@alfresco/js-api';
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
import { DocumentListService } from './document-list.service';
@@ -25,6 +25,7 @@ import { of, throwError } from 'rxjs';
import { MatDialogRef } from '@angular/material/dialog';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { delay } from 'rxjs/operators';
const fakeNode: Node = {
id: 'fake'
@@ -56,51 +57,58 @@ describe('NodeActionsService', () => {
service = TestBed.inject(NodeActionsService);
documentListService = TestBed.inject(DocumentListService);
contentDialogService = TestBed.inject(ContentNodeDialogService);
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]).pipe(delay(100)));
});
it('should be able to copy content', fakeAsync(() => {
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
service.copyContent(fakeNode, 'allowed').subscribe((value) => {
expect(value).toBe('OPERATION.SUCCESS.CONTENT.COPY');
});
tick(100);
}));
it('should be able to move content', fakeAsync(() => {
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
service.moveContent(fakeNode, 'allowed').subscribe((value) => {
expect(value).toBe('OPERATION.SUCCESS.CONTENT.MOVE');
});
tick(100);
}));
it('should be able to move folder', fakeAsync(() => {
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
service.moveFolder(fakeNode, 'allowed').subscribe((value) => {
expect(value).toBe('OPERATION.SUCCESS.FOLDER.MOVE');
});
tick(100);
}));
it('should be able to copy folder', fakeAsync(() => {
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
service.copyFolder(fakeNode, 'allowed').subscribe((value) => {
expect(value).toBe('OPERATION.SUCCESS.FOLDER.COPY');
});
tick(100);
}));
it('should be able to propagate the dialog error', fakeAsync(() => {
spyOn(documentListService, 'copyNode').and.returnValue(throwError('FAKE-KO'));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
service.copyFolder(fakeNode, '!allowed').subscribe(() => {
}, (error) => {
expect(error).toBe('FAKE-KO');
});
tick(100);
}));
});

View File

@@ -250,14 +250,20 @@ describe('AddPermissionDialog', () => {
it('should stream the confirmed selection on the confirm subject', async () => {
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
data.confirm.subscribe((selection) => {
expect(selection[0]).not.toBeNull();
expect(fakeAuthorityResults[0].entry.id).toBe(selection[0].authorityId);
});
fixture.detectChanges();
await fixture.whenStable();
let authorityResult = fixture.debugElement.query(By.css('[data-automation-id="datatable-row-0"]'));
expect(authorityResult).toBeNull();
const confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
confirmButton.click();
fixture.detectChanges();
await fixture.whenStable();
authorityResult = fixture.debugElement.query(By.css('[data-automation-id="datatable-row-0"]'));
expect(authorityResult).toBeTruthy();
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddPermissionPanelComponent } from './add-permission-panel.component';
import { By } from '@angular/platform-browser';
import { SearchService, setupTestBed } from '@alfresco/adf-core';
@@ -24,9 +24,9 @@ import { fakeAuthorityListResult, fakeNameListResult } from '../../../mock/add-p
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { DebugElement } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { MatIconTestingModule } from '@angular/material/icon/testing';
describe('AddPermissionPanelComponent', () => {
let fixture: ComponentFixture<AddPermissionPanelComponent>;
let component: AddPermissionPanelComponent;
let element: HTMLElement;
@@ -36,7 +36,8 @@ describe('AddPermissionPanelComponent', () => {
setupTestBed({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
ContentTestingModule,
MatIconTestingModule
]
});
@@ -60,6 +61,7 @@ describe('AddPermissionPanelComponent', () => {
inputDebugElement.nativeElement.value = word;
inputDebugElement.nativeElement.focus();
inputDebugElement.nativeElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
};
it('should be able to render the component', () => {
@@ -67,20 +69,20 @@ describe('AddPermissionPanelComponent', () => {
expect(element.querySelector('#searchInput')).not.toBeNull();
});
it('should show search results when user types something', fakeAsync(() => {
it('should show search results when user types something', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
expect(element.querySelector('#searchInput')).not.toBeNull();
typeWordIntoSearchInput('a');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#result_option_0')).not.toBeNull();
});
}));
it('should emit a select event with the selected items when an item is clicked', fakeAsync(() => {
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#result_option_0')).not.toBeNull();
});
it('should emit a select event with the selected items when an item is clicked', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
component.select.subscribe((items) => {
expect(items).not.toBeNull();
@@ -90,120 +92,116 @@ describe('AddPermissionPanelComponent', () => {
});
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
});
}));
it('should show the icon related on the nodeType', fakeAsync(() => {
const listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).toBeTruthy();
listElement.triggerEventHandler('click', {});
});
it('should show the icon related on the nodeType', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
expect(element.querySelector('#searchInput')).not.toBeNull();
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).toBeTruthy();
expect(element.querySelector('#result_option_0')).toBeTruthy();
expect(element.querySelector('#result_option_1')).toBeTruthy();
expect(element.querySelector('#result_option_2')).toBeTruthy();
});
it('should clear the search when user delete the search input field', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
expect(element.querySelector('#searchInput')).not.toBeNull();
typeWordIntoSearchInput('a');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#result_option_0 #add-person-icon')).toBeDefined();
expect(element.querySelector('#result_option_0 #add-person-icon')).not.toBeNull();
expect(element.querySelector('#result_option_2 #add-group-icon')).toBeDefined();
expect(element.querySelector('#result_option_2 #add-group-icon')).not.toBeNull();
});
}));
it('should clear the search when user delete the search input field', fakeAsync(() => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
expect(element.querySelector('#searchInput')).not.toBeNull();
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#result_option_0')).not.toBeNull();
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
expect(clearButton).not.toBeNull();
clearButton.triggerEventHandler('click', {});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).toBeNull();
});
});
}));
expect(element.querySelector('#result_option_0')).toBeTruthy();
it('should remove element from selection when is clicked and already selected', fakeAsync(() => {
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
expect(clearButton).toBeTruthy();
clearButton.triggerEventHandler('click', {});
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#result_option_0')).toBeNull();
});
it('should remove element from selection on click when is already selected', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
component.select.subscribe((items) => {
expect(items).not.toBeNull();
expect(items[0]).toBeUndefined();
expect(component.selectedItems.length).toBe(0);
});
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
});
}));
it('should always show as extra result the everyone group', fakeAsync(() => {
let selectedUserIcon = fixture.debugElement.query(By.css('.adf-people-select-icon'));
const listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).toBeTruthy();
expect(selectedUserIcon).toBeFalsy();
listElement.triggerEventHandler('click', {});
fixture.detectChanges();
selectedUserIcon = fixture.debugElement.query(By.css('.adf-people-select-icon'));
expect(selectedUserIcon).toBeTruthy();
listElement.triggerEventHandler('click', {});
fixture.detectChanges();
selectedUserIcon = fixture.debugElement.query(By.css('.adf-people-select-icon'));
expect(selectedUserIcon).toBeFalsy();
});
it('should always show as extra result the everyone group', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#result_option_0 #add-person-icon')).toBeDefined();
expect(element.querySelector('#result_option_0 #add-person-icon')).not.toBeNull();
expect(element.querySelector('#result_option_2 #add-group-icon')).toBeDefined();
expect(element.querySelector('#result_option_2 #add-group-icon')).not.toBeNull();
expect(element.querySelector('#adf-add-permission-group-everyone')).toBeDefined();
expect(element.querySelector('#adf-add-permission-group-everyone')).not.toBeNull();
});
}));
it('should show everyone group when search return no result', fakeAsync(() => {
expect(element.querySelector('#adf-add-permission-authority-results')).toBeTruthy();
expect(element.querySelector('#adf-add-permission-group-everyone')).toBeTruthy();
expect(element.querySelector('#result_option_0')).toBeTruthy();
expect(element.querySelector('#result_option_1')).toBeTruthy();
expect(element.querySelector('#result_option_2')).toBeTruthy();
});
it('should show everyone group when search return no result', async () => {
spyOn(searchApiService, 'search').and.returnValue(of({ list: { entries: [] } }));
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#adf-add-permission-group-everyone')).toBeDefined();
expect(element.querySelector('#adf-add-permission-group-everyone')).not.toBeNull();
});
}));
it('should show first and last name of users', fakeAsync(() => {
expect(element.querySelector('#adf-add-permission-authority-results')).not.toBeNull();
expect(element.querySelector('#adf-add-permission-group-everyone')).toBeDefined();
expect(element.querySelector('#adf-add-permission-group-everyone')).not.toBeNull();
});
it('should show first and last name of users', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeNameListResult));
component.selectedItems.push(fakeNameListResult.list.entries[0]);
component.selectedItems.push(fakeNameListResult.list.entries[1]);
typeWordIntoSearchInput('a');
await fixture.whenStable();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#result_option_0 .mat-list-text')).not.toBeNull();
expect(element.querySelector('#result_option_0 .mat-list-text')).toBeDefined();
expect(element.querySelector('#result_option_1 .mat-list-text')).not.toBeNull();
expect(element.querySelector('#result_option_1 .mat-list-text')).toBeDefined();
expect(element.querySelector('#result_option_0 .mat-list-text').innerHTML).not.toEqual(element.querySelector('#result_option_1 .mat-list-text').innerHTML);
});
}));
it('should emit unique element in between multiple search', fakeAsync(() => {
expect(element.querySelector('#result_option_0 .mat-list-text')).toBeTruthy();
expect(element.querySelector('#result_option_1 .mat-list-text')).toBeTruthy();
expect(element.querySelector('#result_option_0 .mat-list-text').innerHTML).not.toEqual(element.querySelector('#result_option_1 .mat-list-text').innerHTML);
});
it('should emit unique element in between multiple search', async () => {
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
let searchAttempt = 0;
@@ -216,26 +214,27 @@ describe('AddPermissionPanelComponent', () => {
});
typeWordIntoSearchInput('a');
fixture.whenStable().then(() => {
fixture.detectChanges();
let listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
await fixture.whenStable();
fixture.detectChanges();
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
expect(clearButton).not.toBeNull();
clearButton.triggerEventHandler('click', {});
fixture.detectChanges();
let listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
fixture.detectChanges();
typeWordIntoSearchInput('abc');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
listElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
expect(searchAttempt).toBe(2);
});
});
}));
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
expect(clearButton).not.toBeNull();
clearButton.triggerEventHandler('click', {});
fixture.detectChanges();
typeWordIntoSearchInput('abc');
await fixture.whenStable();
fixture.detectChanges();
listElement = fixture.debugElement.query(By.css('#result_option_0'));
expect(listElement).not.toBeNull();
listElement.triggerEventHandler('click', {});
expect(searchAttempt).toBe(2);
});
});

View File

@@ -132,7 +132,7 @@ describe('SearchControlComponent', () => {
});
});
it('should still fire an event when user inputs a search term less than 3 characters', (done) => {
it('should still fire an event when user inputs a search term less than 3 characters', async () => {
searchServiceSpy.and.returnValue(of(JSON.parse(JSON.stringify(results))));
const searchDisposable = component.searchChange.subscribe((value) => {
@@ -140,11 +140,9 @@ describe('SearchControlComponent', () => {
searchDisposable.unsubscribe();
});
typeWordIntoSearchInput('cu');
fixture.detectChanges();
fixture.whenStable().then(() => {
typeWordIntoSearchInput('cu');
done();
});
await fixture.whenStable();
});
});

View File

@@ -22,25 +22,27 @@ import { ContentTestingModule } from '../../../../testing/content.testing.module
import { setupTestBed } from '@alfresco/adf-core';
describe('SearchFilterMenuComponent', () => {
let component: SearchFilterMenuCardComponent;
let fixture: ComponentFixture<SearchFilterMenuCardComponent>;
let component: SearchFilterMenuCardComponent;
let fixture: ComponentFixture<SearchFilterMenuCardComponent>;
setupTestBed({
setupTestBed({
imports: [
TranslateModule.forRoot(),
ContentTestingModule
]
});
beforeEach(() => {
fixture = TestBed.createComponent(SearchFilterMenuCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(SearchFilterMenuCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should emit on close click', (done) => {
component.close.subscribe(() => done());
const closButton = fixture.debugElement.nativeElement.querySelector('.adf-search-filter-title-action');
closButton.click();
});
it('should emit on close click', () => {
const spyCloseEvent = spyOn(component.close, 'emit');
const closeButton = fixture.debugElement.nativeElement.querySelector('.adf-search-filter-title-action');
closeButton.click();
expect(spyCloseEvent).toHaveBeenCalled();
});
});

View File

@@ -669,7 +669,7 @@ describe('SearchQueryBuilder', () => {
expect(compiled.highlight.mergeContiguous).toBe(true);
});
it('should emit error event', (done) => {
it('should emit error event', () => {
const config: SearchConfiguration = {
categories: [
{ id: 'cat1', enabled: true } as any
@@ -680,8 +680,8 @@ describe('SearchQueryBuilder', () => {
const builder = new SearchQueryBuilderService(buildConfig(config), alfrescoApiService);
spyOn(builder, 'buildQuery').and.throwError('some error');
builder.error.subscribe(() => {
done();
builder.error.subscribe((error) => {
expect(error).toEqual(new Error('some error'));
});
builder.execute();

View File

@@ -17,11 +17,12 @@
import { Component, NgZone } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { TranslationService, UploadService, setupTestBed, FileModel } from '@alfresco/adf-core';
import { TranslationService, UploadService, setupTestBed, FileModel, FileUploadErrorEvent } from '@alfresco/adf-core';
import { UploadBase } from './upload-base';
import { UploadFilesEvent } from '../upload-files.event';
import { ContentTestingModule } from '../../../testing/content.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { mockUploadSuccessPromise } from '../../../mock/upload.service.mock';
@Component({
selector: 'adf-upload-button-test',
@@ -36,6 +37,8 @@ export class UploadTestComponent extends UploadBase {
}
}
const file = { name: 'bigFile.png', size: 1000 } as File;
describe('UploadBase', () => {
let component: UploadTestComponent;
@@ -67,12 +70,16 @@ describe('UploadBase', () => {
describe('beginUpload', () => {
it('should raise event', (done) => {
it('should raise event', () => {
spyOn(uploadService, 'addToQueue').and.stub();
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
component.beginUpload.subscribe(() => done());
const file = { name: 'bigFile.png', size: 1000 } as File;
component.beginUpload.subscribe(
(uploadFilesEvent: UploadFilesEvent) => {
expect(uploadFilesEvent.files[0].file).toEqual(file);
}
);
component.uploadFiles([file]);
fixture.detectChanges();
});
@@ -86,7 +93,7 @@ describe('UploadBase', () => {
event.preventDefault();
prevented = true;
});
const file = { name: 'bigFile.png', size: 1000 } as File;
component.uploadFiles([file]);
tick();
@@ -106,7 +113,7 @@ describe('UploadBase', () => {
event.preventDefault();
prevented = true;
});
const file = { name: 'bigFile.png', size: 1000 } as File;
component.uploadFiles([file]);
tick();
@@ -123,25 +130,24 @@ describe('UploadBase', () => {
expect(uploadFilesInTheQueue).toHaveBeenCalled();
}));
it('should emit callback events on resume', fakeAsync((done) => {
spyOn(uploadService, 'addToQueue').and.stub();
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
it('should emit callback events on resume', () => {
spyOn(uploadService, 'addToQueue').and.callThrough();
spyOn(uploadService, 'uploadFilesInTheQueue').and.callThrough();
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadSuccessPromise);
let uploadEvent: UploadFilesEvent;
component.beginUpload.subscribe((event) => {
uploadEvent = event;
event.preventDefault();
});
const file = { name: 'bigFile.png', size: 1000 } as File;
component.success.subscribe((success) => {
expect(success).toBeTruthy();
});
component.uploadFiles([file]);
tick();
uploadEvent.resumeUpload();
component.success.subscribe(() => {
done();
});
}));
});
});
describe('fileSize', () => {
@@ -194,11 +200,11 @@ describe('UploadBase', () => {
expect(addToQueueSpy.calls.mostRecent()).toBeUndefined();
});
it('should output an error when you try to upload a file too big', (done) => {
it('should output an error when you try to upload a file too big', () => {
component.maxFilesSize = 100;
component.error.subscribe(() => {
done();
component.error.subscribe((error: FileUploadErrorEvent) => {
expect(error).toBe('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE');
});
component.uploadFiles(files);

View File

@@ -85,6 +85,18 @@ const getFakeFileShareRow = (allowableOperations = ['delete', 'update', 'create'
}
});
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
describe('UploadDragAreaComponent', () => {
let component: UploadDragAreaComponent;
@@ -103,7 +115,6 @@ describe('UploadDragAreaComponent', () => {
uploadService = TestBed.inject(UploadService);
component = fixture.componentInstance;
fixture.detectChanges();
uploadService.clearCache();
});
@@ -141,7 +152,7 @@ describe('UploadDragAreaComponent', () => {
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
});
it('should NOT upload the folder dropped', (done) => {
it('should NOT upload the folder dropped', () => {
component.disabled = true;
spyOn(uploadService, 'addToQueue');
spyOn(uploadService, 'uploadFilesInTheQueue');
@@ -156,12 +167,10 @@ describe('UploadDragAreaComponent', () => {
})
};
component.onFolderEntityDropped(itemEntity);
fixture.detectChanges();
setTimeout(() => {
expect(uploadService.addToQueue).not.toHaveBeenCalled();
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
done();
}, 0);
expect(uploadService.addToQueue).not.toHaveBeenCalled();
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
});
it('should NOT upload the files', () => {
@@ -169,17 +178,6 @@ describe('UploadDragAreaComponent', () => {
spyOn(uploadService, 'addToQueue');
spyOn(uploadService, 'uploadFilesInTheQueue');
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
fixture.detectChanges();
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
@@ -251,17 +249,6 @@ describe('UploadDragAreaComponent', () => {
});
it('should NOT upload the file if it is dropped on another file', () => {
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
name: 'file-fake.png',
relativeFolder: '/',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
@@ -306,17 +293,6 @@ describe('UploadDragAreaComponent', () => {
});
it('should upload a file when user has create permission on target folder', () => {
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
name: 'file-fake.png',
relativeFolder: '/',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
@@ -329,37 +305,38 @@ describe('UploadDragAreaComponent', () => {
expect(uploadService.addToQueue).toHaveBeenCalled();
});
it('should upload a file to a specific target folder when dropped onto one', (done) => {
const fakeItem = {
it('should upload a file to a specific target folder when dropped onto one', () => {
const fakePippoItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
name: 'file-fake.png',
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
expect(fileList.options.path).toBe('pippo/');
done();
});
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
files: [fakePippoItem]
}
});
addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
expect(fileList.options.path).toBe('pippo/');
});
component.onUploadFiles(fakeCustomEvent);
fixture.detectChanges();
});
it('should upload a folder to a specific target folder when dropped onto one', (done) => {
const fakeItem = {
it('should upload a folder to a specific target folder when dropped onto one', () => {
const fakeSuperItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
@@ -371,35 +348,25 @@ describe('UploadDragAreaComponent', () => {
}
};
addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
expect(fileList.options.path).toBe('pippo/super');
done();
});
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
files: [fakeItem]
files: [fakeSuperItem]
}
});
addToQueueSpy.and.callFake((fileList) => {
expect(fileList.name).toBe('file');
expect(fileList.options.path).toBe('pippo/super');
});
component.onUploadFiles(fakeCustomEvent);
fixture.detectChanges();
});
it('should trigger updating the file version when we drop a file over another file', async () => {
spyOn(component.updateFileVersion, 'emit');
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
name: 'file-fake.png',
relativeFolder: '/',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
@@ -421,24 +388,6 @@ describe('UploadDragAreaComponent', () => {
it('should raise an error if upload a file goes wrong', async () => {
spyOn(uploadService, 'getUploadPromise').and.callThrough();
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
fixture.detectChanges();
await component.error.subscribe((error) => {
expect(error).not.toBeNull();
});
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
detail: {
data: getFakeShareDataRow(),
@@ -446,22 +395,17 @@ describe('UploadDragAreaComponent', () => {
}
});
component.error.subscribe((error) => {
expect(error).not.toBeNull();
});
component.onUploadFiles(fakeCustomEvent);
fixture.detectChanges();
await fixture.whenStable();
});
it('should emit success if successful of upload a file', async () => {
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadSuccessPromise);
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
fixture.detectChanges();
@@ -481,17 +425,6 @@ describe('UploadDragAreaComponent', () => {
it('should emit error if upload errored', async () => {
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadErrorPromise);
const fakeItem = {
fullPath: '/folder-fake/file-fake.png',
isDirectory: false,
isFile: true,
relativeFolder: '/',
name: 'file-fake.png',
file: (callbackFile) => {
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
callbackFile(fileFake);
}
};
fixture.detectChanges();

View File

@@ -16,7 +16,7 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { VersionUploadComponent } from './version-upload.component';
import { ContentService, setupTestBed, UploadService } from '@alfresco/adf-core';
@@ -62,32 +62,35 @@ describe('VersionUploadComponent', () => {
contentService = TestBed.inject(ContentService);
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
component.node = node;
fixture.detectChanges();
});
it('should disabled upload button on upload starts', fakeAsync(() => {
afterEach(() => {
fixture.destroy();
});
it('should disabled upload button on upload starts', () => {
component.uploadStarted.subscribe(() => {
expect(component.disabled).toEqual(true);
});
uploadService.fileUploadStarting.next();
tick(500);
fixture.detectChanges();
}));
it('should enable upload button on error', (done) => {
uploadService.fileUploadStarting.next();
});
it('should enable upload button on error', () => {
spyOn(component, 'canUpload').and.returnValue(true);
component.error.subscribe(() => {
expect(component.disabled).toEqual(false);
done();
});
component.onError({} as any);
fixture.detectChanges();
});
it('should enable upload button on success', (done) => {
it('should enable upload button on success', () => {
spyOn(component, 'canUpload').and.returnValue(true);
component.success.subscribe(() => {
expect(component.disabled).toEqual(false);
done();
});
component.onSuccess(true);
fixture.detectChanges();