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:
Eugenio Romano
2019-07-03 22:42:00 +01:00
committed by GitHub
parent c9b7722bd0
commit 085e1a9dfa
9 changed files with 44 additions and 50 deletions

View File

@@ -76,6 +76,7 @@ describe('ContextMenuHolderComponent', () => {
component = fixture.componentInstance;
contextMenuService = TestBed.get(ContextMenuService);
component.ngOnDestroy = () => {};
fixture.detectChanges();
});

View File

@@ -80,7 +80,7 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
this.subscriptions.push(
this.contextMenuService.show.subscribe((mouseEvent) => this.showMenu(mouseEvent.event, mouseEvent.obj)),
this.menuTrigger.onMenuOpen.subscribe(() => {
this.menuTrigger.menuOpened.subscribe(() => {
const container = this.overlayContainer.getContainerElement();
if (container) {
this.contextMenuListenerFn = this.renderer.listen(container, 'contextmenu', (contextmenuEvent: Event) => {
@@ -90,7 +90,7 @@ export class ContextMenuHolderComponent implements OnInit, OnDestroy {
this.menuElement = this.getContextMenuElement();
}),
this.menuTrigger.onMenuClose.subscribe(() => {
this.menuTrigger.menuClosed.subscribe(() => {
this.menuElement = null;
if (this.contextMenuListenerFn) {
this.contextMenuListenerFn();

View File

@@ -53,7 +53,7 @@ describe('ContextMenuService', () => {
);
});
it('should should create a custom overlay', () => {
it('should create a custom overlay', () => {
contextMenuOverlayService.open(overlayConfig);
expect(document.querySelector('.test-panel')).not.toBe(null);

View File

@@ -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();
});
});

View File

@@ -250,6 +250,8 @@ describe('ContentWidgetComponent', () => {
thumbnailStatus: 'created'
});
component.content.thumbnailUrl = '/alfresco-logo.svg';
component.contentClick.subscribe((content) => {
expect(content.contentBlob).toBe(blob);
expect(content.mimeType).toBe('application/pdf');
@@ -284,6 +286,8 @@ describe('ContentWidgetComponent', () => {
thumbnailStatus: 'created'
});
component.content.thumbnailUrl = '/alfresco-logo.svg';
fixture.detectChanges();
const downloadButton: any = element.querySelector('#download');
downloadButton.click();

View File

@@ -50,7 +50,7 @@ describe('DateTimeWidgetComponent', () => {
});
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, {
id: 'date-id',
name: 'date-name',
@@ -77,7 +77,7 @@ describe('DateTimeWidgetComponent', () => {
});
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, {
maxValue: maxValue
});
@@ -93,14 +93,14 @@ describe('DateTimeWidgetComponent', () => {
const field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '9-12-9999 10:00 AM',
value: '09-12-9999 10:00 AM',
type: 'datetime',
readOnly: 'false'
});
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);
});

View File

@@ -49,8 +49,12 @@ describe('PeopleWidgetComponent', () => {
formService = TestBed.get(FormService);
translationService = TestBed.get(TranslateService);
spyOn(translationService, 'instant').and.callFake((key) => { return key; });
spyOn(translationService, 'get').and.callFake((key) => { return of(key); });
spyOn(translationService, 'instant').and.callFake((key) => {
return key;
});
spyOn(translationService, 'get').and.callFake((key) => {
return of(key);
});
element = fixture.nativeElement;
widget = fixture.componentInstance;
@@ -144,6 +148,13 @@ describe('PeopleWidgetComponent', () => {
});
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({
id: 'people-id',
firstName: 'John',
@@ -180,8 +191,10 @@ describe('PeopleWidgetComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
afterAll(() => {
if (fixture) {
fixture.destroy();
}
TestBed.resetTestingModule();
});

View File

@@ -8,16 +8,21 @@ module.exports = function (config) {
files: [
{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/hammerjs/hammer.min.js', included: true, watched: false},
{pattern: 'node_modules/hammerjs/hammer.min.js.map', included: false, watched: false},
// pdf-js
{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.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.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.map', served: true, included: false, watched: false},
{
pattern: 'node_modules/@angular/material/prebuilt-themes/indigo-pink.css',
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.js' :'/base/node_modules/pdfjs-dist/build/pdf.worker.js',
'/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',
'/assets/images/': '/base/lib/core/assets/images/',
'/assets/images/ecm-background.png': '/base/lib/core/assets/images/ecm-background.png',

View File

@@ -21,6 +21,7 @@ import { MaterialModule } from '../../../material.module';
import { SidebarActionMenuComponent } from './sidebar-action-menu.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('SidebarActionMenuComponent', () => {
let element: HTMLElement;
@@ -91,7 +92,8 @@ describe('Custom SidebarActionMenuComponent', () => {
CustomSidebarActionMenuComponent
],
imports: [
MaterialModule
MaterialModule,
NoopAnimationsModule
]
});