mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5422] remove deprecated "async()" from unit tests (#7109)
* remove angualar async from content services * upgrade more tests * upgrade core tests * upgrade tests * fix deprecated constant * fix tests * fix after rebase
This commit is contained in:
@@ -305,17 +305,23 @@ describe('AspectListDialogComponent', () => {
|
||||
});
|
||||
|
||||
it('Should apply button be disabled by default', async () => {
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const applyButton = fixture.nativeElement.querySelector('#aspect-list-dialog-actions-apply');
|
||||
expect(applyButton.disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('Should apply button get enabled when the aspect list gets updated', async () => {
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const applyButton = fixture.nativeElement.querySelector('#aspect-list-dialog-actions-apply');
|
||||
|
||||
fixture.nativeElement.querySelector('#aspect-list-dialog-actions-clear').click();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(applyButton.disabled).toBe(false);
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { AspectEntry, AspectPaging } from '@alfresco/js-api';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { AlfrescoApiService, AppConfigService, LogService, setupTestBed } from 'core';
|
||||
@@ -163,34 +163,37 @@ describe('AspectListService', () => {
|
||||
service = TestBed.inject(AspectListService);
|
||||
});
|
||||
|
||||
it('should get the list of only available aspects', async(() => {
|
||||
it('should get the list of only available aspects', (done) => {
|
||||
aspectTypesApi.listAspects.and.returnValues(of(listAspectResp), of(customListAspectResp));
|
||||
service.getAspects().subscribe((list) => {
|
||||
expect(list.length).toBe(2);
|
||||
expect(list[0].entry.id).toBe('frs:AspectOne');
|
||||
expect(list[1].entry.id).toBe('frs:AspectCustom');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return a value when the standard aspect call fails', async(() => {
|
||||
it('should return a value when the standard aspect call fails', (done) => {
|
||||
spyOn(logService, 'error').and.stub();
|
||||
aspectTypesApi.listAspects.and.returnValues(throwError('Insert Coin'), of(customListAspectResp));
|
||||
service.getAspects().subscribe((list) => {
|
||||
expect(list.length).toBe(1);
|
||||
expect(list[0].entry.id).toBe('frs:AspectCustom');
|
||||
expect(logService.error).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return a value when the custom aspect call fails', async(() => {
|
||||
it('should return a value when the custom aspect call fails', (done) => {
|
||||
spyOn(logService, 'error').and.stub();
|
||||
aspectTypesApi.listAspects.and.returnValues(of(listAspectResp), throwError('Insert Coin'));
|
||||
service.getAspects().subscribe((list) => {
|
||||
expect(list.length).toBe(1);
|
||||
expect(list[0].entry.id).toBe('frs:AspectOne');
|
||||
expect(logService.error).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { fakeNodeWithCreatePermission } from '../mock';
|
||||
@@ -42,16 +42,16 @@ describe('DropdownBreadcrumb', () => {
|
||||
providers: [{ provide: DocumentListService, useValue: documentListService }]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DropdownBreadcrumbComponent);
|
||||
component = fixture.componentInstance;
|
||||
documentList = TestBed.createComponent<DocumentListComponent>(DocumentListComponent).componentInstance;
|
||||
documentListService = TestBed.inject(DocumentListService);
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(async(() => {
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
}));
|
||||
});
|
||||
|
||||
function openSelect() {
|
||||
const folderIcon = fixture.debugElement.nativeElement.querySelector('[data-automation-id="dropdown-breadcrumb-trigger"]');
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, tick, fakeAsync } from '@angular/core/testing';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { MinimalNode, Node } from '@alfresco/js-api';
|
||||
@@ -98,17 +98,18 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Folder', () => {
|
||||
it('should show the folder node', () => {
|
||||
it('should show the folder node', (done) => {
|
||||
component.expanded = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, folderNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||
expect(basicPropertiesComponent.properties).toBeDefined();
|
||||
done();
|
||||
});
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, folderNode, false) });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -138,10 +139,8 @@ describe('ContentMetadataComponent', () => {
|
||||
it('should save changedProperties on save click', fakeAsync(async () => {
|
||||
component.editable = true;
|
||||
const property = <CardViewBaseItemModel> { key: 'properties.property-key', value: 'original-value' };
|
||||
const expectedNode = Object.assign({}, node, { name: 'some-modified-value' });
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => {
|
||||
return of(expectedNode);
|
||||
});
|
||||
const expectedNode = { ...node, name: 'some-modified-value' };
|
||||
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
|
||||
|
||||
updateService.update(property, 'updated-value');
|
||||
tick(600);
|
||||
@@ -156,7 +155,7 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(nodesApiService.updateNode).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should throw error on unsuccessful save', fakeAsync(async (done) => {
|
||||
it('should throw error on unsuccessful save', fakeAsync((done) => {
|
||||
const logService: LogService = TestBed.inject(LogService);
|
||||
component.editable = true;
|
||||
const property = <CardViewBaseItemModel> { key: 'properties.property-key', value: 'original-value' };
|
||||
@@ -171,25 +170,22 @@ describe('ContentMetadataComponent', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => {
|
||||
return throwError(new Error('My bad'));
|
||||
});
|
||||
spyOn(nodesApiService, 'updateNode').and.returnValue(throwError(new Error('My bad')));
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const saveButton = fixture.debugElement.query(By.css('[data-automation-id="save-metadata"]'));
|
||||
saveButton.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const saveButton = fixture.debugElement.query(By.css('[data-automation-id="save-metadata"]'));
|
||||
saveButton.nativeElement.click();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should open the confirm dialog when content type is changed', fakeAsync(() => {
|
||||
component.editable = true;
|
||||
const property = <CardViewBaseItemModel> { key: 'nodeType', value: 'ft:sbiruli' };
|
||||
const expectedNode = Object.assign({}, node, { nodeType: 'ft:sbiruli' });
|
||||
const expectedNode = { ...node, nodeType: 'ft:sbiruli' };
|
||||
spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true));
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => {
|
||||
return of(expectedNode);
|
||||
});
|
||||
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
|
||||
|
||||
updateService.update(property, 'ft:poppoli');
|
||||
tick(600);
|
||||
@@ -211,9 +207,7 @@ describe('ContentMetadataComponent', () => {
|
||||
const expectedNode = Object.assign({}, node, { nodeType: 'ft:sbiruli' });
|
||||
spyOn(contentMetadataService, 'openConfirmDialog').and.returnValue(of(true));
|
||||
spyOn(updateService, 'updateNodeAspect');
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => {
|
||||
return of(expectedNode);
|
||||
});
|
||||
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
|
||||
|
||||
updateService.update(property, 'ft:poppoli');
|
||||
tick(600);
|
||||
@@ -235,9 +229,7 @@ describe('ContentMetadataComponent', () => {
|
||||
component.hasMetadataChanged = true;
|
||||
component.editable = true;
|
||||
const expectedNode = Object.assign({}, node, { name: 'some-modified-value' });
|
||||
spyOn(nodesApiService, 'updateNode').and.callFake(() => {
|
||||
return of(expectedNode);
|
||||
});
|
||||
spyOn(nodesApiService, 'updateNode').and.returnValue(of(expectedNode));
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -251,10 +243,10 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Properties loading', () => {
|
||||
let expectedNode;
|
||||
let expectedNode: MinimalNode;
|
||||
|
||||
beforeEach(() => {
|
||||
expectedNode = Object.assign({}, node, { name: 'some-modified-value' });
|
||||
expectedNode = { ...node, name: 'some-modified-value' };
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -267,36 +259,37 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(contentMetadataService.getBasicProperties).toHaveBeenCalledWith(expectedNode);
|
||||
});
|
||||
|
||||
it('should pass through the loaded basic properties to the card view', async(() => {
|
||||
it('should pass through the loaded basic properties to the card view', async () => {
|
||||
const expectedProperties = [];
|
||||
component.expanded = false;
|
||||
fixture.detectChanges();
|
||||
spyOn(contentMetadataService, 'getBasicProperties').and.callFake(() => {
|
||||
return of(expectedProperties);
|
||||
});
|
||||
|
||||
spyOn(contentMetadataService, 'getBasicProperties').and.returnValue(of(expectedProperties));
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||
expect(basicPropertiesComponent.properties.length).toBe(expectedProperties.length);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should pass through the displayEmpty to the card view of basic properties', async(() => {
|
||||
component.displayEmpty = false;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||
expect(basicPropertiesComponent.properties.length).toBe(expectedProperties.length);
|
||||
});
|
||||
|
||||
it('should pass through the displayEmpty to the card view of basic properties', async () => {
|
||||
component.displayEmpty = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
spyOn(contentMetadataService, 'getBasicProperties').and.returnValue(of([]));
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||
expect(basicPropertiesComponent.displayEmpty).toBe(false);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
|
||||
expect(basicPropertiesComponent.displayEmpty).toBe(false);
|
||||
});
|
||||
|
||||
it('should load the group properties on node change', () => {
|
||||
spyOn(contentMetadataService, 'getGroupedProperties');
|
||||
@@ -306,55 +299,55 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(contentMetadataService.getGroupedProperties).toHaveBeenCalledWith(expectedNode, 'custom-preset');
|
||||
});
|
||||
|
||||
it('should pass through the loaded group properties to the card view', async(() => {
|
||||
it('should pass through the loaded group properties to the card view', async () => {
|
||||
const expectedProperties = [];
|
||||
component.expanded = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: expectedProperties } as any]));
|
||||
spyOn(component, 'showGroup').and.returnValue(true);
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const firstGroupedPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance;
|
||||
expect(firstGroupedPropertiesComponent.properties).toBe(expectedProperties);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should pass through the displayEmpty to the card view of grouped properties', async(() => {
|
||||
const firstGroupedPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance;
|
||||
expect(firstGroupedPropertiesComponent.properties).toBe(expectedProperties);
|
||||
});
|
||||
|
||||
it('should pass through the displayEmpty to the card view of grouped properties', async () => {
|
||||
component.expanded = true;
|
||||
component.displayEmpty = false;
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any]));
|
||||
spyOn(component, 'showGroup').and.returnValue(true);
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance;
|
||||
expect(basicPropertiesComponent.displayEmpty).toBe(false);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should hide card views group when the grouped properties are empty', async(() => {
|
||||
component.expanded = true;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const basicPropertiesComponent = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container adf-card-view')).componentInstance;
|
||||
expect(basicPropertiesComponent.displayEmpty).toBe(false);
|
||||
});
|
||||
|
||||
it('should hide card views group when the grouped properties are empty', async () => {
|
||||
component.expanded = true;
|
||||
|
||||
spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of([{ properties: [] } as any]));
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel'));
|
||||
expect(basicPropertiesGroup).toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display card views group when there is at least one property that is not empty', async(() => {
|
||||
component.expanded = true;
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel'));
|
||||
expect(basicPropertiesGroup).toBeNull();
|
||||
});
|
||||
|
||||
it('should display card views group when there is at least one property that is not empty', async () => {
|
||||
component.expanded = true;
|
||||
|
||||
const cardViewGroup = {
|
||||
title: 'Group 1', properties: [{
|
||||
data: null,
|
||||
@@ -369,12 +362,12 @@ describe('ContentMetadataComponent', () => {
|
||||
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
|
||||
component.basicProperties$.subscribe(() => {
|
||||
fixture.detectChanges();
|
||||
const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel'));
|
||||
expect(basicPropertiesGroup).toBeDefined();
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const basicPropertiesGroup = fixture.debugElement.query(By.css('.adf-metadata-grouped-properties-container mat-expansion-panel'));
|
||||
expect(basicPropertiesGroup).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Properties displaying', () => {
|
||||
@@ -400,20 +393,22 @@ describe('ContentMetadataComponent', () => {
|
||||
});
|
||||
|
||||
describe('Expand the panel', () => {
|
||||
let expectedNode;
|
||||
let expectedNode: MinimalNode;
|
||||
|
||||
beforeEach(() => {
|
||||
expectedNode = Object.assign({}, node, { name: 'some-modified-value' });
|
||||
expectedNode = { ...node, name: 'some-modified-value' };
|
||||
spyOn(contentMetadataService, 'getGroupedProperties').and.returnValue(of(mockGroupProperties));
|
||||
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
|
||||
});
|
||||
|
||||
it('should open and update drawer with expand section dynamically', async(() => {
|
||||
it('should open and update drawer with expand section dynamically', async () => {
|
||||
component.displayAspect = 'EXIF';
|
||||
component.expanded = true;
|
||||
component.displayEmpty = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable()
|
||||
|
||||
let defaultProp = queryDom(fixture);
|
||||
let exifProp = queryDom(fixture, 'EXIF');
|
||||
let customProp = queryDom(fixture, 'CUSTOM');
|
||||
@@ -422,7 +417,10 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(customProp.componentInstance.expanded).toBeFalsy();
|
||||
|
||||
component.displayAspect = 'CUSTOM';
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable()
|
||||
|
||||
defaultProp = queryDom(fixture);
|
||||
exifProp = queryDom(fixture, 'EXIF');
|
||||
customProp = queryDom(fixture, 'CUSTOM');
|
||||
@@ -431,29 +429,33 @@ describe('ContentMetadataComponent', () => {
|
||||
expect(customProp.componentInstance.expanded).toBeTruthy();
|
||||
|
||||
component.displayAspect = 'Properties';
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable()
|
||||
|
||||
defaultProp = queryDom(fixture);
|
||||
exifProp = queryDom(fixture, 'EXIF');
|
||||
customProp = queryDom(fixture, 'CUSTOM');
|
||||
expect(defaultProp.componentInstance.expanded).toBeTruthy();
|
||||
expect(exifProp.componentInstance.expanded).toBeFalsy();
|
||||
expect(customProp.componentInstance.expanded).toBeFalsy();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not expand anything if input is wrong', async(() => {
|
||||
it('should not expand anything if input is wrong', async () => {
|
||||
component.displayAspect = 'XXXX';
|
||||
component.expanded = true;
|
||||
component.displayEmpty = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const defaultProp = queryDom(fixture);
|
||||
const exifProp = queryDom(fixture, 'EXIF');
|
||||
const customProp = queryDom(fixture, 'CUSTOM');
|
||||
expect(defaultProp.componentInstance.expanded).toBeFalsy();
|
||||
expect(exifProp.componentInstance.expanded).toBeFalsy();
|
||||
expect(customProp.componentInstance.expanded).toBeFalsy();
|
||||
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('events', () => {
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { AppConfigService, LogService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { IndifferentConfigService } from './indifferent-config.service';
|
||||
import { AspectOrientedConfigService } from './aspect-oriented-config.service';
|
||||
@@ -43,55 +43,51 @@ describe('ContentMetadataConfigFactory', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
factory = TestBed.inject(ContentMetadataConfigFactory);
|
||||
appConfig = TestBed.inject(AppConfigService);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
|
||||
let logService: LogService;
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
logService = TestBed.inject(LogService);
|
||||
spyOn(logService, 'error').and.stub();
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
|
||||
it('should get back to default preset if no preset is provided as parameter', async(() => {
|
||||
it('should get back to default preset if no preset is provided as parameter', () => {
|
||||
config = factory.get();
|
||||
|
||||
expect(config).toEqual(jasmine.any(IndifferentConfigService));
|
||||
}));
|
||||
});
|
||||
|
||||
it('should get back to default preset if no preset is set', async(() => {
|
||||
it('should get back to default preset if no preset is set', () => {
|
||||
config = factory.get('default');
|
||||
|
||||
expect(config).toEqual(jasmine.any(IndifferentConfigService));
|
||||
expect(logService.error).not.toHaveBeenCalled();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should get back to the default preset if the requested preset does not exist', async(() => {
|
||||
it('should get back to the default preset if the requested preset does not exist', () => {
|
||||
config = factory.get('not-existing-preset');
|
||||
|
||||
expect(config).toEqual(jasmine.any(IndifferentConfigService));
|
||||
}));
|
||||
});
|
||||
|
||||
it('should log an error message if the requested preset does not exist', async(() => {
|
||||
it('should log an error message if the requested preset does not exist', () => {
|
||||
config = factory.get('not-existing-preset');
|
||||
|
||||
expect(logService.error).toHaveBeenCalledWith('No content-metadata preset for: not-existing-preset');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('set', () => {
|
||||
|
||||
function setConfig(presetName, presetConfig) {
|
||||
function setConfig(presetName: string, presetConfig: any) {
|
||||
appConfig.config['content-metadata'] = {
|
||||
presets: {
|
||||
[presetName]: presetConfig
|
||||
@@ -99,29 +95,29 @@ describe('ContentMetadataConfigFactory', () => {
|
||||
};
|
||||
}
|
||||
|
||||
it('should get back the IndifferentConfigService preset if the preset config is indifferent', async(() => {
|
||||
it('should get back the IndifferentConfigService preset if the preset config is indifferent', () => {
|
||||
setConfig('default', '*');
|
||||
|
||||
config = factory.get('default');
|
||||
|
||||
expect(config).toEqual(jasmine.any(IndifferentConfigService));
|
||||
}));
|
||||
});
|
||||
|
||||
it('should get back the AspectOrientedConfigService preset if the preset config is aspect oriented', async(() => {
|
||||
it('should get back the AspectOrientedConfigService preset if the preset config is aspect oriented', () => {
|
||||
setConfig('default', { 'exif:exif': '*' });
|
||||
|
||||
config = factory.get('default');
|
||||
|
||||
expect(config).toEqual(jasmine.any(AspectOrientedConfigService));
|
||||
}));
|
||||
});
|
||||
|
||||
it('should get back the LayoutOrientedConfigService preset if the preset config is layout oriented', async(() => {
|
||||
it('should get back the LayoutOrientedConfigService preset if the preset config is layout oriented', () => {
|
||||
setConfig('default', []);
|
||||
|
||||
config = factory.get('default');
|
||||
|
||||
expect(config).toEqual(jasmine.any(LayoutOrientedConfigService));
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
|
||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { FolderDialogComponent } from './folder.dialog';
|
||||
@@ -25,7 +25,6 @@ import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('FolderDialogComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<FolderDialogComponent>;
|
||||
let component: FolderDialogComponent;
|
||||
let nodesApi: NodesApiService;
|
||||
@@ -77,10 +76,10 @@ describe('FolderDialogComponent', () => {
|
||||
});
|
||||
|
||||
it('should have the proper title', () => {
|
||||
const title = fixture.debugElement.query(By.css('[mat-dialog-title]'));
|
||||
expect(title === null).toBe(false);
|
||||
expect(title.nativeElement.innerText.trim()).toBe('CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE');
|
||||
});
|
||||
const title = fixture.debugElement.query(By.css('[mat-dialog-title]'));
|
||||
expect(title === null).toBe(false);
|
||||
expect(title.nativeElement.innerText.trim()).toBe('CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE');
|
||||
});
|
||||
|
||||
it('should update form input', () => {
|
||||
component.form.controls['name'].setValue('folder-name-update');
|
||||
@@ -125,19 +124,20 @@ describe('FolderDialogComponent', () => {
|
||||
expect(dialogRef.close).toHaveBeenCalledWith(folder);
|
||||
});
|
||||
|
||||
it('should emit success output event with folder when submit is successful', async(() => {
|
||||
const folder: any = { data: 'folder-data' };
|
||||
let expectedNode = null;
|
||||
it('should emit success output event with folder when submit is successful', async () => {
|
||||
const folder: any = { data: 'folder-data' };
|
||||
let expectedNode = null;
|
||||
|
||||
spyOn(nodesApi, 'updateNode').and.returnValue(of(folder));
|
||||
spyOn(nodesApi, 'updateNode').and.returnValue(of(folder));
|
||||
|
||||
component.success.subscribe((node) => { expectedNode = node; });
|
||||
component.submit();
|
||||
component.success.subscribe((node) => { expectedNode = node; });
|
||||
component.submit();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(expectedNode).toBe(folder);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(expectedNode).toBe(folder);
|
||||
});
|
||||
|
||||
it('should not submit if form is invalid', () => {
|
||||
spyOn(nodesApi, 'updateNode');
|
||||
@@ -213,27 +213,27 @@ describe('FolderDialogComponent', () => {
|
||||
});
|
||||
|
||||
it('should submit updated values if form is valid (with custom nodeType)', () => {
|
||||
spyOn(nodesApi, 'createFolder').and.returnValue(of(null));
|
||||
spyOn(nodesApi, 'createFolder').and.returnValue(of(null));
|
||||
|
||||
component.form.controls['name'].setValue('folder-name-update');
|
||||
component.form.controls['title'].setValue('folder-title-update');
|
||||
component.form.controls['description'].setValue('folder-description-update');
|
||||
component.nodeType = 'cm:sushi';
|
||||
component.form.controls['name'].setValue('folder-name-update');
|
||||
component.form.controls['title'].setValue('folder-title-update');
|
||||
component.form.controls['description'].setValue('folder-description-update');
|
||||
component.nodeType = 'cm:sushi';
|
||||
|
||||
component.submit();
|
||||
component.submit();
|
||||
|
||||
expect(nodesApi.createFolder).toHaveBeenCalledWith(
|
||||
'parentNodeId',
|
||||
{
|
||||
name: 'folder-name-update',
|
||||
properties: {
|
||||
'cm:title': 'folder-title-update',
|
||||
'cm:description': 'folder-description-update'
|
||||
},
|
||||
nodeType: 'cm:sushi'
|
||||
}
|
||||
);
|
||||
});
|
||||
expect(nodesApi.createFolder).toHaveBeenCalledWith(
|
||||
'parentNodeId',
|
||||
{
|
||||
name: 'folder-name-update',
|
||||
properties: {
|
||||
'cm:title': 'folder-title-update',
|
||||
'cm:description': 'folder-description-update'
|
||||
},
|
||||
nodeType: 'cm:sushi'
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should call dialog to close with form data when submit is successfully', () => {
|
||||
const folder: any = {
|
||||
|
@@ -16,10 +16,10 @@
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange, EventEmitter } from '@angular/core';
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { ContentService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { FileNode } from '../../../mock';
|
||||
import { ContentActionHandler, ContentActionModel } from './../../models/content-action.model';
|
||||
import { ContentActionModel } from './../../models/content-action.model';
|
||||
import { DocumentActionsService } from './../../services/document-actions.service';
|
||||
import { FolderActionsService } from './../../services/folder-actions.service';
|
||||
import { NodeActionsService } from './../../services/node-actions.service';
|
||||
@@ -30,7 +30,6 @@ import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('ContentAction', () => {
|
||||
|
||||
let documentList: DocumentListComponent;
|
||||
let actionList: ContentActionListComponent;
|
||||
let documentActions: DocumentActionsService;
|
||||
@@ -229,16 +228,14 @@ describe('ContentAction', () => {
|
||||
});
|
||||
|
||||
it('should find document action handler via service', () => {
|
||||
const handler = <ContentActionHandler> function () {
|
||||
};
|
||||
const handler = () => {};
|
||||
const action = new ContentActionComponent(actionList, documentActions, null);
|
||||
spyOn(documentActions, 'getHandler').and.returnValue(handler);
|
||||
expect(action.getSystemHandler('document', 'name')).toBe(handler);
|
||||
});
|
||||
|
||||
it('should find folder action handler via service', () => {
|
||||
const handler = <ContentActionHandler> function () {
|
||||
};
|
||||
const handler = () => {};
|
||||
const action = new ContentActionComponent(actionList, null, folderActions);
|
||||
spyOn(folderActions, 'getHandler').and.returnValue(handler);
|
||||
expect(action.getSystemHandler('folder', 'name')).toBe(handler);
|
||||
@@ -255,20 +252,21 @@ describe('ContentAction', () => {
|
||||
expect(documentActions.getHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should wire model with custom event handler', async(() => {
|
||||
it('should wire model with custom event handler', (done) => {
|
||||
const action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||
const file = new FileNode();
|
||||
|
||||
const handler = new EventEmitter();
|
||||
handler.subscribe((e) => {
|
||||
expect(e.value).toBe(file);
|
||||
done();
|
||||
});
|
||||
|
||||
action.execute = handler;
|
||||
|
||||
action.ngOnInit();
|
||||
documentList.actions[0].execute(file);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should allow registering model without handler', () => {
|
||||
const action = new ContentActionComponent(actionList, documentActions, folderActions);
|
||||
|
@@ -56,7 +56,7 @@ export class DocumentListService implements DocumentListLoader {
|
||||
* @param targetParentId The id of the folder where the node will be copied
|
||||
* @returns NodeEntry for the copied node
|
||||
*/
|
||||
copyNode(nodeId: string, targetParentId: string) {
|
||||
copyNode(nodeId: string, targetParentId: string): Observable<NodeEntry> {
|
||||
return from(this.apiService.getInstance().nodes.copyNode(nodeId, { targetParentId })).pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { Node, NodeEntry } from '@alfresco/js-api';
|
||||
import { AppConfigService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
@@ -58,7 +58,7 @@ describe('NodeActionsService', () => {
|
||||
contentDialogService = TestBed.inject(ContentNodeDialogService);
|
||||
});
|
||||
|
||||
it('should be able to copy content', async(() => {
|
||||
it('should be able to copy content', fakeAsync(() => {
|
||||
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
||||
|
||||
@@ -67,7 +67,7 @@ describe('NodeActionsService', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to move content', async(() => {
|
||||
it('should be able to move content', fakeAsync(() => {
|
||||
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
||||
|
||||
@@ -76,7 +76,7 @@ describe('NodeActionsService', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to move folder', async(() => {
|
||||
it('should be able to move folder', fakeAsync(() => {
|
||||
spyOn(documentListService, 'moveNode').and.returnValue(of(new NodeEntry()));
|
||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
||||
|
||||
@@ -85,7 +85,7 @@ describe('NodeActionsService', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to copy folder', async(() => {
|
||||
it('should be able to copy folder', fakeAsync(() => {
|
||||
spyOn(documentListService, 'copyNode').and.returnValue(of(new NodeEntry()));
|
||||
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));
|
||||
|
||||
@@ -94,7 +94,7 @@ describe('NodeActionsService', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to propagate the dialog error', async(() => {
|
||||
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]));
|
||||
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Subject, of } from 'rxjs';
|
||||
@@ -112,19 +112,19 @@ describe('FolderCreateDirective', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should emit success event with node if the folder creation was successful', async(() => {
|
||||
it('should emit success event with node if the folder creation was successful', async () => {
|
||||
const testNode = <Node> {};
|
||||
fixture.detectChanges();
|
||||
|
||||
element.triggerEventHandler('click', event);
|
||||
dialogRefMock.componentInstance.success.next(testNode);
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||
});
|
||||
}));
|
||||
fixture.whenStable();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should open the dialog with the proper title and nodeType', async(() => {
|
||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||
});
|
||||
|
||||
it('should open the dialog with the proper title and nodeType', () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', event);
|
||||
|
||||
@@ -136,7 +136,7 @@ describe('FolderCreateDirective', () => {
|
||||
},
|
||||
width: jasmine.any(String)
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Without overrides', () => {
|
||||
@@ -149,7 +149,7 @@ describe('FolderCreateDirective', () => {
|
||||
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
||||
});
|
||||
|
||||
it('should open the dialog with the default title and nodeType', async(() => {
|
||||
it('should open the dialog with the default title and nodeType', () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', event);
|
||||
|
||||
@@ -161,6 +161,6 @@ describe('FolderCreateDirective', () => {
|
||||
},
|
||||
width: jasmine.any(String)
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Subject, of } from 'rxjs';
|
||||
@@ -80,34 +80,35 @@ describe('FolderEditDirective', () => {
|
||||
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
||||
});
|
||||
|
||||
it('should not emit folderEdit event when input value is undefined', () => {
|
||||
it('should not emit folderEdit event when input value is undefined', async () => {
|
||||
spyOn(dialogRefMock, 'afterClosed').and.returnValue(of(null));
|
||||
spyOn(contentService.folderEdit, 'next');
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
element.nativeElement.click();
|
||||
expect(contentService.folderEdit.next).not.toHaveBeenCalled();
|
||||
});
|
||||
element.nativeElement.click();
|
||||
expect(contentService.folderEdit.next).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit success event with node if the folder creation was successful', async(() => {
|
||||
const testNode = <Node> {};
|
||||
it('should emit success event with node if the folder creation was successful', async () => {
|
||||
fixture.detectChanges();
|
||||
const testNode = <Node> {};
|
||||
|
||||
element.triggerEventHandler('click', event);
|
||||
dialogRefMock.componentInstance.success.next(testNode);
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||
});
|
||||
|
||||
it('should open the dialog with the proper title', async(() => {
|
||||
it('should open the dialog with the proper title', async () => {
|
||||
fixture.detectChanges();
|
||||
element.triggerEventHandler('click', event);
|
||||
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), {
|
||||
data: {
|
||||
folder: jasmine.any(Object),
|
||||
@@ -115,5 +116,5 @@ describe('FolderEditDirective', () => {
|
||||
},
|
||||
width: jasmine.any(String)
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -89,37 +89,45 @@ describe('AddPermissionDialog', () => {
|
||||
});
|
||||
|
||||
it('should close the dialog when close button is clicked', () => {
|
||||
const closeButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-close-button"]');
|
||||
const closeButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-close-button"]');
|
||||
expect(closeButton).not.toBeNull();
|
||||
closeButton.click();
|
||||
expect(dialogRef.close).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should disable the confirm button when no selection is applied', () => {
|
||||
const confirmButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
const confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should enable the button when a selection is done', async() => {
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||
let confirmButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
let confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBeTruthy();
|
||||
await fixture.detectChanges();
|
||||
confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
});
|
||||
|
||||
it('should update the role after selection', async (done) => {
|
||||
spyOn(component, 'onMemberUpdate').and.callThrough();
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
let confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
let confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(true);
|
||||
addPermissionPanelComponent.select.emit([fakeAuthorityResults[0]]);
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
confirmButton.click();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger')));
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
@@ -129,7 +137,10 @@ describe('AddPermissionDialog', () => {
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(2);
|
||||
options[0].triggerEventHandler('click', {});
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.onMemberUpdate).toHaveBeenCalled();
|
||||
|
||||
data.confirm.subscribe((selection) => {
|
||||
@@ -137,7 +148,7 @@ describe('AddPermissionDialog', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
confirmButton.click();
|
||||
});
|
||||
@@ -145,30 +156,40 @@ describe('AddPermissionDialog', () => {
|
||||
it('should update all the user role on header column update', async () => {
|
||||
spyOn(component, 'onBulkUpdate').and.callThrough();
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
let confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
let confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(true);
|
||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
confirmButton.click();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const selectBox = fixture.debugElement.query(By.css(('[id="adf-bulk-select-role-permission"] .mat-select-trigger')));
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const options = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(2);
|
||||
options[0].triggerEventHandler('click', {});
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.onBulkUpdate).toHaveBeenCalled();
|
||||
|
||||
data.confirm.subscribe((selection) => {
|
||||
expect(selection.length).toBe(3);
|
||||
});
|
||||
|
||||
confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
confirmButton.click();
|
||||
});
|
||||
@@ -177,31 +198,42 @@ describe('AddPermissionDialog', () => {
|
||||
spyOn(component, 'onMemberUpdate').and.callThrough();
|
||||
spyOn(component, 'onMemberDelete').and.callThrough();
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
let confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
let confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(true);
|
||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
confirmButton.click();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger')));
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const options = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(2);
|
||||
options[0].triggerEventHandler('click', {});
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.onMemberUpdate).toHaveBeenCalled();
|
||||
|
||||
confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
expect(confirmButton.disabled).toBe(true);
|
||||
const deleteButton = element.querySelectorAll('[data-automation-id="adf-delete-permission-button"]') as any;
|
||||
deleteButton[1].click();
|
||||
deleteButton[2].click();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(confirmButton.disabled).toBe(false);
|
||||
expect(component.onMemberDelete).toHaveBeenCalled();
|
||||
@@ -220,8 +252,9 @@ describe('AddPermissionDialog', () => {
|
||||
expect(fakeAuthorityResults[0].entry.id).toBe(selection[0].authorityId);
|
||||
});
|
||||
|
||||
await fixture.detectChanges();
|
||||
const confirmButton = <HTMLButtonElement> element.querySelector('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
const confirmButton = element.querySelector<HTMLButtonElement>('[data-automation-id="add-permission-dialog-confirm-button"]');
|
||||
confirmButton.click();
|
||||
});
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, 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';
|
||||
@@ -42,9 +42,12 @@ describe('AddPermissionPanelComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AddPermissionPanelComponent);
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
|
||||
debugElement = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
@@ -64,8 +67,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
expect(element.querySelector('#searchInput')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should show search results when user types something', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should show search results when user types something', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
||||
expect(element.querySelector('#searchInput')).not.toBeNull();
|
||||
@@ -78,8 +80,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit a select event with the selected items when an item is clicked', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should emit a select event with the selected items when an item is clicked', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
component.select.subscribe((items) => {
|
||||
expect(items).not.toBeNull();
|
||||
@@ -98,8 +99,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the icon related on the nodeType', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should show the icon related on the nodeType', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
expect(element.querySelector('#adf-add-permission-type-search')).not.toBeNull();
|
||||
expect(element.querySelector('#searchInput')).not.toBeNull();
|
||||
@@ -115,8 +115,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should clear the search when user delete the search input field', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
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();
|
||||
@@ -136,8 +135,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should remove element from selection when is clicked and already selected', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should remove element from selection when is clicked and already selected', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
||||
component.select.subscribe((items) => {
|
||||
@@ -156,8 +154,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should always show as extra result the everyone group', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should always show as extra result the everyone group', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
||||
|
||||
@@ -175,8 +172,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show everyone group when search return no result', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should show everyone group when search return no result', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of({ list: { entries: [] } }));
|
||||
component.selectedItems.push(fakeAuthorityListResult.list.entries[0]);
|
||||
|
||||
@@ -190,8 +186,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show first and last name of users', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should show first and last name of users', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeNameListResult));
|
||||
component.selectedItems.push(fakeNameListResult.list.entries[0]);
|
||||
component.selectedItems.push(fakeNameListResult.list.entries[1]);
|
||||
@@ -208,8 +203,7 @@ describe('AddPermissionPanelComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit unique element in between multiple search', async(() => {
|
||||
searchApiService = fixture.componentRef.injector.get(SearchService);
|
||||
it('should emit unique element in between multiple search', fakeAsync(() => {
|
||||
spyOn(searchApiService, 'search').and.returnValue(of(fakeAuthorityListResult));
|
||||
let searchAttempt = 0;
|
||||
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { Node } from '@alfresco/js-api';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AddPermissionComponent } from './add-permission.component';
|
||||
import { AddPermissionPanelComponent } from './add-permission-panel.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
@@ -61,27 +61,28 @@ describe('AddPermissionComponent', () => {
|
||||
expect(addButton.disabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should enable the ADD button when a selection is sent', async(() => {
|
||||
it('should enable the ADD button when a selection is sent', async () => {
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
|
||||
expect(addButton.disabled).toBeFalsy();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should NOT enable the ADD button when a selection is sent but the user does not have the permissions', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
|
||||
expect(addButton.disabled).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should NOT enable the ADD button when a selection is sent but the user does not have the permissions', async () => {
|
||||
const addPermissionPanelComponent: AddPermissionPanelComponent = fixture.debugElement.query(By.directive(AddPermissionPanelComponent)).componentInstance;
|
||||
addPermissionPanelComponent.select.emit(fakeAuthorityResults);
|
||||
fixture.componentInstance.currentNode = new Node({id: 'fake-node-id'});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
|
||||
expect(addButton.disabled).toBeTruthy();
|
||||
});
|
||||
}));
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
|
||||
expect(addButton.disabled).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should emit a success event when the node is updated', async (done) => {
|
||||
fixture.componentInstance.selectedItems = fakeAuthorityResults;
|
||||
@@ -92,8 +93,10 @@ describe('AddPermissionComponent', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
await fixture.detectChanges();
|
||||
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
|
||||
addButton.click();
|
||||
});
|
||||
|
||||
@@ -116,8 +119,10 @@ describe('AddPermissionComponent', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
await fixture.detectChanges();
|
||||
const addButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#adf-add-permission-action-button');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const addButton = element.querySelector<HTMLButtonElement>('#adf-add-permission-action-button');
|
||||
addButton.click();
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { SimpleInheritedPermissionTestComponent } from '../../mock/inherited-permission.component.mock';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { of } from 'rxjs';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
@@ -43,20 +43,22 @@ describe('InheritPermissionDirective', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SimpleInheritedPermissionTestComponent);
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
nodeService = TestBed.inject(NodesApiService);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to render the simple component', async(() => {
|
||||
it('should be able to render the simple component', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#sample-button-permission')).not.toBeNull();
|
||||
expect(element.querySelector('#update-notification')).toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to add inherited permission', async(() => {
|
||||
it('should be able to add inherited permission', async () => {
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeNoInherit));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, nodeBody) => {
|
||||
if (nodeBody.permissions?.isInheritanceEnabled) {
|
||||
@@ -66,17 +68,20 @@ describe('InheritPermissionDirective', () => {
|
||||
}
|
||||
});
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const buttonPermission: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#sample-button-permission');
|
||||
expect(buttonPermission).not.toBeNull();
|
||||
expect(element.querySelector('#update-notification')).toBeNull();
|
||||
buttonPermission.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#update-notification')).not.toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should be able to remove inherited permission', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#update-notification')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should be able to remove inherited permission', async () => {
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeWithInherit));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, nodeBody) => {
|
||||
if (nodeBody.permissions?.isInheritanceEnabled) {
|
||||
@@ -86,29 +91,37 @@ describe('InheritPermissionDirective', () => {
|
||||
}
|
||||
});
|
||||
component.updatedNode = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const buttonPermission: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#sample-button-permission');
|
||||
expect(buttonPermission).not.toBeNull();
|
||||
expect(element.querySelector('#update-notification')).not.toBeNull();
|
||||
buttonPermission.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#update-notification')).toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not update the node when node has no permission', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#update-notification')).toBeNull();
|
||||
});
|
||||
|
||||
it('should not update the node when node has no permission', async () => {
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeWithInheritNoPermission));
|
||||
const spyUpdateNode = spyOn(nodeService, 'updateNode');
|
||||
component.updatedNode = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const buttonPermission: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#sample-button-permission');
|
||||
expect(buttonPermission).not.toBeNull();
|
||||
expect(element.querySelector('#update-notification')).not.toBeNull();
|
||||
buttonPermission.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(spyUpdateNode).not.toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(spyUpdateNode).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { NodesApiService, SearchService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { of, throwError } from 'rxjs';
|
||||
@@ -78,7 +78,10 @@ describe('PermissionListComponent', () => {
|
||||
component.nodeId = 'fake-node-id';
|
||||
getNodeSpy.and.returnValue(of(fakeNodeWithoutPermissions));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('.adf-permission-container')).not.toBeNull();
|
||||
expect(element.querySelector('[data-automation-id="adf-locally-set-permission"]')).not.toBeNull();
|
||||
});
|
||||
@@ -87,7 +90,9 @@ describe('PermissionListComponent', () => {
|
||||
component.nodeId = 'fake-node-id';
|
||||
getNodeSpy.and.returnValue(throwError(null));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('.adf-no-permission__template')).not.toBeNull();
|
||||
expect(element.querySelector('.adf-no-permission__template p').textContent).toContain('PERMISSION_MANAGER.ERROR.NOT-FOUND');
|
||||
@@ -101,7 +106,7 @@ describe('PermissionListComponent', () => {
|
||||
|
||||
expect(element.querySelectorAll('[data-automation-id="adf-locally-set-permission"] .adf-datatable-row').length).toBe(2);
|
||||
|
||||
const showButton: HTMLButtonElement = element.querySelector('[data-automation-id="permission-info-button"]');
|
||||
const showButton = element.querySelector<HTMLButtonElement>('[data-automation-id="permission-info-button"]');
|
||||
showButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -112,7 +117,9 @@ describe('PermissionListComponent', () => {
|
||||
it('should show inherited details', async() => {
|
||||
getNodeSpy.and.returnValue(of(fakeNodeInheritedOnly));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined();
|
||||
expect(element.querySelector('.adf-inherit-container h3').textContent.trim())
|
||||
@@ -121,10 +128,11 @@ describe('PermissionListComponent', () => {
|
||||
.toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE');
|
||||
});
|
||||
|
||||
it('should toggle the inherited button', async() => {
|
||||
it('should toggle the inherited button', fakeAsync(() => {
|
||||
getNodeSpy.and.returnValue(of(fakeNodeInheritedOnly));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined();
|
||||
expect(element.querySelector('.adf-inherit-container h3').textContent.trim())
|
||||
@@ -136,19 +144,22 @@ describe('PermissionListComponent', () => {
|
||||
|
||||
const slider = fixture.debugElement.query(By.css('mat-slide-toggle'));
|
||||
slider.triggerEventHandler('change', { source: { checked: false } });
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.adf-inherit-container .mat-checked')).toBe(null);
|
||||
expect(element.querySelector('.adf-inherit-container h3').textContent.trim())
|
||||
.toBe('PERMISSION_MANAGER.LABELS.INHERITED-PERMISSIONS PERMISSION_MANAGER.LABELS.OFF');
|
||||
expect(element.querySelector('span[title="total"]').textContent.trim())
|
||||
.toBe('PERMISSION_MANAGER.LABELS.INHERITED-SUBTITLE');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not toggle inherited button for read only users', async () => {
|
||||
getNodeSpy.and.returnValue(of(fakeReadOnlyNodeInherited));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined();
|
||||
expect(element.querySelector('.adf-inherit-container h3').textContent.trim())
|
||||
@@ -160,7 +171,9 @@ describe('PermissionListComponent', () => {
|
||||
|
||||
const slider = fixture.debugElement.query(By.css('mat-slide-toggle'));
|
||||
slider.triggerEventHandler('change', { source: { checked: false } });
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('.adf-inherit-container .mat-checked')).toBeDefined();
|
||||
expect(element.querySelector('.adf-inherit-container h3').textContent.trim())
|
||||
@@ -182,7 +195,9 @@ describe('PermissionListComponent', () => {
|
||||
searchQuerySpy.and.returnValue(of(fakeSiteNodeResponse));
|
||||
component.ngOnInit();
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE');
|
||||
expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor');
|
||||
});
|
||||
@@ -191,7 +206,9 @@ describe('PermissionListComponent', () => {
|
||||
searchQuerySpy.and.returnValue(of(fakeSiteNodeResponse));
|
||||
component.ngOnInit();
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE');
|
||||
expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor');
|
||||
|
||||
@@ -199,7 +216,7 @@ describe('PermissionListComponent', () => {
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
|
||||
const options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
const options = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(4);
|
||||
expect(options[0].nativeElement.innerText).toContain('ADF.ROLES.SITECOLLABORATOR');
|
||||
@@ -212,12 +229,14 @@ describe('PermissionListComponent', () => {
|
||||
getNodeSpy.and.returnValue(of(fakeNodeLocalSiteManager));
|
||||
component.ngOnInit();
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_site_testsite_SiteManager');
|
||||
expect(element.querySelector('#adf-select-role-permission').textContent).toContain('ADF.ROLES.SITEMANAGER');
|
||||
const deleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_site_testsite_SiteManager"]');
|
||||
const deleteButton = element.querySelector<HTMLButtonElement>('[data-automation-id="adf-delete-permission-button-GROUP_site_testsite_SiteManager"]');
|
||||
expect(deleteButton.disabled).toBe(true);
|
||||
const otherDeleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-superadminuser"]');
|
||||
const otherDeleteButton = element.querySelector<HTMLButtonElement>('[data-automation-id="adf-delete-permission-button-superadminuser"]');
|
||||
expect(otherDeleteButton.disabled).toBe(false);
|
||||
});
|
||||
|
||||
@@ -226,7 +245,8 @@ describe('PermissionListComponent', () => {
|
||||
searchQuerySpy.and.returnValue(of(fakeEmptyResponse));
|
||||
component.ngOnInit();
|
||||
|
||||
await fixture.detectChanges();
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE');
|
||||
expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor');
|
||||
@@ -234,7 +254,7 @@ describe('PermissionListComponent', () => {
|
||||
const selectBox = fixture.debugElement.query(By.css(('[id="adf-select-role-permission"] .mat-select-trigger')));
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
const options: any = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
const options = fixture.debugElement.queryAll(By.css('mat-option'));
|
||||
expect(options).not.toBeNull();
|
||||
expect(options.length).toBe(5);
|
||||
options[3].triggerEventHandler('click', {});
|
||||
@@ -246,12 +266,14 @@ describe('PermissionListComponent', () => {
|
||||
spyOn(nodeService, 'updateNode').and.returnValue(of(new MinimalNode({id: 'fake-uwpdated-node'})));
|
||||
searchQuerySpy.and.returnValue(of(fakeEmptyResponse));
|
||||
component.ngOnInit();
|
||||
await fixture.detectChanges();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('adf-user-name-column').textContent).toContain('GROUP_EVERYONE');
|
||||
expect(element.querySelector('#adf-select-role-permission').textContent).toContain('Contributor');
|
||||
|
||||
const deleteButton: HTMLButtonElement = element.querySelector('[data-automation-id="adf-delete-permission-button-GROUP_EVERYONE"]');
|
||||
const deleteButton = element.querySelector<HTMLButtonElement>('[data-automation-id="adf-delete-permission-button-GROUP_EVERYONE"]');
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, TestBed } from '@angular/core/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { NodePermissionService } from './node-permission.service';
|
||||
import { SearchService, NodesApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { Node, PermissionElement } from '@alfresco/js-api';
|
||||
@@ -62,18 +62,14 @@ describe('NodePermissionService', () => {
|
||||
nodeService = TestBed.inject(NodesApiService);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
function returnUpdatedNode(_, nodeBody) {
|
||||
const fakeNode: Node = new Node({});
|
||||
fakeNode.id = 'fake-updated-node';
|
||||
fakeNode.permissions = nodeBody.permissions;
|
||||
return of(fakeNode);
|
||||
function returnUpdatedNode(nodeBody: Node) {
|
||||
return of(new Node({
|
||||
id: 'fake-updated-node',
|
||||
permissions: nodeBody.permissions
|
||||
}));
|
||||
}
|
||||
|
||||
it('should return a list of roles taken from the site groups', async(() => {
|
||||
it('should return a list of roles taken from the site groups', (done) => {
|
||||
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeSiteNodeResponse));
|
||||
spyOn(service, 'getGroupMemberByGroupName').and.returnValue(of(fakeSiteRoles));
|
||||
|
||||
@@ -81,20 +77,22 @@ describe('NodePermissionService', () => {
|
||||
expect(roleArray).not.toBeNull();
|
||||
expect(roleArray.length).toBe(4);
|
||||
expect(roleArray[0]).toBe('SiteCollaborator');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return a list of settable if node has no site', async(() => {
|
||||
it('should return a list of settable if node has no site', (done) => {
|
||||
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeEmptyResponse));
|
||||
|
||||
service.getNodeRoles(fakeNodeWithOnlyLocally).subscribe((roleArray: string[]) => {
|
||||
expect(roleArray).not.toBeNull();
|
||||
expect(roleArray.length).toBe(5);
|
||||
expect(roleArray[0]).toBe('Contributor');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to update a locally set permission role', async(() => {
|
||||
it('should be able to update a locally set permission role', (done) => {
|
||||
const fakeAccessStatus: any = 'DENIED';
|
||||
const fakePermission: PermissionElement = {
|
||||
'authorityId': 'GROUP_EVERYONE',
|
||||
@@ -102,7 +100,7 @@ describe('NodePermissionService', () => {
|
||||
'accessStatus' : fakeAccessStatus
|
||||
};
|
||||
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
|
||||
service.updatePermissionRole(JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally)), fakePermission).subscribe((node: Node) => {
|
||||
expect(node).not.toBeNull();
|
||||
@@ -111,16 +109,17 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet[0].authorityId).toBe(fakePermission.authorityId);
|
||||
expect(node.permissions.locallySet[0].name).toBe(fakePermission.name);
|
||||
expect(node.permissions.locallySet[0].accessStatus).toBe(fakePermission.accessStatus);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to remove a locally set permission', async(() => {
|
||||
const fakePermission: PermissionElement = <PermissionElement> {
|
||||
it('should be able to remove a locally set permission', (done) => {
|
||||
const fakePermission = <PermissionElement> {
|
||||
'authorityId': 'FAKE_PERSON_1',
|
||||
'name': 'Contributor',
|
||||
'accessStatus' : 'ALLOWED'
|
||||
};
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeToRemovePermission));
|
||||
|
||||
service.removePermission(fakeNodeCopy, fakePermission).subscribe((node: Node) => {
|
||||
@@ -129,13 +128,14 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet.length).toBe(2);
|
||||
expect(node.permissions.locallySet[0].authorityId).not.toBe(fakePermission.authorityId);
|
||||
expect(node.permissions.locallySet[1].authorityId).not.toBe(fakePermission.authorityId);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to update locally set permissions on the node by node id', async(() => {
|
||||
it('should be able to update locally set permissions on the node by node id', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
|
||||
service.updateNodePermissions('fake-node-id', fakePermissionElements).subscribe((node: Node) => {
|
||||
expect(node).not.toBeNull();
|
||||
@@ -144,12 +144,13 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet[3].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to update locally permissions on the node', async(() => {
|
||||
it('should be able to update locally permissions on the node', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
|
||||
service.updateLocallySetPermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => {
|
||||
expect(node).not.toBeNull();
|
||||
@@ -158,13 +159,14 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet[3].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to update locally permissions on the node without locally set permissions', async(() => {
|
||||
it('should be able to update locally permissions on the node without locally set permissions', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithoutPermissions));
|
||||
fakeNodeCopy.permissions.locallySet = undefined;
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
service.updateLocallySetPermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => {
|
||||
expect(node).not.toBeNull();
|
||||
expect(node.id).toBe('fake-updated-node');
|
||||
@@ -172,10 +174,11 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet[2].authorityId).not.toBe(fakeAuthorityResults[0].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[1].authorityId).not.toBe(fakeAuthorityResults[1].entry['cm:userName']);
|
||||
expect(node.permissions.locallySet[0].authorityId).not.toBe(fakeAuthorityResults[2].entry['cm:userName']);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fail when user select the same authority and role to add', async(() => {
|
||||
it('should fail when user select the same authority and role to add', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
|
||||
const fakeDuplicateAuthority: PermissionElement [] = [{
|
||||
@@ -185,32 +188,35 @@ describe('NodePermissionService', () => {
|
||||
}];
|
||||
|
||||
service.updateLocallySetPermissions(fakeNodeCopy, fakeDuplicateAuthority)
|
||||
.subscribe(() => {
|
||||
fail('should throw exception');
|
||||
}, (errorMessage) => {
|
||||
expect(errorMessage).not.toBeNull();
|
||||
expect(errorMessage).toBeDefined();
|
||||
expect(errorMessage).toBe('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION');
|
||||
});
|
||||
}));
|
||||
.subscribe(
|
||||
() => { fail('should throw exception'); },
|
||||
(errorMessage) => {
|
||||
expect(errorMessage).not.toBeNull();
|
||||
expect(errorMessage).toBeDefined();
|
||||
expect(errorMessage).toBe('PERMISSION_MANAGER.ERROR.DUPLICATE-PERMISSION');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should be able to remove the locallyset permission', async(() => {
|
||||
it('should be able to remove the locallyset permission', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithoutPermissions));
|
||||
fakeNodeCopy.permissions.locallySet = [...fakePermissionElements];
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
service.removePermissions(fakeNodeCopy, [fakePermissionElements[2]]).subscribe((node: Node) => {
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
service.removePermissions(fakeNodeCopy, [fakePermissionElements[2]]).subscribe((node) => {
|
||||
expect(node).not.toBeNull();
|
||||
expect(node.id).toBe('fake-updated-node');
|
||||
expect(node.permissions.locallySet.length).toBe(2);
|
||||
expect(node.permissions.locallySet[0].authorityId).toBe(fakePermissionElements[0].authorityId);
|
||||
expect(node.permissions.locallySet[1].authorityId).toBe(fakePermissionElements[1].authorityId);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to replace the locally set', async(() => {
|
||||
it('should be able to replace the locally set', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
fakeNodeCopy.permissions.locallySet = [];
|
||||
spyOn(nodeService, 'updateNode').and.callFake((nodeId, permissionBody) => returnUpdatedNode(nodeId, permissionBody));
|
||||
spyOn(nodeService, 'updateNode').and.callFake((_, permissionBody) => returnUpdatedNode(permissionBody));
|
||||
service.updatePermissions(fakeNodeCopy, fakePermissionElements).subscribe((node: Node) => {
|
||||
expect(node).not.toBeNull();
|
||||
expect(node.id).toBe('fake-updated-node');
|
||||
@@ -218,10 +224,11 @@ describe('NodePermissionService', () => {
|
||||
expect(node.permissions.locallySet[0].authorityId).toBe(fakePermissionElements[0].authorityId);
|
||||
expect(node.permissions.locallySet[1].authorityId).toBe(fakePermissionElements[1].authorityId);
|
||||
expect(node.permissions.locallySet[2].authorityId).toBe(fakePermissionElements[2].authorityId);
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to get node and it\'s roles', async(() => {
|
||||
it('should be able to get node and its roles', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy));
|
||||
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(of(fakeSiteNodeResponse));
|
||||
@@ -230,10 +237,11 @@ describe('NodePermissionService', () => {
|
||||
expect(node).toBe(fakeNodeCopy);
|
||||
expect(roles.length).toBe(4);
|
||||
expect(roles[0].role).toBe('SiteCollaborator');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should provide node and default role if search API failed', async(() => {
|
||||
it('should provide node and default role if search API failed', (done) => {
|
||||
const fakeNodeCopy = JSON.parse(JSON.stringify(fakeNodeWithOnlyLocally));
|
||||
spyOn(nodeService, 'getNode').and.returnValue(of(fakeNodeCopy));
|
||||
spyOn(searchApiService, 'searchByQueryBody').and.returnValue(throwError('search service down'));
|
||||
@@ -241,6 +249,7 @@ describe('NodePermissionService', () => {
|
||||
expect(node).toBe(fakeNodeCopy);
|
||||
expect(roles.length).toBe(5);
|
||||
expect(roles[0].role).toBe('Contributor');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Component, DebugElement, ViewChild } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import {
|
||||
AuthenticationService,
|
||||
@@ -90,7 +90,6 @@ describe('SearchControlComponent', () => {
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
function typeWordIntoSearchInput(word: string): void {
|
||||
@@ -151,18 +150,22 @@ describe('SearchControlComponent', () => {
|
||||
|
||||
describe('component rendering', () => {
|
||||
|
||||
it('should display a text input field by default', async(() => {
|
||||
it('should display a text input field by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelectorAll('#adf-control-input').length).toBe(1);
|
||||
expect(element.querySelector('#adf-control-input')).toBeDefined();
|
||||
expect(element.querySelector('#adf-control-input')).not.toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should set browser autocomplete to off by default', async(() => {
|
||||
it('should set browser autocomplete to off by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const attr = element.querySelector('#adf-control-input').getAttribute('autocomplete');
|
||||
expect(attr).toBe('off');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('autocomplete list', () => {
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { SearchDateRangeComponent } from './search-date-range.component';
|
||||
import { MomentDateAdapter, setupTestBed } from '@alfresco/adf-core';
|
||||
import { DateAdapter } from '@angular/material/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@@ -195,11 +195,12 @@ describe('SearchDateRangeComponent', () => {
|
||||
expect(component.getFromValidationMessage()).toEqual('');
|
||||
});
|
||||
|
||||
it('should have no maximum date by default', async(() => {
|
||||
it('should have no maximum date by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(fixture.debugElement.nativeElement.querySelector('input[ng-reflect-max]')).toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to set a fixed maximum date', async () => {
|
||||
component.settings = { field: 'cm:created', dateFormat: dateFormatFixture, maxDate: maxDate };
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { SearchDatetimeRangeComponent } from './search-datetime-range.component';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@@ -45,17 +45,20 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
|
||||
afterEach(() => fixture.destroy());
|
||||
|
||||
it('should setup form elements on init', () => {
|
||||
it('should setup form elements on init', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.from).toBeDefined();
|
||||
expect(component.to).toBeDefined();
|
||||
expect(component.form).toBeDefined();
|
||||
});
|
||||
|
||||
it('should setup form control with formatted valid datetime on change', () => {
|
||||
it('should setup form control with formatted valid datetime on change', async () => {
|
||||
component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture };
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const inputString = '20-feb-18 20:00';
|
||||
const momentFromInput = moment(inputString, datetimeFormatFixture);
|
||||
@@ -67,9 +70,11 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
expect(component.from.value.toString()).toEqual(momentFromInput.toString());
|
||||
});
|
||||
|
||||
it('should NOT setup form control with invalid datetime on change', () => {
|
||||
it('should NOT setup form control with invalid datetime on change', async () => {
|
||||
component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture };
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const inputString = '2017-10-16 20:f:00';
|
||||
const momentFromInput = moment(inputString, datetimeFormatFixture);
|
||||
@@ -81,8 +86,10 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
expect(component.from.value.toString()).not.toEqual(momentFromInput.toString());
|
||||
});
|
||||
|
||||
it('should reset form', () => {
|
||||
it('should reset form', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.form.setValue({ from: fromDatetime, to: toDatetime });
|
||||
|
||||
expect(component.from.value).toEqual(fromDatetime);
|
||||
@@ -95,15 +102,17 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
expect(component.form.value).toEqual({ from: '', to: '' });
|
||||
});
|
||||
|
||||
it('should reset fromMaxDatetime on reset', () => {
|
||||
it('should reset fromMaxDatetime on reset', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.fromMaxDatetime = fromDatetime;
|
||||
component.reset();
|
||||
|
||||
expect(component.fromMaxDatetime).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should update query builder on reset', () => {
|
||||
it('should update query builder on reset', async () => {
|
||||
const context: any = {
|
||||
queryFragments: {
|
||||
createdDatetimeRange: 'query'
|
||||
@@ -118,13 +127,15 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
spyOn(context, 'update').and.stub();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.reset();
|
||||
|
||||
expect(context.queryFragments.createdDatetimeRange).toEqual('');
|
||||
expect(context.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should update the query in UTC format when values change', () => {
|
||||
it('should update the query in UTC format when values change', async () => {
|
||||
const context: any = {
|
||||
queryFragments: {},
|
||||
update() {
|
||||
@@ -138,6 +149,8 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
spyOn(context, 'update').and.stub();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.apply({
|
||||
from: fromDatetime,
|
||||
to: toDatetime
|
||||
@@ -149,7 +162,7 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
expect(context.update).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be able to update the query in UTC format from a GMT format', () => {
|
||||
it('should be able to update the query in UTC format from a GMT format', async () => {
|
||||
const context: any = {
|
||||
queryFragments: {},
|
||||
update() {
|
||||
@@ -165,6 +178,8 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
spyOn(context, 'update').and.stub();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.apply({
|
||||
from: fromInGmt,
|
||||
to: toInGmt
|
||||
@@ -178,6 +193,8 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
|
||||
it('should show datetime-format error when an invalid datetime is set', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.onChangedHandler({ value: '10/14/2020 10:00:00 PM' }, component.from);
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -188,6 +205,8 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
|
||||
it('should not show datetime-format error when valid found', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const input = fixture.debugElement.nativeElement.querySelector('[data-automation-id="datetime-range-from-input"]');
|
||||
input.value = '10/16/2017 9:00 PM';
|
||||
input.dispatchEvent(new Event('input'));
|
||||
@@ -198,15 +217,18 @@ describe('SearchDatetimeRangeComponent', () => {
|
||||
expect(component.getFromValidationMessage()).toEqual('');
|
||||
});
|
||||
|
||||
it('should have no maximum datetime by default', async(() => {
|
||||
it('should have no maximum datetime by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(fixture.debugElement.nativeElement.querySelector('input[ng-reflect-max]')).toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to set a fixed maximum datetime', async () => {
|
||||
component.settings = { field: 'cm:created', datetimeFormat: datetimeFormatFixture, maxDatetime: maxDatetime };
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const inputs = fixture.debugElement.nativeElement.querySelectorAll('input[ng-reflect-max="Tue Mar 10 2020 20:00:00 GMT+0"]');
|
||||
|
||||
|
@@ -22,7 +22,7 @@ import { Subject } from 'rxjs';
|
||||
import { FacetFieldBucket } from '../../models/facet-field-bucket.interface';
|
||||
import { FacetField } from '../../models/facet-field.interface';
|
||||
import { SearchFilterList } from '../../models/search-filter-list.model';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import {
|
||||
@@ -714,74 +714,85 @@ describe('SearchFilterComponent', () => {
|
||||
|
||||
describe('widgets', () => {
|
||||
|
||||
it('should have expandable categories', async(() => {
|
||||
it('should have expandable categories', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
queryBuilder.categories = expandableCategories;
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
await fixture.whenStable();
|
||||
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
}));
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
|
||||
it('should not show the disabled widget', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should not show the disabled widget', async () => {
|
||||
appConfigService.config.search = { categories: disabledCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(0);
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should show the widget in expanded mode', async(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should show the widget in expanded mode', async () => {
|
||||
appConfigService.config.search = { categories: expandedCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
await fixture.whenStable();
|
||||
|
||||
const title = fixture.debugElement.query(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(title.nativeElement.innerText.trim()).toBe('Type');
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(1);
|
||||
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
const title = fixture.debugElement.query(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(title.nativeElement.innerText.trim()).toBe('Type');
|
||||
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
fixture.detectChanges();
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
}));
|
||||
const element: HTMLElement = panels[0].nativeElement;
|
||||
expect(element.classList.contains('mat-expanded')).toBeTruthy();
|
||||
|
||||
it('should show the widgets only if configured', async(() => {
|
||||
(element.childNodes[0] as HTMLElement).click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.classList.contains('mat-expanded')).toEqual(false);
|
||||
});
|
||||
|
||||
it('should show the widgets only if configured', async () => {
|
||||
appConfigService.config.search = { categories: simpleCategories };
|
||||
queryBuilder.resetToDefaults();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(2);
|
||||
await fixture.whenStable();
|
||||
|
||||
const titleElements = fixture.debugElement.queryAll(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(titleElements.map(title => title.nativeElement.innerText.trim())).toEqual(['Name', 'Type']);
|
||||
});
|
||||
}));
|
||||
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(2);
|
||||
|
||||
it('should be update the search query when name changed', async( async () => {
|
||||
const titleElements = fixture.debugElement.queryAll(By.css('.mat-expansion-panel-header-title'));
|
||||
expect(titleElements.map(title => title.nativeElement.innerText.trim())).toEqual(['Name', 'Type']);
|
||||
});
|
||||
|
||||
it('should be update the search query when name changed', async () => {
|
||||
spyOn(queryBuilder, 'update').and.stub();
|
||||
appConfigService.config.search = searchFilter;
|
||||
queryBuilder.resetToDefaults();
|
||||
@@ -800,7 +811,7 @@ describe('SearchFilterComponent', () => {
|
||||
|
||||
panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
|
||||
expect(panels.length).toBe(8);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should add a panel only for the response buckets that are present in the response', async () => {
|
||||
appConfigService.config.search = searchFilter;
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { SearchTextComponent } from './search-text.component';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { ContentTestingModule } from '../../../testing/content.testing.module';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('SearchTextComponent', () => {
|
||||
@@ -97,24 +97,22 @@ describe('SearchTextComponent', () => {
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
|
||||
it('should show the custom/default name', async(() => {
|
||||
it('should show the custom/default name', async () => {
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.value).toEqual('secret.pdf');
|
||||
const input = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix input');
|
||||
expect(input.value).toEqual('secret.pdf');
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
expect(component.value).toEqual('secret.pdf');
|
||||
const input = fixture.debugElement.nativeElement.querySelector('.mat-form-field-infix input');
|
||||
expect(input.value).toEqual('secret.pdf');
|
||||
});
|
||||
|
||||
it('should be able to reset by clicking clear button', async(() => {
|
||||
it('should be able to reset by clicking clear button', async () => {
|
||||
component.context.queryFragments[component.id] = "cm:name:'secret.pdf'";
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const clearElement = fixture.debugElement.nativeElement.querySelector('button');
|
||||
clearElement.click();
|
||||
expect(component.value).toBe('');
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
const clearElement = fixture.debugElement.nativeElement.querySelector('button');
|
||||
clearElement.click();
|
||||
expect(component.value).toBe('');
|
||||
expect(component.context.queryFragments[component.id]).toBe('');
|
||||
});
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DropdownSitesComponent, Relations } from './sites-dropdown.component';
|
||||
import { SitesService, setupTestBed } from '@alfresco/adf-core';
|
||||
@@ -68,36 +68,35 @@ describe('DropdownSitesComponent', () => {
|
||||
|
||||
describe('Infinite Loading', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
siteService = TestBed.inject(SitesService);
|
||||
fixture = TestBed.createComponent(DropdownSitesComponent);
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePaging()));
|
||||
}));
|
||||
});
|
||||
|
||||
it('Should show loading item if there are more itemes', async(() => {
|
||||
it('Should show loading item if there are more itemes', async () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('[data-automation-id="site-loading"]')).toBeDefined();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
it('Should not show loading item if there are more itemes', async(() => {
|
||||
expect(element.querySelector('[data-automation-id="site-loading"]')).toBeDefined();
|
||||
});
|
||||
|
||||
it('Should not show loading item if there are more itemes', async () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('[data-automation-id="site-loading"]')).toBeNull();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('[data-automation-id="site-loading"]')).toBeNull();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Sites', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
siteService = TestBed.inject(SitesService);
|
||||
spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePagingNoMoreItems()));
|
||||
|
||||
@@ -105,108 +104,113 @@ describe('DropdownSitesComponent', () => {
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
}));
|
||||
});
|
||||
|
||||
function openSelectBox() {
|
||||
const selectBox = debug.query(By.css(('[data-automation-id="site-my-files-option"] .mat-select-trigger')));
|
||||
selectBox.triggerEventHandler('click', null);
|
||||
}
|
||||
|
||||
it('Dropdown sites should be rendered', async(() => {
|
||||
it('Dropdown sites should be rendered', async () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#site-dropdown-container')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown-container')).not.toBeNull();
|
||||
expect(element.querySelector('#site-dropdown')).not.toBeNull();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should show the "My files" option by default', async(() => {
|
||||
expect(element.querySelector('#site-dropdown-container')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown-container')).not.toBeNull();
|
||||
expect(element.querySelector('#site-dropdown')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should show the "My files" option by default', async () => {
|
||||
component.hideMyFiles = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[0].nativeElement.innerText).toContain('DROPDOWN.MY_FILES_OPTION');
|
||||
});
|
||||
}));
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
|
||||
it('should hide the "My files" option if the developer desires that way', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[0].nativeElement.innerText).toContain('DROPDOWN.MY_FILES_OPTION');
|
||||
});
|
||||
|
||||
it('should hide the "My files" option if the developer desires that way', async () => {
|
||||
component.hideMyFiles = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[0].nativeElement.innerText).not.toContain('DROPDOWN.MY_FILES_OPTION');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the default placeholder label by default', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[0].nativeElement.innerText).not.toContain('DROPDOWN.MY_FILES_OPTION');
|
||||
});
|
||||
|
||||
it('should show the default placeholder label by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
openSelectBox();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.innerText.trim()).toContain('DROPDOWN.PLACEHOLDER_LABEL');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show custom placeholder label when the \'placeholder\' input property is given a value', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(fixture.nativeElement.innerText.trim()).toContain('DROPDOWN.PLACEHOLDER_LABEL');
|
||||
});
|
||||
|
||||
it('should show custom placeholder label when the "placeholder" input property is given a value', async () => {
|
||||
component.placeholder = 'NODE_SELECTOR.SELECT_LOCATION';
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
openSelectBox();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.innerText.trim()).toContain('NODE_SELECTOR.SELECT_LOCATION');
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should load custom sites when the \'siteList\' input property is given a value', async(() => {
|
||||
expect(fixture.nativeElement.innerText.trim()).toContain('NODE_SELECTOR.SELECT_LOCATION');
|
||||
});
|
||||
|
||||
it('should load custom sites when the "siteList" input property is given a value', async () => {
|
||||
component.siteList = customSiteList;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
openSelectBox();
|
||||
|
||||
let options: any = [];
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
options = debug.queryAll(By.css('mat-option'));
|
||||
options[0].triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
component.change.subscribe(() => {
|
||||
expect(options[0].nativeElement.innerText).toContain('PERSONAL_FILES');
|
||||
expect(options[1].nativeElement.innerText).toContain('FILE_LIBRARIES');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should load sites by default', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[1].nativeElement.innerText).toContain('fake-test-site');
|
||||
expect(options[2].nativeElement.innerText).toContain('fake-test-2');
|
||||
});
|
||||
}));
|
||||
let options = debug.queryAll(By.css('mat-option'));
|
||||
options[0].triggerEventHandler('click', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(options[0].nativeElement.innerText).toContain('PERSONAL_FILES');
|
||||
expect(options[1].nativeElement.innerText).toContain('FILE_LIBRARIES');
|
||||
});
|
||||
|
||||
it('should load sites by default', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const options: any = debug.queryAll(By.css('mat-option'));
|
||||
expect(options[1].nativeElement.innerText).toContain('fake-test-site');
|
||||
expect(options[2].nativeElement.innerText).toContain('fake-test-2');
|
||||
});
|
||||
|
||||
it('should raise an event when a site is selected', (done) => {
|
||||
fixture.detectChanges();
|
||||
@@ -226,26 +230,25 @@ describe('DropdownSitesComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be possible to select the default value', (done) => {
|
||||
it('should be possible to select the default value', async () => {
|
||||
component.value = 'swsdp';
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.selected.entry.title).toBe('fake-test-2');
|
||||
done();
|
||||
});
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(component.selected.entry.title).toBe('fake-test-2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Default value', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
siteService = TestBed.inject(SitesService);
|
||||
spyOn(siteService, 'getSites').and.returnValues(of(getFakeSitePagingFirstPage()), of(getFakeSitePagingLastPage()));
|
||||
|
||||
fixture = TestBed.createComponent(DropdownSitesComponent);
|
||||
component = fixture.componentInstance;
|
||||
}));
|
||||
});
|
||||
|
||||
it('should load new sites if default value is not in the first page', (done) => {
|
||||
component.value = 'fake-test-4';
|
||||
@@ -271,7 +274,7 @@ describe('DropdownSitesComponent', () => {
|
||||
|
||||
describe('Sites with members', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
siteService = TestBed.inject(SitesService);
|
||||
spyOn(siteService, 'getSites').and.returnValue(of(getFakeSitePagingWithMembers()));
|
||||
|
||||
@@ -279,18 +282,17 @@ describe('DropdownSitesComponent', () => {
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(async(() => {
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
TestBed.resetTestingModule();
|
||||
}));
|
||||
});
|
||||
|
||||
describe('No relations', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
component.relations = Relations.Members;
|
||||
}));
|
||||
});
|
||||
|
||||
it('should show only sites which logged user is member of when member relation is set', (done) => {
|
||||
spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test');
|
||||
@@ -312,9 +314,9 @@ describe('DropdownSitesComponent', () => {
|
||||
});
|
||||
|
||||
describe('No relations', () => {
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
component.relations = [];
|
||||
}));
|
||||
});
|
||||
|
||||
it('should show all the sites if no relation is set', (done) => {
|
||||
spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test');
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { LikeComponent } from './like.component';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('Like component', () => {
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(RatingService);
|
||||
|
||||
spyOn(service, 'getRating').and.returnValue(of({
|
||||
@@ -54,17 +54,16 @@ describe('Like component', () => {
|
||||
component.nodeId = 'test-id';
|
||||
component.ngOnChanges();
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should load the likes by default on onChanges', async(() => {
|
||||
it('should load the likes by default on onChanges', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('2');
|
||||
});
|
||||
}));
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('2');
|
||||
});
|
||||
|
||||
it('should increase the number of likes when clicked', async(() => {
|
||||
it('should increase the number of likes when clicked', async () => {
|
||||
spyOn(service, 'postRating').and.returnValue(of({
|
||||
entry: {
|
||||
id: 'likes',
|
||||
@@ -75,13 +74,13 @@ describe('Like component', () => {
|
||||
const likeButton: any = element.querySelector('#adf-like-test-id');
|
||||
likeButton.click();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('3');
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should decrease the number of likes when clicked and is already liked', async(() => {
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('3');
|
||||
});
|
||||
|
||||
it('should decrease the number of likes when clicked and is already liked', async () => {
|
||||
spyOn(service, 'deleteRating').and.returnValue(of(''));
|
||||
|
||||
component.isLike = true;
|
||||
@@ -89,10 +88,9 @@ describe('Like component', () => {
|
||||
const likeButton: any = element.querySelector('#adf-like-test-id');
|
||||
likeButton.click();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('1');
|
||||
});
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
}));
|
||||
expect(element.querySelector('#adf-like-counter').innerHTML).toBe('1');
|
||||
});
|
||||
});
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { TreeViewComponent } from './tree-view.component';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
@@ -76,13 +76,12 @@ describe('TreeViewComponent', () => {
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
ContentTestingModule
|
||||
],
|
||||
declarations: []
|
||||
]
|
||||
});
|
||||
|
||||
describe('When there is a nodeId', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
treeService = TestBed.inject(TreeViewService);
|
||||
fixture = TestBed.createComponent(TreeViewComponent);
|
||||
element = fixture.nativeElement;
|
||||
@@ -92,44 +91,50 @@ describe('TreeViewComponent', () => {
|
||||
const changeNodeId = new SimpleChange(null, '9999999', true);
|
||||
component.ngOnChanges({ 'nodeId': changeNodeId });
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should show the folder', async(() => {
|
||||
expect(element.querySelector('#fake-node-name-tree-child-node')).not.toBeNull();
|
||||
}));
|
||||
it('should show the folder', async () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should show the subfolders when the folder is clicked', async(() => {
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-node-name');
|
||||
expect(element.querySelector('#fake-node-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should show the subfolders when the folder is clicked', async () => {
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-node-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show only the correct subfolders when the nodeId is changed', async(() => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should show only the correct subfolders when the nodeId is changed', async () => {
|
||||
component.nodeId = 'fake-second-id';
|
||||
const changeNodeId = new SimpleChange('9999999', 'fake-second-id', true);
|
||||
component.ngOnChanges({ 'nodeId': changeNodeId });
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-next-child-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelectorAll('mat-tree-node').length).toBe(4);
|
||||
});
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-next-child-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelectorAll('mat-tree-node').length).toBe(4);
|
||||
});
|
||||
|
||||
it('should throw a nodeClicked event when a node is clicked', (done) => {
|
||||
component.nodeClicked.subscribe((nodeClicked: NodeEntry) => {
|
||||
@@ -139,100 +144,105 @@ describe('TreeViewComponent', () => {
|
||||
expect(nodeClicked.entry.id).toBe('fake-node-id');
|
||||
done();
|
||||
});
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-node-name');
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-node-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
});
|
||||
|
||||
it('should change the icon of the opened folders', async(() => {
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-node-name');
|
||||
it('should change the icon of the opened folders', async () => {
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-node-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder');
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder_open');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the subfolders of a subfolder if there are any', async(() => {
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-node-name');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder_open');
|
||||
});
|
||||
|
||||
it('should show the subfolders of a subfolder if there are any', async () => {
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-node-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
const childButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-second-name');
|
||||
expect(childButton).not.toBeNull();
|
||||
childButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-next-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-next-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should hide the subfolders when clicked again', async(() => {
|
||||
const rootFolderButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#button-fake-node-name');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
const childButton = element.querySelector<HTMLButtonElement>('#button-fake-second-name');
|
||||
expect(childButton).not.toBeNull();
|
||||
childButton.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-next-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-next-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should hide the subfolders when clicked again', async () => {
|
||||
const rootFolderButton = element.querySelector<HTMLButtonElement>('#button-fake-node-name');
|
||||
expect(rootFolderButton).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder');
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).toBeNull();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the subfolders when the label is clicked', async(() => {
|
||||
const rootLabel: HTMLButtonElement = <HTMLButtonElement> element.querySelector('.adf-tree-view-label');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
rootFolderButton.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#button-fake-node-name .mat-icon').textContent.trim()).toBe('folder');
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).toBeNull();
|
||||
});
|
||||
|
||||
it('should show the subfolders when the label is clicked', async () => {
|
||||
const rootLabel = element.querySelector<HTMLButtonElement>('.adf-tree-view-label');
|
||||
rootLabel.click();
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(element.querySelector('#fake-child-name-tree-child-node')).not.toBeNull();
|
||||
expect(element.querySelector('#fake-second-name-tree-child-node')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When no nodeId is given', () => {
|
||||
|
||||
let emptyElement: HTMLElement;
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TreeViewComponent);
|
||||
emptyElement = fixture.nativeElement;
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should show an error message when no nodeId is provided', async(() => {
|
||||
it('should show an error message when no nodeId is provided', async () => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(emptyElement.querySelector('#adf-tree-view-missing-node')).toBeDefined();
|
||||
expect(emptyElement.querySelector('#adf-tree-view-missing-node')).not.toBeNull();
|
||||
});
|
||||
}));
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(emptyElement.querySelector('#adf-tree-view-missing-node')).toBeDefined();
|
||||
expect(emptyElement.querySelector('#adf-tree-view-missing-node')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('When invalid nodeId is given', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TreeViewComponent);
|
||||
treeService = TestBed.inject(TreeViewService);
|
||||
spyOn(treeService, 'getTreeNodes').and.callFake(() => throwError('Invalid Node Id'));
|
||||
spyOn(treeService, 'getTreeNodes').and.returnValue(throwError('Invalid Node Id'));
|
||||
fixture.componentInstance.nodeId = 'Poopoovic';
|
||||
}));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { FileModel, UploadService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||
@@ -197,13 +197,13 @@ describe('UploadDragAreaComponent', () => {
|
||||
});
|
||||
|
||||
describe('Upload Files', () => {
|
||||
let addToQueueSpy;
|
||||
let addToQueueSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(async(() => {
|
||||
beforeEach(() => {
|
||||
addToQueueSpy = spyOn(uploadService, 'addToQueue');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should upload the list of files dropped', async(() => {
|
||||
it('should upload the list of files dropped', (done) => {
|
||||
component.success = null;
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||
fixture.detectChanges();
|
||||
@@ -215,12 +215,13 @@ describe('UploadDragAreaComponent', () => {
|
||||
fixture.whenStable().then(() => {
|
||||
addToQueueSpy.and.callFake((f: FileModel) => {
|
||||
expect(f.file).toBe(file);
|
||||
done();
|
||||
});
|
||||
component.onFilesDropped(filesList);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should only upload those files whose fileTypes are in acceptedFilesType', async(() => {
|
||||
it('should only upload those files whose fileTypes are in acceptedFilesType', async () => {
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||
component.success = null;
|
||||
component.error = null;
|
||||
@@ -232,27 +233,28 @@ describe('UploadDragAreaComponent', () => {
|
||||
<File> { name: 'ganymede.bmp' }
|
||||
];
|
||||
component.onFilesDropped(files);
|
||||
fixture.whenStable().then(() => {
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null);
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(2, 'Files should contain two elements');
|
||||
expect(filesCalledWith[0].name).toBe('phobos.jpg');
|
||||
expect(filesCalledWith[1].name).toBe('deimos.pdf');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should upload a file if fileType is in acceptedFilesType', async(() => {
|
||||
await fixture.whenStable();
|
||||
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null);
|
||||
const filesCalledWith = addToQueueSpy.calls.mostRecent().args;
|
||||
expect(filesCalledWith.length).toBe(2, 'Files should contain two elements');
|
||||
expect(filesCalledWith[0].name).toBe('phobos.jpg');
|
||||
expect(filesCalledWith[1].name).toBe('deimos.pdf');
|
||||
});
|
||||
|
||||
it('should upload a file if fileType is in acceptedFilesType', async () => {
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||
component.success = null;
|
||||
component.error = null;
|
||||
component.acceptedFilesType = '.png';
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]);
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]);
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null);
|
||||
});
|
||||
|
||||
it('should NOT upload the file if it is dropped on another file', () => {
|
||||
const fakeItem = {
|
||||
@@ -282,30 +284,34 @@ describe('UploadDragAreaComponent', () => {
|
||||
component.onUploadFiles(fakeCustomEvent);
|
||||
});
|
||||
|
||||
it('should not upload a file if fileType is not in acceptedFilesType', async(() => {
|
||||
it('should not upload a file if fileType is not in acceptedFilesType', async () => {
|
||||
component.success = null;
|
||||
component.error = null;
|
||||
component.acceptedFilesType = '.pdf';
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalledWith(null, null);
|
||||
});
|
||||
}));
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
it('should upload a file with a custom root folder ID when dropped', async(() => {
|
||||
component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]);
|
||||
expect(uploadService.uploadFilesInTheQueue).not.toHaveBeenCalledWith(null, null);
|
||||
});
|
||||
|
||||
it('should upload a file with a custom root folder ID when dropped', async () => {
|
||||
component.success = null;
|
||||
component.error = null;
|
||||
fixture.detectChanges();
|
||||
|
||||
spyOn(uploadService, 'uploadFilesInTheQueue');
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
component.onFilesDropped([new File(['fakefake'], 'file-fake.png', { type: 'image/png' })]);
|
||||
expect(uploadService.uploadFilesInTheQueue).toHaveBeenCalledWith(null, null);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should upload a file when user has create permission on target folder', async(() => {
|
||||
it('should upload a file when user has create permission on target folder', () => {
|
||||
const fakeItem = {
|
||||
fullPath: '/folder-fake/file-fake.png',
|
||||
isDirectory: false,
|
||||
@@ -327,10 +333,9 @@ describe('UploadDragAreaComponent', () => {
|
||||
|
||||
component.onUploadFiles(fakeCustomEvent);
|
||||
expect(uploadService.addToQueue).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should upload a file to a specific target folder when dropped onto one', async(() => {
|
||||
});
|
||||
|
||||
it('should upload a file to a specific target folder when dropped onto one', (done) => {
|
||||
const fakeItem = {
|
||||
fullPath: '/folder-fake/file-fake.png',
|
||||
isDirectory: false,
|
||||
@@ -346,6 +351,7 @@ describe('UploadDragAreaComponent', () => {
|
||||
addToQueueSpy.and.callFake((fileList) => {
|
||||
expect(fileList.name).toBe('file');
|
||||
expect(fileList.options.path).toBe('pippo/');
|
||||
done();
|
||||
});
|
||||
|
||||
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||
@@ -356,10 +362,9 @@ describe('UploadDragAreaComponent', () => {
|
||||
});
|
||||
|
||||
component.onUploadFiles(fakeCustomEvent);
|
||||
}));
|
||||
|
||||
it('should upload a folder to a specific target folder when dropped onto one', async(() => {
|
||||
});
|
||||
|
||||
it('should upload a folder to a specific target folder when dropped onto one', (done) => {
|
||||
const fakeItem = {
|
||||
fullPath: '/folder-fake/file-fake.png',
|
||||
isDirectory: false,
|
||||
@@ -375,6 +380,7 @@ 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', {
|
||||
@@ -385,9 +391,9 @@ describe('UploadDragAreaComponent', () => {
|
||||
});
|
||||
|
||||
component.onUploadFiles(fakeCustomEvent);
|
||||
}));
|
||||
});
|
||||
|
||||
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', fakeAsync((done) => {
|
||||
spyOn(component.updateFileVersion, 'emit');
|
||||
const fakeItem = {
|
||||
fullPath: '/folder-fake/file-fake.png',
|
||||
@@ -404,6 +410,7 @@ describe('UploadDragAreaComponent', () => {
|
||||
addToQueueSpy.and.callFake((fileList) => {
|
||||
expect(fileList.name).toBe('file');
|
||||
expect(fileList.options.path).toBe('/');
|
||||
done();
|
||||
});
|
||||
|
||||
const fakeCustomEvent: CustomEvent = new CustomEvent('CustomEvent', {
|
||||
@@ -414,6 +421,8 @@ describe('UploadDragAreaComponent', () => {
|
||||
});
|
||||
|
||||
component.onUploadFiles(fakeCustomEvent);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(component.updateFileVersion.emit).toHaveBeenCalledWith(fakeCustomEvent);
|
||||
}));
|
||||
});
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { Node, VersionPaging } from '@alfresco/js-api';
|
||||
@@ -80,7 +80,7 @@ describe('VersionManagerComponent', () => {
|
||||
expect(component.viewVersion.emit).toHaveBeenCalledWith('1.0');
|
||||
});
|
||||
|
||||
it('should display comments for versions when not configured otherwise', async(() => {
|
||||
it('should display comments for versions when not configured otherwise', fakeAsync(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
@@ -91,27 +91,26 @@ describe('VersionManagerComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not display comments for versions when configured not to show them', async(() => {
|
||||
it('should not display comments for versions when configured not to show them', async () => {
|
||||
component.showComments = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
const versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
|
||||
const versionCommentEl = fixture.debugElement.query(By.css('.adf-version-list-item-comment'));
|
||||
expect(versionCommentEl).toBeNull();
|
||||
});
|
||||
|
||||
expect(versionCommentEl).toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should emit success event upon successful upload of a new version', async(() => {
|
||||
it('should emit success event upon successful upload of a new version', (done) => {
|
||||
fixture.detectChanges();
|
||||
|
||||
const emittedData = { value: { entry: node }};
|
||||
component.uploadSuccess.subscribe((event) => {
|
||||
expect(event).toBe(node);
|
||||
done();
|
||||
});
|
||||
component.onUploadSuccess(emittedData);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should emit nodeUpdated event upon successful upload of a new version', (done) => {
|
||||
fixture.detectChanges();
|
||||
|
Reference in New Issue
Block a user