mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -26,6 +26,19 @@ import { ContentTypePropertiesService } from './content-type-property.service';
|
|||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { PropertyDescriptorsService } from './property-descriptors.service';
|
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', () => {
|
describe('ContentMetaDataService', () => {
|
||||||
|
|
||||||
let service: ContentMetadataService;
|
let service: ContentMetadataService;
|
||||||
@@ -74,15 +87,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return all the properties of the node', () => {
|
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(
|
service.getBasicProperties(fakeNode).subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res.length).toEqual(10);
|
expect(res.length).toEqual(10);
|
||||||
@@ -94,16 +98,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the content type property', () => {
|
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));
|
spyOn(contentPropertyService, 'getContentTypeCardItem').and.returnValue(of({ label: 'hello i am a weird content type'} as any));
|
||||||
|
|
||||||
service.getContentTypeProperty(fakeNode).subscribe(
|
service.getContentTypeProperty(fakeNode).subscribe(
|
||||||
@@ -116,9 +110,9 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should trigger the opening of the content type dialog', () => {
|
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');
|
expect(contentPropertyService.openContentTypeDialogConfirm).toHaveBeenCalledWith('fn:fakenode');
|
||||||
}
|
}
|
||||||
@@ -128,7 +122,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
describe('AspectOriented preset', () => {
|
describe('AspectOriented preset', () => {
|
||||||
|
|
||||||
it('should return response with exif property', (done) => {
|
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': '*' });
|
setConfig('default', { 'exif:exif': '*' });
|
||||||
|
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
|
||||||
@@ -146,7 +139,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should filter the record options for node ', (done) => {
|
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': '*' });
|
setConfig('default', { 'exif:exif': '*', 'rma:record': '*' });
|
||||||
|
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(exifResponse));
|
||||||
@@ -167,8 +159,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
describe('LayoutOriented preset', () => {
|
describe('LayoutOriented preset', () => {
|
||||||
|
|
||||||
it('should return the node property', (done) => {
|
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 = [
|
const customLayoutOrientedScheme = [
|
||||||
{
|
{
|
||||||
id: 'app.content.metadata.customGroup2',
|
id: 'app.content.metadata.customGroup2',
|
||||||
@@ -186,7 +176,7 @@ describe('ContentMetaDataService', () => {
|
|||||||
setConfig('custom', customLayoutOrientedScheme);
|
setConfig('custom', customLayoutOrientedScheme);
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
||||||
|
|
||||||
service.getGroupedProperties(fakeNode, 'custom').subscribe(
|
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res.length).toEqual(1);
|
expect(res.length).toEqual(1);
|
||||||
expect(res[0].title).toEqual('Properties');
|
expect(res[0].title).toEqual('Properties');
|
||||||
@@ -199,8 +189,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should filter the exif property', (done) => {
|
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 = [
|
const customLayoutOrientedScheme = [
|
||||||
{
|
{
|
||||||
id: 'app.content.metadata.customGroup',
|
id: 'app.content.metadata.customGroup',
|
||||||
@@ -229,7 +217,7 @@ describe('ContentMetaDataService', () => {
|
|||||||
setConfig('custom', customLayoutOrientedScheme);
|
setConfig('custom', customLayoutOrientedScheme);
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
||||||
|
|
||||||
service.getGroupedProperties(fakeNode, 'custom').subscribe(
|
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res.length).toEqual(1);
|
expect(res.length).toEqual(1);
|
||||||
expect(res[0].title).toEqual('Properties');
|
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) => {
|
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 = [
|
const customLayoutOrientedScheme = [
|
||||||
{
|
{
|
||||||
id: 'app.content.metadata.customGroup',
|
id: 'app.content.metadata.customGroup',
|
||||||
@@ -263,7 +249,7 @@ describe('ContentMetaDataService', () => {
|
|||||||
setConfig('custom', customLayoutOrientedScheme);
|
setConfig('custom', customLayoutOrientedScheme);
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
||||||
|
|
||||||
service.getGroupedProperties(fakeNode, 'custom').subscribe(
|
service.getGroupedProperties(fakeContentNode, 'custom').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res.length).toEqual(0);
|
expect(res.length).toEqual(0);
|
||||||
done();
|
done();
|
||||||
@@ -277,8 +263,6 @@ describe('ContentMetaDataService', () => {
|
|||||||
|
|
||||||
describe('Provided preset config', () => {
|
describe('Provided preset config', () => {
|
||||||
it('should create the metadata config on the fly when preset config is provided', (done) => {
|
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 = [
|
const customLayoutOrientedScheme = [
|
||||||
{
|
{
|
||||||
id: 'app.content.metadata.customGroup',
|
id: 'app.content.metadata.customGroup',
|
||||||
@@ -306,7 +290,7 @@ describe('ContentMetaDataService', () => {
|
|||||||
|
|
||||||
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
|
||||||
|
|
||||||
service.getGroupedProperties(fakeNode, customLayoutOrientedScheme).subscribe(
|
service.getGroupedProperties(fakeContentNode, customLayoutOrientedScheme).subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res.length).toEqual(1);
|
expect(res.length).toEqual(1);
|
||||||
expect(res[0].title).toEqual('Properties');
|
expect(res[0].title).toEqual('Properties');
|
||||||
|
@@ -468,32 +468,6 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
|||||||
component.isSelectionValid = returnHasPermission;
|
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 () => {
|
it('should NOT be null after clicking on a node (with the right permissions) in the list (onNodeSelect)', async () => {
|
||||||
hasAllowableOperations = true;
|
hasAllowableOperations = true;
|
||||||
|
|
||||||
|
@@ -177,43 +177,19 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Cancel button', () => {
|
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', () => {
|
it('should not be shown if dialogRef is NOT injected', () => {
|
||||||
const closeButton = fixture.debugElement.query(By.css('[content-node-selector-actions-cancel]'));
|
const closeButton = fixture.debugElement.query(By.css('[content-node-selector-actions-cancel]'));
|
||||||
expect(closeButton).toBeNull();
|
expect(closeButton).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close the dialog', () => {
|
it('should close the dialog', () => {
|
||||||
let cancelButton;
|
let cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]'));
|
||||||
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', {});
|
cancelButton.triggerEventHandler('click', {});
|
||||||
expect(dialog.close).toHaveBeenCalled();
|
expect(dialog.close).toHaveBeenCalled();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
cancelButton = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-actions-cancel"]'));
|
||||||
|
expect(cancelButton).not.toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -46,11 +46,10 @@ describe('NodeCounterDirective', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the counter component', () => {
|
it('should display the counter component', async () => {
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
const counterElement = fixture.debugElement.query(By.css('adf-node-counter'));
|
const counterElement = fixture.debugElement.query(By.css('adf-node-counter'));
|
||||||
expect(counterElement).not.toBeNull();
|
expect(counterElement).not.toBeNull();
|
||||||
expect(counterElement.nativeElement.innerText).toBe('NODE_COUNTER.SELECTED_COUNT');
|
expect(counterElement.nativeElement.innerText).toBe('NODE_COUNTER.SELECTED_COUNT');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { setupTestBed } from '@alfresco/adf-core';
|
import { setupTestBed } from '@alfresco/adf-core';
|
||||||
import { DocumentListService } from './document-list.service';
|
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 { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ describe('DocumentListService', () => {
|
|||||||
jasmine.Ajax.uninstall();
|
jasmine.Ajax.uninstall();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the folder info', () => {
|
it('should return the folder info', fakeAsync(() => {
|
||||||
service.getFolder('/fake-root/fake-name').subscribe(
|
service.getFolder('/fake-root/fake-name').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
@@ -94,7 +94,7 @@ describe('DocumentListService', () => {
|
|||||||
contentType: 'json',
|
contentType: 'json',
|
||||||
responseText: fakeFolder
|
responseText: fakeFolder
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should add the includeTypes in the request Node Children if required', () => {
|
it('should add the includeTypes in the request Node Children if required', () => {
|
||||||
const spyGetNodeInfo = spyOn(service['nodes'], 'listNodeChildren').and.callThrough();
|
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(
|
service.deleteNode('fake-id').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
expect(res).toBe('');
|
expect(res).toBe('');
|
||||||
@@ -154,7 +154,7 @@ describe('DocumentListService', () => {
|
|||||||
status: 204,
|
status: 204,
|
||||||
contentType: 'json'
|
contentType: 'json'
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('should copy a node', (done) => {
|
it('should copy a node', (done) => {
|
||||||
service.copyNode('node-id', 'parent-id').subscribe(() => done());
|
service.copyNode('node-id', 'parent-id').subscribe(() => done());
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* 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 { Node, NodeEntry } from '@alfresco/js-api';
|
||||||
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
|
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
|
||||||
import { DocumentListService } from './document-list.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
@@ -25,6 +25,7 @@ import { of, throwError } from 'rxjs';
|
|||||||
import { MatDialogRef } from '@angular/material/dialog';
|
import { MatDialogRef } from '@angular/material/dialog';
|
||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { delay } from 'rxjs/operators';
|
||||||
|
|
||||||
const fakeNode: Node = {
|
const fakeNode: Node = {
|
||||||
id: 'fake'
|
id: 'fake'
|
||||||
@@ -56,51 +57,58 @@ describe('NodeActionsService', () => {
|
|||||||
service = TestBed.inject(NodeActionsService);
|
service = TestBed.inject(NodeActionsService);
|
||||||
documentListService = TestBed.inject(DocumentListService);
|
documentListService = TestBed.inject(DocumentListService);
|
||||||
contentDialogService = TestBed.inject(ContentNodeDialogService);
|
contentDialogService = TestBed.inject(ContentNodeDialogService);
|
||||||
|
|
||||||
|
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]).pipe(delay(100)));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to copy content', fakeAsync(() => {
|
it('should be able to copy content', fakeAsync(() => {
|
||||||
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
||||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
|
||||||
|
|
||||||
service.copyContent(fakeNode, 'allowed').subscribe((value) => {
|
service.copyContent(fakeNode, 'allowed').subscribe((value) => {
|
||||||
expect(value).toBe('OPERATION.SUCCESS.CONTENT.COPY');
|
expect(value).toBe('OPERATION.SUCCESS.CONTENT.COPY');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick(100);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to move content', fakeAsync(() => {
|
it('should be able to move content', fakeAsync(() => {
|
||||||
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
||||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
|
||||||
|
|
||||||
service.moveContent(fakeNode, 'allowed').subscribe((value) => {
|
service.moveContent(fakeNode, 'allowed').subscribe((value) => {
|
||||||
expect(value).toBe('OPERATION.SUCCESS.CONTENT.MOVE');
|
expect(value).toBe('OPERATION.SUCCESS.CONTENT.MOVE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick(100);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to move folder', fakeAsync(() => {
|
it('should be able to move folder', fakeAsync(() => {
|
||||||
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
||||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
|
||||||
|
|
||||||
service.moveFolder(fakeNode, 'allowed').subscribe((value) => {
|
service.moveFolder(fakeNode, 'allowed').subscribe((value) => {
|
||||||
expect(value).toBe('OPERATION.SUCCESS.FOLDER.MOVE');
|
expect(value).toBe('OPERATION.SUCCESS.FOLDER.MOVE');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick(100);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to copy folder', fakeAsync(() => {
|
it('should be able to copy folder', fakeAsync(() => {
|
||||||
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
||||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
|
||||||
|
|
||||||
service.copyFolder(fakeNode, 'allowed').subscribe((value) => {
|
service.copyFolder(fakeNode, 'allowed').subscribe((value) => {
|
||||||
expect(value).toBe('OPERATION.SUCCESS.FOLDER.COPY');
|
expect(value).toBe('OPERATION.SUCCESS.FOLDER.COPY');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick(100);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should be able to propagate the dialog error', fakeAsync(() => {
|
it('should be able to propagate the dialog error', fakeAsync(() => {
|
||||||
spyOn(documentListService, 'copyNode').and.returnValue(throwError('FAKE-KO'));
|
spyOn(documentListService, 'copyNode').and.returnValue(throwError('FAKE-KO'));
|
||||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
|
||||||
|
|
||||||
service.copyFolder(fakeNode, '!allowed').subscribe(() => {
|
service.copyFolder(fakeNode, '!allowed').subscribe(() => {
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
expect(error).toBe('FAKE-KO');
|
expect(error).toBe('FAKE-KO');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tick(100);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@@ -250,14 +250,20 @@ describe('AddPermissionDialog', () => {
|
|||||||
it('should stream the confirmed selection on the confirm subject', async () => {
|
it('should stream the confirmed selection on the confirm subject', async () => {
|
||||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||||
data.confirm.subscribe((selection) => {
|
|
||||||
expect(selection[0]).not.toBeNull();
|
|
||||||
expect(fakeAuthorityResults[0].entry.id).toBe(selection[0].authorityId);
|
|
||||||
});
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
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"]');
|
const confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||||
confirmButton.click();
|
confirmButton.click();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
authorityResult = fixture.debugElement.query(By.css('[data-automation-id="datatable-row-0"]'));
|
||||||
|
expect(authorityResult).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* 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 { AddPermissionPanelComponent } from './add-permission-panel.component';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { SearchService, setupTestBed } from '@alfresco/adf-core';
|
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 { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement } from '@angular/core';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { MatIconTestingModule } from '@angular/material/icon/testing';
|
||||||
|
|
||||||
describe('AddPermissionPanelComponent', () => {
|
describe('AddPermissionPanelComponent', () => {
|
||||||
|
|
||||||
let fixture: ComponentFixture<AddPermissionPanelComponent>;
|
let fixture: ComponentFixture<AddPermissionPanelComponent>;
|
||||||
let component: AddPermissionPanelComponent;
|
let component: AddPermissionPanelComponent;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
@@ -36,7 +36,8 @@ describe('AddPermissionPanelComponent', () => {
|
|||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
ContentTestingModule
|
ContentTestingModule,
|
||||||
|
MatIconTestingModule
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -60,6 +61,7 @@ describe('AddPermissionPanelComponent', () => {
|
|||||||
inputDebugElement.nativeElement.value = word;
|
inputDebugElement.nativeElement.value = word;
|
||||||
inputDebugElement.nativeElement.focus();
|
inputDebugElement.nativeElement.focus();
|
||||||
inputDebugElement.nativeElement.dispatchEvent(new Event('input'));
|
inputDebugElement.nativeElement.dispatchEvent(new Event('input'));
|
||||||
|
fixture.detectChanges();
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should be able to render the component', () => {
|
it('should be able to render the component', () => {
|
||||||
@@ -67,20 +69,20 @@ describe('AddPermissionPanelComponent', () => {
|
|||||||
expect(element.querySelector('#searchInput')).not.toBeNull();
|
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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||||
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
||||||
expect(element.querySelector('#searchInput')).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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||||
component.select.subscribe((items) => {
|
component.select.subscribe((items) => {
|
||||||
expect(items).not.toBeNull();
|
expect(items).not.toBeNull();
|
||||||
@@ -90,120 +92,116 @@ describe('AddPermissionPanelComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
typeWordIntoSearchInput('a');
|
typeWordIntoSearchInput('a');
|
||||||
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||||
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
||||||
expect(element.querySelector('#searchInput')).not.toBeNull();
|
expect(element.querySelector('#searchInput')).not.toBeNull();
|
||||||
typeWordIntoSearchInput('a');
|
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(() => {
|
await fixture.whenStable();
|
||||||
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.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
expect(element.querySelector('#result_option_0')).toBeTruthy();
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
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));
|
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');
|
typeWordIntoSearchInput('a');
|
||||||
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||||
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
||||||
|
|
||||||
typeWordIntoSearchInput('a');
|
typeWordIntoSearchInput('a');
|
||||||
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
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: [] } }));
|
spyOn(searchApiService, 'search').and.returnValue(of({ list: { entries: [] } }));
|
||||||
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
||||||
|
|
||||||
typeWordIntoSearchInput('a');
|
typeWordIntoSearchInput('a');
|
||||||
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeNameListResult));
|
||||||
component.selectedItems.push(fakeNameListResult.list.entries[0]);
|
component.selectedItems.push(fakeNameListResult.list.entries[0]);
|
||||||
component.selectedItems.push(fakeNameListResult.list.entries[1]);
|
component.selectedItems.push(fakeNameListResult.list.entries[1]);
|
||||||
|
|
||||||
typeWordIntoSearchInput('a');
|
typeWordIntoSearchInput('a');
|
||||||
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
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));
|
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||||
let searchAttempt = 0;
|
let searchAttempt = 0;
|
||||||
|
|
||||||
@@ -216,26 +214,27 @@ describe('AddPermissionPanelComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
typeWordIntoSearchInput('a');
|
typeWordIntoSearchInput('a');
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
|
|
||||||
expect(listElement).not.toBeNull();
|
|
||||||
listElement.triggerEventHandler('click', {});
|
|
||||||
|
|
||||||
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
|
let listElement: DebugElement = fixture.debugElement.query(By.css('#result_option_0'));
|
||||||
expect(clearButton).not.toBeNull();
|
expect(listElement).not.toBeNull();
|
||||||
clearButton.triggerEventHandler('click', {});
|
listElement.triggerEventHandler('click', {});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
typeWordIntoSearchInput('abc');
|
const clearButton = fixture.debugElement.query(By.css('#adf-permission-clear-input'));
|
||||||
fixture.detectChanges();
|
expect(clearButton).not.toBeNull();
|
||||||
fixture.whenStable().then(() => {
|
clearButton.triggerEventHandler('click', {});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
listElement = fixture.debugElement.query(By.css('#result_option_0'));
|
|
||||||
expect(listElement).not.toBeNull();
|
typeWordIntoSearchInput('abc');
|
||||||
listElement.triggerEventHandler('click', {});
|
await fixture.whenStable();
|
||||||
expect(searchAttempt).toBe(2);
|
fixture.detectChanges();
|
||||||
});
|
|
||||||
});
|
listElement = fixture.debugElement.query(By.css('#result_option_0'));
|
||||||
}));
|
expect(listElement).not.toBeNull();
|
||||||
|
|
||||||
|
listElement.triggerEventHandler('click', {});
|
||||||
|
expect(searchAttempt).toBe(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -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))));
|
searchServiceSpy.and.returnValue(of(JSON.parse(JSON.stringify(results))));
|
||||||
|
|
||||||
const searchDisposable = component.searchChange.subscribe((value) => {
|
const searchDisposable = component.searchChange.subscribe((value) => {
|
||||||
@@ -140,11 +140,9 @@ describe('SearchControlComponent', () => {
|
|||||||
searchDisposable.unsubscribe();
|
searchDisposable.unsubscribe();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
typeWordIntoSearchInput('cu');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
fixture.whenStable().then(() => {
|
await fixture.whenStable();
|
||||||
typeWordIntoSearchInput('cu');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -22,25 +22,27 @@ import { ContentTestingModule } from '../../../../testing/content.testing.module
|
|||||||
import { setupTestBed } from '@alfresco/adf-core';
|
import { setupTestBed } from '@alfresco/adf-core';
|
||||||
|
|
||||||
describe('SearchFilterMenuComponent', () => {
|
describe('SearchFilterMenuComponent', () => {
|
||||||
let component: SearchFilterMenuCardComponent;
|
let component: SearchFilterMenuCardComponent;
|
||||||
let fixture: ComponentFixture<SearchFilterMenuCardComponent>;
|
let fixture: ComponentFixture<SearchFilterMenuCardComponent>;
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
imports: [
|
imports: [
|
||||||
TranslateModule.forRoot(),
|
TranslateModule.forRoot(),
|
||||||
ContentTestingModule
|
ContentTestingModule
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(SearchFilterMenuCardComponent);
|
fixture = TestBed.createComponent(SearchFilterMenuCardComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit on close click', (done) => {
|
it('should emit on close click', () => {
|
||||||
component.close.subscribe(() => done());
|
const spyCloseEvent = spyOn(component.close, 'emit');
|
||||||
const closButton = fixture.debugElement.nativeElement.querySelector('.adf-search-filter-title-action');
|
const closeButton = fixture.debugElement.nativeElement.querySelector('.adf-search-filter-title-action');
|
||||||
closButton.click();
|
|
||||||
});
|
closeButton.click();
|
||||||
|
expect(spyCloseEvent).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -669,7 +669,7 @@ describe('SearchQueryBuilder', () => {
|
|||||||
expect(compiled.highlight.mergeContiguous).toBe(true);
|
expect(compiled.highlight.mergeContiguous).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error event', (done) => {
|
it('should emit error event', () => {
|
||||||
const config: SearchConfiguration = {
|
const config: SearchConfiguration = {
|
||||||
categories: [
|
categories: [
|
||||||
{ id: 'cat1', enabled: true } as any
|
{ id: 'cat1', enabled: true } as any
|
||||||
@@ -680,8 +680,8 @@ describe('SearchQueryBuilder', () => {
|
|||||||
const builder = new SearchQueryBuilderService(buildConfig(config), alfrescoApiService);
|
const builder = new SearchQueryBuilderService(buildConfig(config), alfrescoApiService);
|
||||||
spyOn(builder, 'buildQuery').and.throwError('some error');
|
spyOn(builder, 'buildQuery').and.throwError('some error');
|
||||||
|
|
||||||
builder.error.subscribe(() => {
|
builder.error.subscribe((error) => {
|
||||||
done();
|
expect(error).toEqual(new Error('some error'));
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.execute();
|
builder.execute();
|
||||||
|
@@ -17,11 +17,12 @@
|
|||||||
|
|
||||||
import { Component, NgZone } from '@angular/core';
|
import { Component, NgZone } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
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 { UploadBase } from './upload-base';
|
||||||
import { UploadFilesEvent } from '../upload-files.event';
|
import { UploadFilesEvent } from '../upload-files.event';
|
||||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { mockUploadSuccessPromise } from '../../../mock/upload.service.mock';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-upload-button-test',
|
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', () => {
|
describe('UploadBase', () => {
|
||||||
|
|
||||||
let component: UploadTestComponent;
|
let component: UploadTestComponent;
|
||||||
@@ -67,12 +70,16 @@ describe('UploadBase', () => {
|
|||||||
|
|
||||||
describe('beginUpload', () => {
|
describe('beginUpload', () => {
|
||||||
|
|
||||||
it('should raise event', (done) => {
|
it('should raise event', () => {
|
||||||
spyOn(uploadService, 'addToQueue').and.stub();
|
spyOn(uploadService, 'addToQueue').and.stub();
|
||||||
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
||||||
|
|
||||||
component.beginUpload.subscribe(() => done());
|
component.beginUpload.subscribe(
|
||||||
const file = { name: 'bigFile.png', size: 1000 } as File;
|
(uploadFilesEvent: UploadFilesEvent) => {
|
||||||
|
expect(uploadFilesEvent.files[0].file).toEqual(file);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
component.uploadFiles([file]);
|
component.uploadFiles([file]);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
@@ -86,7 +93,7 @@ describe('UploadBase', () => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
prevented = true;
|
prevented = true;
|
||||||
});
|
});
|
||||||
const file = { name: 'bigFile.png', size: 1000 } as File;
|
|
||||||
component.uploadFiles([file]);
|
component.uploadFiles([file]);
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
@@ -106,7 +113,7 @@ describe('UploadBase', () => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
prevented = true;
|
prevented = true;
|
||||||
});
|
});
|
||||||
const file = { name: 'bigFile.png', size: 1000 } as File;
|
|
||||||
component.uploadFiles([file]);
|
component.uploadFiles([file]);
|
||||||
|
|
||||||
tick();
|
tick();
|
||||||
@@ -123,25 +130,24 @@ describe('UploadBase', () => {
|
|||||||
expect(uploadFilesInTheQueue).toHaveBeenCalled();
|
expect(uploadFilesInTheQueue).toHaveBeenCalled();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should emit callback events on resume', fakeAsync((done) => {
|
it('should emit callback events on resume', () => {
|
||||||
spyOn(uploadService, 'addToQueue').and.stub();
|
spyOn(uploadService, 'addToQueue').and.callThrough();
|
||||||
spyOn(uploadService, 'uploadFilesInTheQueue').and.stub();
|
spyOn(uploadService, 'uploadFilesInTheQueue').and.callThrough();
|
||||||
|
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadSuccessPromise);
|
||||||
|
|
||||||
let uploadEvent: UploadFilesEvent;
|
let uploadEvent: UploadFilesEvent;
|
||||||
|
|
||||||
component.beginUpload.subscribe((event) => {
|
component.beginUpload.subscribe((event) => {
|
||||||
uploadEvent = event;
|
uploadEvent = event;
|
||||||
event.preventDefault();
|
|
||||||
});
|
});
|
||||||
const file = { name: 'bigFile.png', size: 1000 } as File;
|
|
||||||
|
component.success.subscribe((success) => {
|
||||||
|
expect(success).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
component.uploadFiles([file]);
|
component.uploadFiles([file]);
|
||||||
|
|
||||||
tick();
|
|
||||||
uploadEvent.resumeUpload();
|
uploadEvent.resumeUpload();
|
||||||
|
});
|
||||||
component.success.subscribe(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fileSize', () => {
|
describe('fileSize', () => {
|
||||||
@@ -194,11 +200,11 @@ describe('UploadBase', () => {
|
|||||||
expect(addToQueueSpy.calls.mostRecent()).toBeUndefined();
|
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.maxFilesSize = 100;
|
||||||
|
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe((error: FileUploadErrorEvent) => {
|
||||||
done();
|
expect(error).toBe('FILE_UPLOAD.MESSAGES.EXCEED_MAX_FILE_SIZE');
|
||||||
});
|
});
|
||||||
|
|
||||||
component.uploadFiles(files);
|
component.uploadFiles(files);
|
||||||
|
@@ -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', () => {
|
describe('UploadDragAreaComponent', () => {
|
||||||
|
|
||||||
let component: UploadDragAreaComponent;
|
let component: UploadDragAreaComponent;
|
||||||
@@ -103,7 +115,6 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
uploadService = TestBed.inject(UploadService);
|
uploadService = TestBed.inject(UploadService);
|
||||||
|
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
uploadService.clearCache();
|
uploadService.clearCache();
|
||||||
});
|
});
|
||||||
@@ -141,7 +152,7 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT upload the folder dropped', (done) => {
|
it('should NOT upload the folder dropped', () => {
|
||||||
component.disabled = true;
|
component.disabled = true;
|
||||||
spyOn(uploadService, 'addToQueue');
|
spyOn(uploadService, 'addToQueue');
|
||||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||||
@@ -156,12 +167,10 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
component.onFolderEntityDropped(itemEntity);
|
component.onFolderEntityDropped(itemEntity);
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
setTimeout(() => {
|
expect(uploadService.addToQueue).not.toHaveBeenCalled();
|
||||||
expect(uploadService.addToQueue).not.toHaveBeenCalled();
|
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
||||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
}, 0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT upload the files', () => {
|
it('should NOT upload the files', () => {
|
||||||
@@ -169,17 +178,6 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
spyOn(uploadService, 'addToQueue');
|
spyOn(uploadService, 'addToQueue');
|
||||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
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();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
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', () => {
|
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) => {
|
addToQueueSpy.and.callFake((fileList) => {
|
||||||
expect(fileList.name).toBe('file');
|
expect(fileList.name).toBe('file');
|
||||||
@@ -306,17 +293,6 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should upload a file when user has create permission on target folder', () => {
|
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', {
|
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
@@ -329,37 +305,38 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
expect(uploadService.addToQueue).toHaveBeenCalled();
|
expect(uploadService.addToQueue).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should upload a file to a specific target folder when dropped onto one', (done) => {
|
it('should upload a file to a specific target folder when dropped onto one', () => {
|
||||||
const fakeItem = {
|
const fakePippoItem = {
|
||||||
fullPath: '/folder-fake/file-fake.png',
|
fullPath: '/folder-fake/file-fake.png',
|
||||||
isDirectory: false,
|
isDirectory: false,
|
||||||
isFile: true,
|
isFile: true,
|
||||||
name: 'file-fake.png',
|
|
||||||
relativeFolder: '/',
|
relativeFolder: '/',
|
||||||
|
name: 'file-fake.png',
|
||||||
file: (callbackFile) => {
|
file: (callbackFile) => {
|
||||||
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
|
const fileFake = new File(['fakefake'], 'file-fake.png', { type: 'image/png' });
|
||||||
callbackFile(fileFake);
|
callbackFile(fileFake);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
addToQueueSpy.and.callFake((fileList) => {
|
|
||||||
expect(fileList.name).toBe('file');
|
|
||||||
expect(fileList.options.path).toBe('pippo/');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
data: getFakeShareDataRow(),
|
data: getFakeShareDataRow(),
|
||||||
files: [fakeItem]
|
files: [fakePippoItem]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addToQueueSpy.and.callFake((fileList) => {
|
||||||
|
expect(fileList.name).toBe('file');
|
||||||
|
expect(fileList.options.path).toBe('pippo/');
|
||||||
|
});
|
||||||
|
|
||||||
component.onUploadFiles(fakeCustomEvent);
|
component.onUploadFiles(fakeCustomEvent);
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should upload a folder to a specific target folder when dropped onto one', (done) => {
|
it('should upload a folder to a specific target folder when dropped onto one', () => {
|
||||||
const fakeItem = {
|
const fakeSuperItem = {
|
||||||
fullPath: '/folder-fake/file-fake.png',
|
fullPath: '/folder-fake/file-fake.png',
|
||||||
isDirectory: false,
|
isDirectory: false,
|
||||||
isFile: true,
|
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', {
|
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
data: getFakeShareDataRow(),
|
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);
|
component.onUploadFiles(fakeCustomEvent);
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should trigger updating the file version when we drop a file over another file', async () => {
|
it('should trigger updating the file version when we drop a file over another file', async () => {
|
||||||
spyOn(component.updateFileVersion, 'emit');
|
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', {
|
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
@@ -421,24 +388,6 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
it('should raise an error if upload a file goes wrong', async () => {
|
it('should raise an error if upload a file goes wrong', async () => {
|
||||||
spyOn(uploadService, 'getUploadPromise').and.callThrough();
|
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', {
|
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||||
detail: {
|
detail: {
|
||||||
data: getFakeShareDataRow(),
|
data: getFakeShareDataRow(),
|
||||||
@@ -446,22 +395,17 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
component.error.subscribe((error) => {
|
||||||
|
expect(error).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
component.onUploadFiles(fakeCustomEvent);
|
component.onUploadFiles(fakeCustomEvent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
await fixture.whenStable();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit success if successful of upload a file', async () => {
|
it('should emit success if successful of upload a file', async () => {
|
||||||
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadSuccessPromise);
|
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();
|
fixture.detectChanges();
|
||||||
|
|
||||||
@@ -481,17 +425,6 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
|
|
||||||
it('should emit error if upload errored', async () => {
|
it('should emit error if upload errored', async () => {
|
||||||
spyOn(uploadService, 'getUploadPromise').and.returnValue(mockUploadErrorPromise);
|
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();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
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 { TranslateModule } from '@ngx-translate/core';
|
||||||
import { VersionUploadComponent } from './version-upload.component';
|
import { VersionUploadComponent } from './version-upload.component';
|
||||||
import { ContentService, setupTestBed, UploadService } from '@alfresco/adf-core';
|
import { ContentService, setupTestBed, UploadService } from '@alfresco/adf-core';
|
||||||
@@ -62,32 +62,35 @@ describe('VersionUploadComponent', () => {
|
|||||||
contentService = TestBed.inject(ContentService);
|
contentService = TestBed.inject(ContentService);
|
||||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||||
component.node = node;
|
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(() => {
|
component.uploadStarted.subscribe(() => {
|
||||||
expect(component.disabled).toEqual(true);
|
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);
|
spyOn(component, 'canUpload').and.returnValue(true);
|
||||||
component.error.subscribe(() => {
|
component.error.subscribe(() => {
|
||||||
expect(component.disabled).toEqual(false);
|
expect(component.disabled).toEqual(false);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
component.onError({} as any);
|
component.onError({} as any);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should enable upload button on success', (done) => {
|
it('should enable upload button on success', () => {
|
||||||
spyOn(component, 'canUpload').and.returnValue(true);
|
spyOn(component, 'canUpload').and.returnValue(true);
|
||||||
component.success.subscribe(() => {
|
component.success.subscribe(() => {
|
||||||
expect(component.disabled).toEqual(false);
|
expect(component.disabled).toEqual(false);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
component.onSuccess(true);
|
component.onSuccess(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
Reference in New Issue
Block a user