mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
clean unit tests core part 2 (#4897)
* promote use setupTestbed * fix context menu unit test * fix sidebar warning unit test * fix spy people widget * fix ISO warning date time widget * fix sidebar spy 404 url * minor karma fix import pdf.js map * restore md * revert extension change
This commit is contained in:
@@ -76,6 +76,7 @@ describe('ContextMenuHolderComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
contextMenuService = TestBed.get(ContextMenuService);
|
contextMenuService = TestBed.get(ContextMenuService);
|
||||||
|
|
||||||
|
component.ngOnDestroy = () => {};
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -80,7 +80,7 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
|
|||||||
this.subscriptions.push(
|
this.subscriptions.push(
|
||||||
this.contextMenuService.show.subscribe((mouseEvent) => this.showMenu(mouseEvent.event, mouseEvent.obj)),
|
this.contextMenuService.show.subscribe((mouseEvent) => this.showMenu(mouseEvent.event, mouseEvent.obj)),
|
||||||
|
|
||||||
this.menuTrigger.onMenuOpen.subscribe(() => {
|
this.menuTrigger.menuOpened.subscribe(() => {
|
||||||
const container = this.overlayContainer.getContainerElement();
|
const container = this.overlayContainer.getContainerElement();
|
||||||
if (container) {
|
if (container) {
|
||||||
this.contextMenuListenerFn = this.renderer.listen(container, 'contextmenu', (contextmenuEvent: Event) => {
|
this.contextMenuListenerFn = this.renderer.listen(container, 'contextmenu', (contextmenuEvent: Event) => {
|
||||||
@@ -90,7 +90,7 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
|
|||||||
this.menuElement = this.getContextMenuElement();
|
this.menuElement = this.getContextMenuElement();
|
||||||
}),
|
}),
|
||||||
|
|
||||||
this.menuTrigger.onMenuClose.subscribe(() => {
|
this.menuTrigger.menuClosed.subscribe(() => {
|
||||||
this.menuElement = null;
|
this.menuElement = null;
|
||||||
if (this.contextMenuListenerFn) {
|
if (this.contextMenuListenerFn) {
|
||||||
this.contextMenuListenerFn();
|
this.contextMenuListenerFn();
|
||||||
|
@@ -53,7 +53,7 @@ describe('ContextMenuService', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should should create a custom overlay', () => {
|
it('should create a custom overlay', () => {
|
||||||
contextMenuOverlayService.open(overlayConfig);
|
contextMenuOverlayService.open(overlayConfig);
|
||||||
|
|
||||||
expect(document.querySelector('.test-panel')).not.toBe(null);
|
expect(document.querySelector('.test-panel')).not.toBe(null);
|
||||||
|
@@ -1,32 +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 { ContextMenuService } from './context-menu.service';
|
|
||||||
|
|
||||||
describe('ContextMenuService', () => {
|
|
||||||
|
|
||||||
let service;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
service = new ContextMenuService();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should setup default show subject', () => {
|
|
||||||
expect(service.show).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
@@ -42,7 +42,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
|
|
||||||
function createFakeImageBlob() {
|
function createFakeImageBlob() {
|
||||||
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||||
return new Blob([data], {type: 'image/png'});
|
return new Blob([data], { type: 'image/png' });
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFakePdfBlob(): Blob {
|
function createFakePdfBlob(): Blob {
|
||||||
@@ -60,7 +60,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
|
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
|
||||||
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
|
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
|
||||||
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
|
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
|
||||||
return new Blob([pdfData], {type: 'application/pdf'});
|
return new Blob([pdfData], { type: 'application/pdf' });
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTestBed({
|
setupTestBed({
|
||||||
@@ -165,7 +165,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
|
|
||||||
const contentId = 1;
|
const contentId = 1;
|
||||||
const change = new SimpleChange(null, contentId, true);
|
const change = new SimpleChange(null, contentId, true);
|
||||||
component.ngOnChanges({'id': change});
|
component.ngOnChanges({ 'id': change });
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -193,7 +193,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
|
|
||||||
const contentId = 1;
|
const contentId = 1;
|
||||||
const change = new SimpleChange(null, contentId, true);
|
const change = new SimpleChange(null, contentId, true);
|
||||||
component.ngOnChanges({'id': change});
|
component.ngOnChanges({ 'id': change });
|
||||||
|
|
||||||
component.contentLoaded.subscribe((res) => {
|
component.contentLoaded.subscribe((res) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -250,6 +250,8 @@ describe('ContentWidgetComponent', () => {
|
|||||||
thumbnailStatus: 'created'
|
thumbnailStatus: 'created'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
component.content.thumbnailUrl = '/alfresco-logo.svg';
|
||||||
|
|
||||||
component.contentClick.subscribe((content) => {
|
component.contentClick.subscribe((content) => {
|
||||||
expect(content.contentBlob).toBe(blob);
|
expect(content.contentBlob).toBe(blob);
|
||||||
expect(content.mimeType).toBe('application/pdf');
|
expect(content.mimeType).toBe('application/pdf');
|
||||||
@@ -284,6 +286,8 @@ describe('ContentWidgetComponent', () => {
|
|||||||
thumbnailStatus: 'created'
|
thumbnailStatus: 'created'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
component.content.thumbnailUrl = '/alfresco-logo.svg';
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const downloadButton: any = element.querySelector('#download');
|
const downloadButton: any = element.querySelector('#download');
|
||||||
downloadButton.click();
|
downloadButton.click();
|
||||||
|
@@ -50,7 +50,7 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setup min value for date picker', () => {
|
it('should setup min value for date picker', () => {
|
||||||
const minValue = '1982-03-13T10:00Z';
|
const minValue = '1982-03-13T10:00:000Z';
|
||||||
widget.field = new FormFieldModel(null, {
|
widget.field = new FormFieldModel(null, {
|
||||||
id: 'date-id',
|
id: 'date-id',
|
||||||
name: 'date-name',
|
name: 'date-name',
|
||||||
@@ -77,7 +77,7 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setup max value for date picker', () => {
|
it('should setup max value for date picker', () => {
|
||||||
const maxValue = '1982-03-13T10:00Z';
|
const maxValue = '1982-03-13T10:00:000Z';
|
||||||
widget.field = new FormFieldModel(null, {
|
widget.field = new FormFieldModel(null, {
|
||||||
maxValue: maxValue
|
maxValue: maxValue
|
||||||
});
|
});
|
||||||
@@ -93,14 +93,14 @@ describe('DateTimeWidgetComponent', () => {
|
|||||||
const field = new FormFieldModel(new FormModel(), {
|
const field = new FormFieldModel(new FormModel(), {
|
||||||
id: 'date-field-id',
|
id: 'date-field-id',
|
||||||
name: 'date-name',
|
name: 'date-name',
|
||||||
value: '9-12-9999 10:00 AM',
|
value: '09-12-9999 10:00 AM',
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
readOnly: 'false'
|
readOnly: 'false'
|
||||||
});
|
});
|
||||||
|
|
||||||
widget.field = field;
|
widget.field = field;
|
||||||
|
|
||||||
widget.onDateChanged({ value: moment('13-03-1982 10:00 AM') });
|
widget.onDateChanged({ value: moment('2008-09-15T15:53:00') });
|
||||||
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
|
expect(widget.onFieldChanged).toHaveBeenCalledWith(field);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -49,8 +49,12 @@ describe('PeopleWidgetComponent', () => {
|
|||||||
formService = TestBed.get(FormService);
|
formService = TestBed.get(FormService);
|
||||||
|
|
||||||
translationService = TestBed.get(TranslateService);
|
translationService = TestBed.get(TranslateService);
|
||||||
spyOn(translationService, 'instant').and.callFake((key) => { return key; });
|
spyOn(translationService, 'instant').and.callFake((key) => {
|
||||||
spyOn(translationService, 'get').and.callFake((key) => { return of(key); });
|
return key;
|
||||||
|
});
|
||||||
|
spyOn(translationService, 'get').and.callFake((key) => {
|
||||||
|
return of(key);
|
||||||
|
});
|
||||||
|
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
widget = fixture.componentInstance;
|
widget = fixture.componentInstance;
|
||||||
@@ -143,7 +147,14 @@ describe('PeopleWidgetComponent', () => {
|
|||||||
expect(widget.groupId).toBe('<id>');
|
expect(widget.groupId).toBe('<id>');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display involved user in task form', async() => {
|
it('should display involved user in task form', async () => {
|
||||||
|
spyOn(formService, 'getWorkflowUsers').and.returnValue(
|
||||||
|
new Observable((observer) => {
|
||||||
|
observer.next(null);
|
||||||
|
observer.complete();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
widget.field.value = new UserProcessModel({
|
widget.field.value = new UserProcessModel({
|
||||||
id: 'people-id',
|
id: 'people-id',
|
||||||
firstName: 'John',
|
firstName: 'John',
|
||||||
@@ -180,8 +191,10 @@ describe('PeopleWidgetComponent', () => {
|
|||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
afterEach(() => {
|
afterAll(() => {
|
||||||
fixture.destroy();
|
if (fixture) {
|
||||||
|
fixture.destroy();
|
||||||
|
}
|
||||||
TestBed.resetTestingModule();
|
TestBed.resetTestingModule();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -243,7 +256,7 @@ describe('PeopleWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should emit peopleSelected if option is valid', async() => {
|
it('should emit peopleSelected if option is valid', async () => {
|
||||||
const selectEmitSpy = spyOn(widget.peopleSelected, 'emit');
|
const selectEmitSpy = spyOn(widget.peopleSelected, 'emit');
|
||||||
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
|
||||||
peopleHTMLElement.focus();
|
peopleHTMLElement.focus();
|
||||||
|
@@ -8,16 +8,21 @@ module.exports = function (config) {
|
|||||||
files: [
|
files: [
|
||||||
{pattern: 'node_modules/core-js/client/core.js', included: true, watched: false},
|
{pattern: 'node_modules/core-js/client/core.js', included: true, watched: false},
|
||||||
{pattern: 'node_modules/tslib/tslib.js', included: true, watched: false},
|
{pattern: 'node_modules/tslib/tslib.js', included: true, watched: false},
|
||||||
|
|
||||||
{pattern: 'node_modules/hammerjs/hammer.min.js', included: true, watched: false},
|
{pattern: 'node_modules/hammerjs/hammer.min.js', included: true, watched: false},
|
||||||
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
|
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
|
||||||
|
|
||||||
// pdf-js
|
// pdf-js
|
||||||
{pattern: 'node_modules/pdfjs-dist/build/pdf.js.map', included: false, watched: false},
|
{pattern: 'node_modules/pdfjs-dist/build/pdf.js.map', included: false, watched: false},
|
||||||
{pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false},
|
{pattern: 'node_modules/pdfjs-dist/build/pdf.js', included: true, watched: false},
|
||||||
|
|
||||||
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false, served: true},
|
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js', included: true, watched: false, served: true},
|
||||||
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js.map', included: false, watched: false},
|
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.js.map', included: false, watched: false},
|
||||||
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.min.js', included: true, watched: false, served: true},
|
{pattern: 'node_modules/pdfjs-dist/build/pdf.worker.min.js', included: true, watched: false, served: true},
|
||||||
|
|
||||||
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false},
|
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js', included: true, watched: false},
|
||||||
|
{pattern: 'node_modules/pdfjs-dist/web/pdf_viewer.js.map', served: true, included: false, watched: false},
|
||||||
|
|
||||||
{
|
{
|
||||||
pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css',
|
pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css',
|
||||||
included: true,
|
included: true,
|
||||||
@@ -47,6 +52,7 @@ module.exports = function (config) {
|
|||||||
'/pdf.worker.min.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.min.js',
|
'/pdf.worker.min.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.min.js',
|
||||||
'/pdf.worker.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
|
'/pdf.worker.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
|
||||||
'/fake-url-file.png' :'/base/lib/core/assets/images/logo.png',
|
'/fake-url-file.png' :'/base/lib/core/assets/images/logo.png',
|
||||||
|
'/logo.png' :'/base/lib/core/assets/images/logo.png',
|
||||||
'/alfresco-logo.svg' :'/base/lib/core/assets/images/alfresco-logo.svg',
|
'/alfresco-logo.svg' :'/base/lib/core/assets/images/alfresco-logo.svg',
|
||||||
'/assets/images/': '/base/lib/core/assets/images/',
|
'/assets/images/': '/base/lib/core/assets/images/',
|
||||||
'/assets/images/ecm-background.png': '/base/lib/core/assets/images/ecm-background.png',
|
'/assets/images/ecm-background.png': '/base/lib/core/assets/images/ecm-background.png',
|
||||||
|
@@ -21,6 +21,7 @@ import { MaterialModule } from '../../../material.module';
|
|||||||
import { SidebarActionMenuComponent } from './sidebar-action-menu.component';
|
import { SidebarActionMenuComponent } from './sidebar-action-menu.component';
|
||||||
import { setupTestBed } from '../../../testing/setupTestBed';
|
import { setupTestBed } from '../../../testing/setupTestBed';
|
||||||
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
import { CoreTestingModule } from '../../../testing/core.testing.module';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
|
||||||
describe('SidebarActionMenuComponent', () => {
|
describe('SidebarActionMenuComponent', () => {
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
@@ -91,7 +92,8 @@ describe('Custom SidebarActionMenuComponent', () => {
|
|||||||
CustomSidebarActionMenuComponent
|
CustomSidebarActionMenuComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
MaterialModule
|
MaterialModule,
|
||||||
|
NoopAnimationsModule
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user