[AAE-1883] document list preset unit tests (#5519)

* document list preset unit tests

* remove useless tests

* remove useless tests

* remove even more garbage

* remove junk
This commit is contained in:
Denys Vuika
2020-02-28 13:26:01 +00:00
committed by GitHub
parent b5d443f2a8
commit a9b49a1eb7
41 changed files with 127 additions and 664 deletions

View File

@@ -1,69 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { DataColumn, setupTestBed, LogService } from '@alfresco/adf-core';
import { DocumentListComponent } from './../document-list.component';
import { ContentColumnListComponent } from './content-column-list.component';
import { ContentTestingModule } from '../../../testing/content.testing.module';
describe('ContentColumnList', () => {
let documentList: DocumentListComponent;
let columnList: ContentColumnListComponent;
let logService: LogService;
setupTestBed({
imports: [ContentTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(() => {
documentList = (TestBed.createComponent(DocumentListComponent).componentInstance as DocumentListComponent);
logService = TestBed.get(LogService);
columnList = new ContentColumnListComponent(documentList, logService);
documentList.ngOnInit();
});
it('should register column within parent document list', () => {
const columns = documentList.data.getColumns();
expect(columns.length).toBe(0);
const column = <DataColumn> {};
const result = columnList.registerColumn(column);
expect(result).toBeTruthy();
expect(columns.length).toBe(1);
expect(columns[0]).toBe(column);
});
it('should require document list instance to register action', () => {
columnList = new ContentColumnListComponent(null, logService);
const col = <DataColumn> {};
expect(columnList.registerColumn(col)).toBeFalsy();
});
it('should require action instance to register', () => {
spyOn(documentList.actions, 'push').and.callThrough();
const result = columnList.registerColumn(null);
expect(result).toBeFalsy();
expect(documentList.actions.push).not.toHaveBeenCalled();
});
});

View File

@@ -1,47 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* tslint:disable:component-selector */
import { DataColumn, LogService } from '@alfresco/adf-core';
import { Component } from '@angular/core';
import { DocumentListComponent } from './../document-list.component';
@Component({
selector: 'content-columns',
template: ''
})
export class ContentColumnListComponent {
constructor(private documentList: DocumentListComponent, private logService: LogService ) {
this.logService.log('ContentColumnListComponent is deprecated starting with 1.7.0 and may be removed in future versions. Use DataColumnListComponent instead.');
}
/**
* Registers column model within the parent document list component.
* @param column Column definition model to register.
*/
registerColumn(column: DataColumn): boolean {
if (this.documentList && column) {
const columns = this.documentList.data.getColumns();
columns.push(column);
return true;
}
return false;
}
}

View File

@@ -1,81 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { LogService, setupTestBed } from '@alfresco/adf-core';
import { DocumentListComponent } from './../document-list.component';
import { ContentColumnListComponent } from './content-column-list.component';
import { ContentColumnComponent } from './content-column.component';
import { ContentTestingModule } from '../../../testing/content.testing.module';
describe('ContentColumn', () => {
let documentList: DocumentListComponent;
let columnList: ContentColumnListComponent;
let logService: LogService;
setupTestBed({
imports: [ContentTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(() => {
documentList = (TestBed.createComponent(DocumentListComponent).componentInstance as DocumentListComponent);
logService = TestBed.get(LogService);
columnList = new ContentColumnListComponent(documentList, logService);
documentList.ngOnInit();
});
it('should register model within parent column list', () => {
spyOn(columnList, 'registerColumn').and.callThrough();
const column = new ContentColumnComponent(columnList, logService);
column.ngAfterContentInit();
expect(columnList.registerColumn).toHaveBeenCalled();
const columns = documentList.data.getColumns();
expect(columns.length).toBe(1);
expect(columns[0]).toBe(column);
});
it('should setup screen reader title for thumbnail column', () => {
const column = new ContentColumnComponent(columnList, logService);
column.key = '$thumbnail';
column.ngOnInit();
expect(column.srTitle).toBe('Thumbnail');
});
it('should register on init', () => {
const column = new ContentColumnComponent(columnList, logService);
spyOn(column, 'register').and.callThrough();
column.ngAfterContentInit();
expect(column.register).toHaveBeenCalled();
});
it('should require action list to register action with', () => {
let column = new ContentColumnComponent(columnList, logService);
expect(column.register()).toBeTruthy();
column = new ContentColumnComponent(null, logService);
expect(column.register()).toBeFalsy();
});
});

View File

@@ -1,77 +0,0 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* tslint:disable:component-selector no-input-rename */
import { DataColumn, DataColumnType, LogService } from '@alfresco/adf-core';
import { AfterContentInit, Component, ContentChild, Input, OnInit, TemplateRef } from '@angular/core';
import { ContentColumnListComponent } from './content-column-list.component';
@Component({
selector: 'content-column',
template: ''
})
export class ContentColumnComponent implements OnInit, AfterContentInit, DataColumn {
@Input()
key: string;
@Input()
type: DataColumnType = 'text';
@Input()
format: string;
@Input()
sortable: boolean = false;
@Input()
title: string = '';
@ContentChild(TemplateRef)
template: any;
/**
* Title to be used for screen readers.
*/
@Input('sr-title')
srTitle: string;
@Input('class')
cssClass: string;
constructor(private list: ContentColumnListComponent, private logService: LogService) {
this.logService.log('ContentColumnComponent is deprecated starting with 1.7.0 and may be removed in future versions. Use DataColumnComponent instead.');
}
ngOnInit() {
if (!this.srTitle && this.key === '$thumbnail') {
this.srTitle = 'Thumbnail';
}
}
ngAfterContentInit() {
this.register();
}
register(): boolean {
if (this.list) {
return this.list.registerColumn(this);
}
return false;
}
}

View File

@@ -104,6 +104,123 @@ describe('DocumentList', () => {
fixture.destroy();
});
describe('presets', () => {
const validatePreset = (keys: string[]) => {
const columns = documentList.data.getColumns();
expect(columns.length).toBe(keys.length);
keys.forEach((key, index) => {
expect(columns[index].key).toBe(key);
});
};
it('should load -trashcan- preset', async () => {
documentList.currentFolderId = '-trashcan-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'name',
'path',
'content.sizeInBytes',
'archivedAt',
'archivedByUser.displayName'
]);
});
it('should load -sites- preset', async () => {
documentList.currentFolderId = '-sites-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'title',
'visibility'
]);
});
it('shuld load -mysites- preset', async () => {
documentList.currentFolderId = '-mysites-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'title',
'visibility'
]);
});
it('should load -favorites- preset', async () => {
documentList.currentFolderId = '-favorites-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'name',
'path',
'content.sizeInBytes',
'modifiedAt',
'modifiedByUser.displayName'
]);
});
it('should load -recent- preset', async () => {
documentList.currentFolderId = '-recent-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'name',
'path',
'content.sizeInBytes',
'modifiedAt'
]);
});
it('should load -sharedlinks- preset', async () => {
documentList.currentFolderId = '-sharedlinks-';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'name',
'path',
'content.sizeInBytes',
'modifiedAt',
'modifiedByUser.displayName',
'sharedByUser.displayName'
]);
});
it('should load default preset', async () => {
documentList.currentFolderId = 'f5dacdb9-6d07-4fe9-9f2a-dedc21bae603';
fixture.detectChanges();
await fixture.whenStable();
validatePreset([
'$thumbnail',
'name',
'content.sizeInBytes',
'modifiedAt',
'modifiedByUser.displayName'
]);
});
});
it('should update schema if columns change', fakeAsync(() => {
documentList.columnList = new DataColumnListComponent();
documentList.columnList.columns = new QueryList<DataColumnComponent>();

View File

@@ -25,8 +25,6 @@ import { UploadModule } from '../upload/upload.module';
import { ContentActionListComponent } from './components/content-action/content-action-list.component';
import { ContentActionComponent } from './components/content-action/content-action.component';
import { ContentColumnListComponent } from './components/content-column/content-column-list.component';
import { ContentColumnComponent } from './components/content-column/content-column.component';
import { DocumentListComponent } from './components/document-list.component';
import { TrashcanNameColumnComponent } from './components/trashcan-name-column/trashcan-name-column.component';
@@ -46,25 +44,21 @@ import { NameColumnComponent } from './components/name-column/name-column.compon
],
declarations: [
DocumentListComponent,
ContentColumnComponent,
TrashcanNameColumnComponent,
LibraryStatusColumnComponent,
LibraryRoleColumnComponent,
LibraryNameColumnComponent,
NameColumnComponent,
ContentColumnListComponent,
ContentActionComponent,
ContentActionListComponent
],
exports: [
DocumentListComponent,
ContentColumnComponent,
TrashcanNameColumnComponent,
LibraryStatusColumnComponent,
LibraryRoleColumnComponent,
LibraryNameColumnComponent,
NameColumnComponent,
ContentColumnListComponent,
ContentActionComponent,
ContentActionListComponent
],

View File

@@ -17,8 +17,6 @@
export * from './components/document-list.component';
export * from './components/node.event';
export * from './components/content-column/content-column.component';
export * from './components/content-column/content-column-list.component';
export * from './components/content-action/content-action.component';
export * from './components/content-action/content-action-list.component';
export * from './components/library-name-column/library-name-column.component';

View File

@@ -60,10 +60,6 @@ describe('NodeActionsService', () => {
contentDialogService = TestBed.get(ContentNodeDialogService);
});
it('should be able to create the service', () => {
expect(service).not.toBeNull();
});
it('should be able to copy content', async(() => {
spyOn(documentListService, 'copyNode').and.returnValue(of('FAKE-OK'));
spyOn(contentDialogService, 'openCopyMoveDialog').and.returnValue(of([fakeNode]));

View File

@@ -54,10 +54,6 @@ describe('NodePermissionDialogService', () => {
});
});
it('should be able to create the service', () => {
expect(service).not.toBeNull();
});
describe('when node has permission to update permissions', () => {
let fakePermissionNode = new Node({});