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

@@ -42,7 +42,7 @@ describe('ContentWidgetComponent', () => {
function createFakeImageBlob() {
const data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
return new Blob([data], {type: 'image/png'});
return new Blob([data], { type: 'image/png' });
}
function createFakePdfBlob(): Blob {
@@ -60,7 +60,7 @@ describe('ContentWidgetComponent', () => {
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
return new Blob([pdfData], {type: 'application/pdf'});
return new Blob([pdfData], { type: 'application/pdf' });
}
setupTestBed({
@@ -165,7 +165,7 @@ describe('ContentWidgetComponent', () => {
const contentId = 1;
const change = new SimpleChange(null, contentId, true);
component.ngOnChanges({'id': change});
component.ngOnChanges({ 'id': change });
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
@@ -193,7 +193,7 @@ describe('ContentWidgetComponent', () => {
const contentId = 1;
const change = new SimpleChange(null, contentId, true);
component.ngOnChanges({'id': change});
component.ngOnChanges({ 'id': change });
component.contentLoaded.subscribe((res) => {
fixture.detectChanges();
@@ -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;
@@ -143,7 +147,14 @@ describe('PeopleWidgetComponent', () => {
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({
id: 'people-id',
firstName: 'John',
@@ -180,8 +191,10 @@ describe('PeopleWidgetComponent', () => {
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
afterAll(() => {
if (fixture) {
fixture.destroy();
}
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 peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
peopleHTMLElement.focus();