[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:
Denys Vuika
2021-06-15 16:16:15 +01:00
committed by GitHub
parent ba03c60adb
commit 3079aa48c3
121 changed files with 5316 additions and 4780 deletions

View File

@@ -16,7 +16,7 @@
*/
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { async, TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { AppConfigService } from './app-config.service';
import { AppConfigModule } from './app-config.module';
import { ExtensionConfig, ExtensionService } from '@alfresco/adf-extensions';
@@ -111,14 +111,14 @@ describe('AppConfigService', () => {
done();
});
it('should stream only the selected attribute changes when using select', async(() => {
it('should stream only the selected attribute changes when using select', fakeAsync(() => {
appConfigService.config.testProp = true;
appConfigService.select('testProp').subscribe((property) => {
expect(property).toBeTruthy();
});
}));
it('should stream the page size value when is set', async(() => {
it('should stream the page size value when is set', fakeAsync(() => {
appConfigService.config.testProp = true;
appConfigService.onLoad.subscribe((config) => {
expect(config.testProp).toBeTruthy();

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, async } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MaterialModule } from '../material.module';
import { CoreTestingModule } from '../testing/core.testing.module';
import { setupTestBed } from '../testing/setup-test-bed';
@@ -55,7 +55,7 @@ describe('ButtonsMenuComponent', () => {
describe('When Buttons are injected', () => {
let fixture;
let fixture: ComponentFixture<CustomContainerComponent>;
let component: CustomContainerComponent;
let element: HTMLElement;
@@ -81,31 +81,34 @@ describe('ButtonsMenuComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should render buttons menu when at least one button is declared', async(() => {
it('should render buttons menu when at least one button is declared', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const buttonsMenuElement = element.querySelector('#adf-buttons-menu');
expect(buttonsMenuElement).toBeDefined();
});
}));
await fixture.whenStable();
it('should trigger event when a specific button is clicked', async(() => {
const buttonsMenuElement = element.querySelector('#adf-buttons-menu');
expect(buttonsMenuElement).toBeDefined();
});
it('should trigger event when a specific button is clicked', async () => {
expect(component.value).toBeUndefined();
fixture.detectChanges();
await fixture.whenStable();
const button = element.querySelector('button');
button.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(component.value).toBe(1);
});
}));
await fixture.whenStable();
expect(component.value).toBe(1);
});
});
describe('When no buttons are injected', () => {
let fixture;
let fixture: ComponentFixture<CustomEmptyContainerComponent>;
let element: HTMLElement;
setupTestBed({
@@ -132,12 +135,12 @@ describe('ButtonsMenuComponent', () => {
TestBed.resetTestingModule();
});
it('should hide buttons menu if buttons input is empty', async(() => {
it('should hide buttons menu if buttons input is empty', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const buttonsMenuElement = element.querySelector('#adf-buttons-menu');
expect(buttonsMenuElement).toBeNull();
});
}));
await fixture.whenStable();
const buttonsMenuElement = element.querySelector('#adf-buttons-menu');
expect(buttonsMenuElement).toBeNull();
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { MatCheckbox, MatCheckboxChange } from '@angular/material/checkbox';
import { setupTestBed } from '../../../testing/setup-test-bed';
@@ -68,7 +68,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value).not.toBeNull();
});
it('should NOT render the label and value if the property is NOT editable and doesn\'t have a proper boolean value set', () => {
it('should NOT render the label and value if the property is NOT editable and has no proper boolean value set', () => {
component.editable = true;
component.property.value = undefined;
component.property.editable = false;
@@ -189,15 +189,16 @@ describe('CardViewBoolItemComponent', () => {
expect(cardViewUpdateService.update).toHaveBeenCalledWith(property, true);
});
it('should update the property value after a changed', async(() => {
it('should update the property value after a changed', async () => {
component.property.value = true;
component.changed(<MatCheckboxChange> { checked: false });
fixture.whenStable().then(() => {
expect(component.property.value).toBe(false);
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(component.property.value).toBe(false);
});
it('should trigger an update event on the CardViewUpdateService [integration]', (done) => {
const cardViewUpdateService = TestBed.inject(CardViewUpdateService);

View File

@@ -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 { By } from '@angular/platform-browser';
import { setupTestBed } from '../../../testing/setup-test-bed';
import moment from 'moment-es6';
@@ -209,7 +209,7 @@ describe('CardViewDateItemComponent', () => {
component.onDateChanged({ value: expectedDate });
});
it('should update the property value after a successful update attempt', async(() => {
it('should update the property value after a successful update attempt', fakeAsync(() => {
component.editable = true;
component.property.editable = true;
component.property.value = null;
@@ -271,7 +271,7 @@ describe('CardViewDateItemComponent', () => {
expect(datePickerClearToggle).toBeNull('Clean Icon should not be in DOM');
});
it('should remove the property value after a successful clear attempt', async(() => {
it('should remove the property value after a successful clear attempt', fakeAsync(() => {
component.editable = true;
component.property.editable = true;
component.property.value = 'Jul 10 2017';
@@ -286,7 +286,7 @@ describe('CardViewDateItemComponent', () => {
);
}));
it('should remove the property default value after a successful clear attempt', async(() => {
it('should remove the property default value after a successful clear attempt', fakeAsync(() => {
component.editable = true;
component.property.editable = true;
component.property.default = 'Jul 10 2017';
@@ -301,7 +301,7 @@ describe('CardViewDateItemComponent', () => {
);
}));
it('should remove actual and default value after a successful clear attempt', async(() => {
it('should remove actual and default value after a successful clear attempt', fakeAsync(() => {
component.editable = true;
component.property.editable = true;
component.property.default = 'Jul 10 2017';

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { CardViewKeyValuePairsItemModel } from '../../models/card-view-keyvaluepairs.model';
import { CardViewKeyValuePairsItemComponent } from './card-view-keyvaluepairsitem.component';
@@ -28,7 +28,7 @@ describe('CardViewKeyValuePairsItemComponent', () => {
let fixture: ComponentFixture<CardViewKeyValuePairsItemComponent>;
let component: CardViewKeyValuePairsItemComponent;
let cardViewUpdateService;
let cardViewUpdateService: CardViewUpdateService;
const mockEmptyData = [{ name: '', value: '' }];
const mockData = [{ name: 'test-name', value: 'test-value' }];
@@ -125,7 +125,7 @@ describe('CardViewKeyValuePairsItemComponent', () => {
expect(component.property.value.length).toBe(0);
});
it('should update property on input blur', async(() => {
it('should update property on input blur', fakeAsync(() => {
spyOn(cardViewUpdateService, 'update');
component.ngOnChanges();
fixture.detectChanges();
@@ -153,7 +153,7 @@ describe('CardViewKeyValuePairsItemComponent', () => {
});
}));
it('should not update property if at least one input is empty on blur', async(() => {
it('should not update property if at least one input is empty on blur', fakeAsync(() => {
spyOn(cardViewUpdateService, 'update');
component.ngOnChanges();
fixture.detectChanges();

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed } from '../../../../testing/setup-test-bed';
import { CoreTestingModule } from '../../../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
@@ -46,29 +46,33 @@ describe('SelectFilterInputComponent', () => {
fixture.detectChanges();
});
it('should focus input on initialization', async(() => {
it('should focus input on initialization', async () => {
spyOn(component.selectFilterInput.nativeElement, 'focus');
matSelect.openedChange.next(true);
fixture.detectChanges();
await fixture.whenStable();
expect(component.selectFilterInput.nativeElement.focus).toHaveBeenCalled();
}));
});
it('should clear search term on close', async(() => {
it('should clear search term on close', async () => {
component.onModelChange('some-search-term');
expect(component.term).toBe('some-search-term');
matSelect.openedChange.next(false);
fixture.detectChanges();
expect(component.term).toBe('');
}));
await fixture.whenStable();
it('should emit event when value changes', async(() => {
expect(component.term).toBe('');
});
it('should emit event when value changes', async () => {
spyOn(component.change, 'next');
component.onModelChange('some-search-term');
expect(component.change.next).toHaveBeenCalledWith('some-search-term');
}));
});
it('should reset value on reset() event', () => {
component.onModelChange('some-search-term');

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { setupTestBed } from '../../../testing/setup-test-bed';
import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
@@ -45,21 +45,20 @@ describe('CardViewComponent', () => {
fixture.destroy();
});
it('should render the label and value', async(() => {
it('should render the label and value', async () => {
component.properties = [new CardViewTextItemModel({ label: 'My label', value: 'My value', key: 'some key' })];
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
await fixture.whenStable();
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My label');
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My label');
const value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('My value');
});
}));
const value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('My value');
});
it('should pass through editable property to the items', () => {
component.editable = true;
@@ -76,28 +75,27 @@ describe('CardViewComponent', () => {
expect(datePicker).not.toBeNull('Datepicker should be in DOM');
});
it('should render the date in the correct format', async(() => {
it('should render the date in the correct format', async () => {
component.properties = [new CardViewDateItemModel({
label: 'My date label',
value: '2017-06-14',
key: 'some key',
format: 'short'
})];
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
await fixture.whenStable();
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My date label');
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My date label');
const value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
expect(value.nativeElement.innerText).toBe('6/14/17, 12:00 AM');
});
}));
const value = fixture.debugElement.query(By.css('.adf-property-value'));
expect(value).not.toBeNull();
expect(value.nativeElement.innerText).toBe('6/14/17, 12:00 AM');
});
it('should render the default value if the value is empty, not editable and displayEmpty is true', async(() => {
it('should render the default value if the value is empty, not editable and displayEmpty is true', async () => {
component.properties = [new CardViewTextItemModel({
label: 'My default label',
value: null,
@@ -107,22 +105,20 @@ describe('CardViewComponent', () => {
})];
component.editable = true;
component.displayEmpty = true;
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My default label');
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My default label');
const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('default value');
});
const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('default value');
});
}));
it('should render the default value if the value is empty and is editable', async(() => {
it('should render the default value if the value is empty and is editable', async () => {
component.properties = [new CardViewTextItemModel({
label: 'My default label',
value: null,
@@ -132,18 +128,16 @@ describe('CardViewComponent', () => {
})];
component.editable = true;
component.displayEmpty = false;
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My default label');
const labelValue = fixture.debugElement.query(By.css('.adf-property-label'));
expect(labelValue).not.toBeNull();
expect(labelValue.nativeElement.innerText).toBe('My default label');
const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('default value');
});
}));
const value = fixture.debugElement.query(By.css('[data-automation-id="card-textitem-value-some-key"]'));
expect(value).not.toBeNull();
expect(value.nativeElement.value).toBe('default value');
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async } from '@angular/core/testing';
import { fakeAsync } from '@angular/core/testing';
import { CardViewSelectItemModel } from './card-view-selectitem.model';
import { CardViewSelectItemProperties } from '../interfaces/card-view.interfaces';
import { of } from 'rxjs';
@@ -35,7 +35,7 @@ describe('CardViewSelectItemModel', () => {
});
describe('displayValue', () => {
it('should return the value if it is present', async(() => {
it('should return the value if it is present', fakeAsync(() => {
const itemModel = new CardViewSelectItemModel(properties);
itemModel.displayValue.subscribe((value) => {

View File

@@ -16,7 +16,7 @@
*/
import { MinimalNode } from '@alfresco/js-api';
import { async, TestBed } from '@angular/core/testing';
import { fakeAsync, TestBed } from '@angular/core/testing';
import { CardViewBaseItemModel } from '../models/card-view-baseitem.model';
import { CardViewUpdateService, transformKeyToObject } from './card-view-update.service';
@@ -63,7 +63,7 @@ describe('CardViewUpdateService', () => {
cardViewUpdateService = TestBed.inject(CardViewUpdateService);
});
it('should send updated message with proper parameters', async(() => {
it('should send updated message with proper parameters', fakeAsync(() => {
cardViewUpdateService.itemUpdated$.subscribe(
( { target, changed } ) => {
@@ -74,7 +74,7 @@ describe('CardViewUpdateService', () => {
cardViewUpdateService.update(property, 'changed-property-value');
}));
it('should send clicked message with proper parameters', async(() => {
it('should send clicked message with proper parameters', fakeAsync(() => {
cardViewUpdateService.itemClicked$.subscribe(
( { target } ) => {
@@ -84,7 +84,7 @@ describe('CardViewUpdateService', () => {
cardViewUpdateService.clicked(property);
}));
it('should send updated node when aspect changed', async(() => {
it('should send updated node when aspect changed', fakeAsync(() => {
const fakeNode: MinimalNode = <MinimalNode> { id: 'Bigfoot'};
cardViewUpdateService.updatedAspect$.subscribe((node: MinimalNode) => {
expect(node.id).toBe('Bigfoot');

View File

@@ -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 { CommentModel, UserProcessModel } from '../models';
import { CommentListComponent } from './comment-list.component';
import { By } from '@angular/platform-browser';
@@ -26,28 +26,28 @@ import { setupTestBed } from '../testing/setup-test-bed';
import { CoreTestingModule } from '../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
const testUser: UserProcessModel = new UserProcessModel({
const testUser = new UserProcessModel({
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com'
});
const processCommentOne: CommentModel = new CommentModel({
const processCommentOne = new CommentModel({
id: 1,
message: 'Test Comment',
created: new Date(),
createdBy: testUser
});
const processCommentTwo: CommentModel = new CommentModel({
const processCommentTwo = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
createdBy: testUser
});
const contentCommentUserPictureDefined: CommentModel = new CommentModel({
const contentCommentUserPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
@@ -63,7 +63,7 @@ const contentCommentUserPictureDefined: CommentModel = new CommentModel({
}
});
const processCommentUserPictureDefined: CommentModel = new CommentModel({
const processCommentUserPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
@@ -76,7 +76,7 @@ const processCommentUserPictureDefined: CommentModel = new CommentModel({
}
});
const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
const contentCommentUserNoPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
@@ -91,7 +91,7 @@ const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
}
});
const processCommentUserNoPictureDefined: CommentModel = new CommentModel({
const processCommentUserNoPictureDefined = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date(),
@@ -119,7 +119,7 @@ describe('CommentListComponent', () => {
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(async(() => {
beforeEach(() => {
ecmUserService = TestBed.inject(EcmUserService);
spyOn(ecmUserService, 'getUserProfileImage').and.returnValue('alfresco-logo.svg');
@@ -130,16 +130,16 @@ describe('CommentListComponent', () => {
commentList = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
}));
});
afterEach(() => {
fixture.destroy();
});
it('should emit row click event', async(() => {
it('should emit row click event', fakeAsync(() => {
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.clickRow.subscribe((selectedComment) => {
commentList.clickRow.subscribe((selectedComment: CommentModel) => {
expect(selectedComment.id).toEqual(1);
expect(selectedComment.message).toEqual('Test Comment');
expect(selectedComment.createdBy).toEqual(testUser);
@@ -153,7 +153,7 @@ describe('CommentListComponent', () => {
});
}));
it('should deselect the previous selected comment when a new one is clicked', async(() => {
it('should deselect the previous selected comment when a new one is clicked', fakeAsync(() => {
processCommentOne.isSelected = true;
const commentOne = Object.assign({}, processCommentOne);
const commentTwo = Object.assign({}, processCommentTwo);
@@ -174,127 +174,126 @@ describe('CommentListComponent', () => {
});
}));
it('should not show comment list if no input is given', async(() => {
it('should not show comment list if no input is given', async () => {
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
expect(fixture.nativeElement.querySelector('adf-datatable')).toBeNull();
});
}));
expect(fixture.nativeElement.querySelector('adf-datatable')).toBeNull();
});
it('should show comment message when input is given', async(() => {
it('should show comment message when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.message);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
}));
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.message);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
it('should show comment user when input is given', async(() => {
it('should show comment user when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('#comment-user');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName);
expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull();
});
}));
const elements = fixture.nativeElement.querySelectorAll('#comment-user');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(processCommentOne.createdBy.firstName + ' ' + processCommentOne.createdBy.lastName);
expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull();
});
it('comment date time should start with few seconds ago when comment date is few seconds ago', async(() => {
it('comment date time should start with few seconds ago when comment date is few seconds ago', async () => {
const commentFewSecond = Object.assign({}, processCommentOne);
commentFewSecond.created = new Date();
commentList.comments = [commentFewSecond];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('a few seconds ago');
});
}));
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('a few seconds ago');
});
it('comment date time should start with Yesterday when comment date is yesterday', async(() => {
it('comment date time should start with Yesterday when comment date is yesterday', async () => {
const commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [commentOld];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('a day ago');
});
}));
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('a day ago');
});
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => {
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async () => {
const commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [commentOld];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).not.toContain('Today');
expect(element.innerText).not.toContain('Yesterday');
});
}));
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).not.toContain('Today');
expect(element.innerText).not.toContain('Yesterday');
});
it('should show user icon when input is given', async(() => {
it('should show user icon when input is given', async () => {
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('#comment-user-icon');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy));
expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull();
});
}));
const elements = fixture.nativeElement.querySelectorAll('#comment-user-icon');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toContain(commentList.getUserShortName(processCommentOne.createdBy));
expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull();
});
it('should return content picture when is a content user with a picture', async(() => {
it('should return content picture when is a content user with a picture', async () => {
commentList.comments = [contentCommentUserPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
}));
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
it('should return process picture when is a process user with a picture', async(() => {
it('should return process picture when is a process user with a picture', async () => {
commentList.comments = [processCommentUserPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
}));
const elements = fixture.nativeElement.querySelectorAll('.adf-people-img');
expect(elements.length).toBe(1);
expect(fixture.nativeElement.getElementsByClassName('adf-people-img')[0].src).toContain('alfresco-logo.svg');
});
it('should return content short name when is a content user without a picture', async(() => {
it('should return content short name when is a content user without a picture', async () => {
commentList.comments = [contentCommentUserNoPictureDefined];
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
expect(elements.length).toBe(1);
});
}));
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
expect(elements.length).toBe(1);
});
it('should return process short name when is a process user without a picture', async(() => {
it('should return process short name when is a process user without a picture', async () => {
commentList.comments = [processCommentUserNoPictureDefined];
fixture.detectChanges();
fixture.whenStable().then(() => {
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
expect(elements.length).toBe(1);
});
}));
fixture.detectChanges();
await fixture.whenStable();
const elements = fixture.nativeElement.querySelectorAll('.adf-comment-user-icon');
expect(elements.length).toBe(1);
});
});

View File

@@ -16,7 +16,7 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of, throwError } from 'rxjs';
import { CommentProcessService } from '../services/comment-process.service';
import { CommentsComponent } from './comments.component';
@@ -27,7 +27,6 @@ import { TranslateModule } from '@ngx-translate/core';
import { CommentModel } from '../models/comment.model';
describe('CommentsComponent', () => {
let component: CommentsComponent;
let fixture: ComponentFixture<CommentsComponent>;
let getProcessCommentsSpy: jasmine.Spy;
@@ -109,66 +108,65 @@ describe('CommentsComponent', () => {
expect(getProcessCommentsSpy).not.toHaveBeenCalled();
});
it('should display comments when the task has comments', async(() => {
it('should display comments when the task has comments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({'taskId': change});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelectorAll('#comment-message').length).toBe(3);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should display comments count when the task has comments', async(() => {
expect(fixture.nativeElement.querySelectorAll('#comment-message').length).toBe(3);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
it('should display comments count when the task has comments', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({'taskId': change});
fixture.whenStable().then(() => {
fixture.detectChanges();
const element = fixture.nativeElement.querySelector('#comment-header');
expect(element.innerText).toBe('COMMENTS.HEADER');
});
}));
it('should not display comments when the task has no comments', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const element = fixture.nativeElement.querySelector('#comment-header');
expect(element.innerText).toBe('COMMENTS.HEADER');
});
it('should not display comments when the task has no comments', async () => {
component.taskId = '123';
getProcessCommentsSpy.and.returnValue(of([]));
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
}));
it('should display comments input by default', async(() => {
fixture.detectChanges();
await fixture.whenStable()
expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
it('should display comments input by default', async () => {
const change = new SimpleChange(null, '123', true);
component.ngOnChanges({'taskId': change});
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
}));
it('should not display comments input when the task is readonly', async(() => {
component.readOnly = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
}));
await fixture.whenStable()
expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
it('should not display comments input when the task is readonly', async () => {
component.readOnly = true;
fixture.detectChanges();
await fixture.whenStable()
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
describe('change detection taskId', () => {
const change = new SimpleChange('123', '456', true);
const nullChange = new SimpleChange('123', null, true);
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable().then(() => {
getProcessCommentsSpy.calls.reset();
});
}));
});
it('should fetch new comments when taskId changed', () => {
component.ngOnChanges({'taskId': change});
@@ -187,17 +185,13 @@ describe('CommentsComponent', () => {
});
describe('change detection node', () => {
const change = new SimpleChange('123', '456', true);
const nullChange = new SimpleChange('123', null, true);
beforeEach(async(() => {
beforeEach(() => {
component.nodeId = '123';
fixture.detectChanges();
fixture.whenStable().then(() => {
getContentCommentsSpy.calls.reset();
});
}));
});
it('should fetch new comments when nodeId changed', () => {
component.ngOnChanges({'nodeId': change});
@@ -217,81 +211,81 @@ describe('CommentsComponent', () => {
describe('Add comment task', () => {
beforeEach(async(() => {
beforeEach(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable();
}));
});
it('should sanitize comment when user input contains html elements', async(() => {
it('should sanitize comment when user input contains html elements', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = '<div class="text-class"><button onclick=""><h1>action</h1></button></div>';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'action');
});
}));
it('should normalize comment when user input contains spaces sequence', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'action');
});
it('should normalize comment when user input contains spaces sequence', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'test comment';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'test comment');
});
}));
it('should add break lines to comment when user input contains new line characters', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'test comment');
});
it('should add break lines to comment when user input contains new line characters', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'these\nare\nparagraphs\n';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'these<br/>are<br/>paragraphs');
});
}));
it('should call service to add a comment when add button is pressed', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addProcessCommentSpy).toHaveBeenCalledWith('123', 'these<br/>are<br/>paragraphs');
});
it('should call service to add a comment when add button is pressed', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'Test Comment';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addProcessCommentSpy).toHaveBeenCalled();
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe('Test Comment');
});
}));
it('should not call service to add a comment when comment is empty', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addProcessCommentSpy).toHaveBeenCalled();
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe('Test Comment');
});
it('should not call service to add a comment when comment is empty', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = '';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addProcessCommentSpy).not.toHaveBeenCalled();
});
}));
it('should clear comment when escape key is pressed', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addProcessCommentSpy).not.toHaveBeenCalled();
});
it('should clear comment when escape key is pressed', async () => {
const event = new KeyboardEvent('keydown', {'key': 'Escape'});
let element = fixture.nativeElement.querySelector('#comment-input');
element.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
element = fixture.nativeElement.querySelector('#comment-input');
expect(element.value).toBe('');
});
}));
await fixture.whenStable();
element = fixture.nativeElement.querySelector('#comment-input');
expect(element.value).toBe('');
});
it('should emit an error when an error occurs adding the comment', () => {
const emitSpy = spyOn(component.error, 'emit');
@@ -304,81 +298,81 @@ describe('CommentsComponent', () => {
describe('Add comment node', () => {
beforeEach(async(() => {
beforeEach(() => {
component.nodeId = '123';
fixture.detectChanges();
fixture.whenStable();
}));
});
it('should call service to add a comment when add button is pressed', async(() => {
it('should call service to add a comment when add button is pressed', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'Test Comment';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addContentCommentSpy).toHaveBeenCalled();
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe('Test Comment');
});
}));
it('should sanitize comment when user input contains html elements', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addContentCommentSpy).toHaveBeenCalled();
const elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe('Test Comment');
});
it('should sanitize comment when user input contains html elements', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = '<div class="text-class"><button onclick=""><h1>action</h1></button></div>';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'action');
});
}));
it('should normalize comment when user input contains spaces sequence', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'action');
});
it('should normalize comment when user input contains spaces sequence', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'test comment';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'test comment');
});
}));
it('should add break lines to comment when user input contains new line characters', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'test comment');
});
it('should add break lines to comment when user input contains new line characters', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = 'these\nare\nparagraphs\n';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'these<br/>are<br/>paragraphs');
});
}));
it('should not call service to add a comment when comment is empty', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addContentCommentSpy).toHaveBeenCalledWith('123', 'these<br/>are<br/>paragraphs');
});
it('should not call service to add a comment when comment is empty', async () => {
const element = fixture.nativeElement.querySelector('.adf-comments-input-add');
component.message = '';
element.dispatchEvent(new Event('click'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addContentCommentSpy).not.toHaveBeenCalled();
});
}));
it('should clear comment when escape key is pressed', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(addContentCommentSpy).not.toHaveBeenCalled();
});
it('should clear comment when escape key is pressed', async () => {
const event = new KeyboardEvent('keydown', {'key': 'Escape'});
let element = fixture.nativeElement.querySelector('#comment-input');
element.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
element = fixture.nativeElement.querySelector('#comment-input');
expect(element.value).toBe('');
});
}));
await fixture.whenStable();
element = fixture.nativeElement.querySelector('#comment-input');
expect(element.value).toBe('');
});
it('should emit an error when an error occurs adding the comment', () => {
const emitSpy = spyOn(component.error, 'emit');

View File

@@ -15,14 +15,13 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EmptyListComponent } from './empty-list.component';
import { setupTestBed } from '../../../testing/setup-test-bed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
import { TranslateModule } from '@ngx-translate/core';
describe('EmptyListComponentComponent', () => {
let component: EmptyListComponent;
let fixture: ComponentFixture<EmptyListComponent>;
setupTestBed({
@@ -34,22 +33,16 @@ describe('EmptyListComponentComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(EmptyListComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should be defined', () => {
expect(component).toBeDefined();
});
it('should render the input values', async(() => {
it('should render the input values', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('.adf-empty-list_template')).toBeDefined();
});
}));
await fixture.whenStable();
expect(fixture.nativeElement.querySelector('.adf-empty-list_template')).toBeDefined();
});
});

View File

@@ -16,10 +16,12 @@
*/
import { Inject, AfterViewInit, Directive, EventEmitter, OnDestroy, Output } from '@angular/core';
import { MatSelect, SELECT_ITEM_HEIGHT_EM } from '@angular/material/select';
import { MatSelect } from '@angular/material/select';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
const SELECT_ITEM_HEIGHT_EM = 3;
@Directive({
selector: '[adf-infinite-select-scroll]'
})

View File

@@ -46,17 +46,17 @@ describe('TaskAttachmentList', () => {
}));
it('should show the forms as a list', async(() => {
it('should show the forms as a list', async () => {
spyOn(service, 'getForms').and.returnValue(of([
{ name: 'FakeName-1', lastUpdatedByFullName: 'FakeUser-1', lastUpdated: '2017-01-02' },
{ name: 'FakeName-2', lastUpdatedByFullName: 'FakeUser-2', lastUpdated: '2017-01-03' }
]));
component.ngOnChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelectorAll('.adf-datatable-body > .adf-datatable-row').length).toBe(2);
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelectorAll('.adf-datatable-body > .adf-datatable-row').length).toBe(2);
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormFieldModel } from './../core/form-field.model';
import { AmountWidgetComponent, ADF_AMOUNT_SETTINGS } from './amount.widget';
import { setupTestBed } from '../../../../testing/setup-test-bed';
@@ -147,7 +147,7 @@ describe('AmountWidgetComponent - rendering', () => {
expect(errorWidget.textContent).toBe('FORM.FIELD.VALIDATOR.INVALID_NUMBER');
});
it('should display tooltip when tooltip is set', async(() => {
it('should display tooltip when tooltip is set', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'TestAmount1',
name: 'Test Amount',
@@ -168,11 +168,13 @@ describe('AmountWidgetComponent - rendering', () => {
});
fixture.detectChanges();
await fixture.whenStable();
const ammountElement: any = fixture.nativeElement.querySelector('#TestAmount1');
const tooltip = ammountElement.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(widget.field.tooltip);
}));
});
});
describe('AmountWidgetComponent settings', () => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { FormFieldTypes } from '../core/form-field-types';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
@@ -54,6 +54,8 @@ describe('CheckboxWidgetComponent', () => {
element = fixture.nativeElement;
});
afterEach(() => fixture.destroy());
describe('when template is ready', () => {
beforeEach(() => {
@@ -67,14 +69,14 @@ describe('CheckboxWidgetComponent', () => {
});
});
it('should be marked as invalid when required', async(() => {
it('should be marked as invalid when required', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('.adf-invalid')).not.toBeNull();
});
}));
await fixture.whenStable();
it('should be checked if boolean true is passed', async(() => {
expect(element.querySelector('.adf-invalid')).not.toBeNull();
});
it('should be checked if boolean true is passed', fakeAsync(() => {
widget.field.value = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -84,26 +86,26 @@ describe('CheckboxWidgetComponent', () => {
});
}));
it('should not be checked if false is passed', async(() => {
it('should not be checked if false is passed', async () => {
widget.field.value = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input');
expect(checkbox.getAttribute('aria-checked')).toBe('false');
});
}));
it('should display tooltip when tooltip is set', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const checkbox = fixture.debugElement.nativeElement.querySelector('mat-checkbox input');
expect(checkbox.getAttribute('aria-checked')).toBe('false');
});
it('should display tooltip when tooltip is set', async () => {
widget.field.tooltip = 'checkbox widget';
fixture.detectChanges();
fixture.whenStable().then(() => {
const checkbox = fixture.debugElement.nativeElement.querySelector('#check-id');
const tooltip = checkbox.getAttribute('ng-reflect-message');
await fixture.whenStable();
expect(tooltip).toEqual(widget.field.tooltip);
});
}));
const checkbox = fixture.debugElement.nativeElement.querySelector('#check-id');
const tooltip = checkbox.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(widget.field.tooltip);
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import moment from 'moment-es6';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
@@ -109,7 +109,7 @@ describe('DateTimeWidgetComponent', () => {
describe('template check', () => {
it('should show visible date widget', async(() => {
it('should show visible date widget', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -117,37 +117,36 @@ describe('DateTimeWidgetComponent', () => {
type: 'datetime',
readOnly: 'false'
});
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toBe('30-11-9999 10:30 AM');
});
}));
it('should show the correct format type', async(() => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '12-30-9999 10:30 AM',
dateDisplayFormat: 'MM-DD-YYYY HH:mm A',
type: 'datetime',
readOnly: 'false'
});
fixture.detectChanges();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999 10:30 AM');
});
}));
it('should disable date button when is readonly', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toBe('30-11-9999 10:30 AM');
});
it('should show the correct format type', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '12-30-9999 10:30 AM',
dateDisplayFormat: 'MM-DD-YYYY HH:mm A',
type: 'datetime',
readOnly: 'false'
});
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999 10:30 AM');
});
it('should disable date button when is readonly', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -157,18 +156,20 @@ describe('DateTimeWidgetComponent', () => {
readOnly: 'false'
});
fixture.detectChanges();
await fixture.whenStable();
let dateButton = <HTMLButtonElement> element.querySelector('button');
expect(dateButton.disabled).toBeFalsy();
widget.field.readOnly = true;
fixture.detectChanges();
await fixture.whenStable();
dateButton = <HTMLButtonElement> element.querySelector('button');
expect(dateButton.disabled).toBeTruthy();
}));
});
it('should display tooltip when tooltip is set', async(() => {
it('should display tooltip when tooltip is set', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -180,11 +181,13 @@ describe('DateTimeWidgetComponent', () => {
});
fixture.detectChanges();
await fixture.whenStable();
const dateElement: any = element.querySelector('#date-field-id');
const tooltip = dateElement.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(widget.field.tooltip);
}));
});
});
it('should display always the json value', () => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import moment from 'moment-es6';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
@@ -105,7 +105,7 @@ describe('DateWidgetComponent', () => {
TestBed.resetTestingModule();
});
it('should show visible date widget', async(() => {
it('should show visible date widget', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -115,16 +115,17 @@ describe('DateWidgetComponent', () => {
});
widget.field.isVisible = true;
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('9-9-9999');
});
}));
it('should show the correct format type', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('9-9-9999');
});
it('should show the correct format type', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -135,17 +136,17 @@ describe('DateWidgetComponent', () => {
widget.field.isVisible = true;
widget.field.dateDisplayFormat = 'MM-DD-YYYY';
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999');
});
}));
it('should disable date button when is readonly', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
const dateElement: any = element.querySelector('#date-field-id');
expect(dateElement.value).toContain('12-30-9999');
});
it('should disable date button when is readonly', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -155,7 +156,9 @@ describe('DateWidgetComponent', () => {
});
widget.field.isVisible = true;
widget.field.readOnly = false;
fixture.detectChanges();
await fixture.whenStable();
let dateButton = <HTMLButtonElement> element.querySelector('button');
expect(dateButton.disabled).toBeFalsy();
@@ -165,9 +168,9 @@ describe('DateWidgetComponent', () => {
dateButton = <HTMLButtonElement> element.querySelector('button');
expect(dateButton.disabled).toBeTruthy();
}));
});
it('should set isValid to false when the value is not a correct date value', async(() => {
it('should set isValid to false when the value is not a correct date value', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -177,9 +180,11 @@ describe('DateWidgetComponent', () => {
});
widget.field.isVisible = true;
widget.field.readOnly = false;
fixture.detectChanges();
await fixture.whenStable();
expect(widget.field.isValid).toBeFalsy();
}));
});
});
});

View File

@@ -132,28 +132,33 @@ describe('DropdownWidgetComponent', () => {
});
}));
it('should be able to display label with asterix', async(() => {
it('should be able to display label with asterix', async () => {
const label = 'MyLabel123';
widget.field.name = label;
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('label').innerText).toBe(label + '*');
}));
});
it('should be invalid if no default option', async(() => {
it('should be invalid if no default option', async () => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-invalid')).toBeDefined();
expect(element.querySelector('.adf-invalid')).not.toBeNull();
}));
});
it('should be valid if default option', async(() => {
it('should be valid if default option', async () => {
widget.field.options = fakeOptionList;
widget.field.value = fakeOptionList[0].id;
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-invalid')).toBeNull();
}));
});
});
describe('when template is ready', () => {
@@ -177,7 +182,7 @@ describe('DropdownWidgetComponent', () => {
fixture.detectChanges();
}));
it('should show visible dropdown widget', async(() => {
it('should show visible dropdown widget', async () => {
expect(element.querySelector('#dropdown-id')).toBeDefined();
expect(element.querySelector('#dropdown-id')).not.toBeNull();
@@ -190,36 +195,35 @@ describe('DropdownWidgetComponent', () => {
expect(optOne).not.toBeNull();
expect(optTwo).not.toBeNull();
expect(optThree).not.toBeNull();
}));
});
it('should select the default value when an option is chosen as default', async(() => {
it('should select the default value when an option is chosen as default', async () => {
widget.field.value = 'option_2';
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2');
expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2');
});
}));
it('should select the empty value when no default is chosen', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2');
expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2');
});
it('should select the empty value when no default is chosen', async () => {
widget.field.value = 'empty';
widget.ngOnInit();
fixture.detectChanges();
await fixture.whenStable();
openSelect();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable()
.then(() => {
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty');
});
}));
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty');
});
});
describe('and dropdown is populated via processDefinitionId', () => {
@@ -241,7 +245,7 @@ describe('DropdownWidgetComponent', () => {
fixture.detectChanges();
}));
it('should show visible dropdown widget', async(() => {
it('should show visible dropdown widget', () => {
expect(element.querySelector('#dropdown-id')).toBeDefined();
expect(element.querySelector('#dropdown-id')).not.toBeNull();
@@ -254,37 +258,37 @@ describe('DropdownWidgetComponent', () => {
expect(optOne).not.toBeNull();
expect(optTwo).not.toBeNull();
expect(optThree).not.toBeNull();
}));
});
it('should select the default value when an option is chosen as default', async(() => {
it('should select the default value when an option is chosen as default', async () => {
widget.field.value = 'option_2';
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2');
expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2');
});
}));
it('should select the empty value when no default is chosen', async(() => {
fixture.detectChanges();
await fixture.whenStable();
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('option_2');
expect(dropDownElement.attributes['ng-reflect-model'].textContent).toBe('option_2');
});
it('should select the empty value when no default is chosen', async () => {
widget.field.value = 'empty';
widget.ngOnInit();
fixture.detectChanges();
await fixture.whenStable();
openSelect();
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable()
.then(() => {
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty');
});
}));
const dropDownElement: any = element.querySelector('#dropdown-id');
expect(dropDownElement.attributes['ng-reflect-model'].value).toBe('empty');
});
it('should be disabled when the field is readonly', async(() => {
it('should be disabled when the field is readonly', async () => {
widget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), {
id: 'dropdown-id',
name: 'date-name',
@@ -294,15 +298,14 @@ describe('DropdownWidgetComponent', () => {
});
fixture.detectChanges();
fixture.whenStable()
.then(() => {
const dropDownElement: HTMLSelectElement = <HTMLSelectElement> element.querySelector('#dropdown-id');
expect(dropDownElement).not.toBeNull();
expect(dropDownElement.getAttribute('aria-disabled')).toBe('true');
});
}));
await fixture.whenStable();
it('should show the option value when the field is readonly', async(() => {
const dropDownElement: HTMLSelectElement = <HTMLSelectElement> element.querySelector('#dropdown-id');
expect(dropDownElement).not.toBeNull();
expect(dropDownElement.getAttribute('aria-disabled')).toBe('true');
});
it('should show the option value when the field is readonly', async () => {
widget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), {
id: 'dropdown-id',
name: 'date-name',
@@ -315,16 +318,14 @@ describe('DropdownWidgetComponent', () => {
openSelect();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
fixture.detectChanges();
const options = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(options.length).toBe(1);
await fixture.whenStable();
const option = options[0].nativeElement;
expect(option.innerText).toEqual('FakeValue');
});
}));
const options = fixture.debugElement.queryAll(By.css('.mat-option-text'));
expect(options.length).toBe(1);
const option = options[0].nativeElement;
expect(option.innerText).toEqual('FakeValue');
});
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LogService } from '../../../../services';
import { FormService } from './../../../services/form.service';
import { FormFieldModel, FormFieldTypes, FormModel } from './../core/index';
@@ -338,7 +338,7 @@ describe('DynamicTableWidgetComponent', () => {
TestBed.resetTestingModule();
});
it('should select a row when press space bar', async(() => {
it('should select a row when press space bar', async () => {
const rowElement = element.querySelector('#fake-dynamic-table-row-0');
expect(element.querySelector('#dynamic-table-fake-dynamic-table')).not.toBeNull();
@@ -348,15 +348,15 @@ describe('DynamicTableWidgetComponent', () => {
const event: any = new Event('keyup');
event.keyCode = 32;
rowElement.dispatchEvent(event);
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
const selectedRow = element.querySelector('#fake-dynamic-table-row-0');
expect(selectedRow.className).toContain('adf-dynamic-table-widget__row-selected');
});
}));
const selectedRow = element.querySelector('#fake-dynamic-table-row-0');
expect(selectedRow.className).toContain('adf-dynamic-table-widget__row-selected');
});
it('should focus on add button when a new row is saved', async(() => {
it('should focus on add button when a new row is saved', async () => {
const addNewRowButton: HTMLButtonElement = <HTMLButtonElement> element.querySelector('#fake-dynamic-table-add-row');
expect(element.querySelector('#dynamic-table-fake-dynamic-table')).not.toBeNull();
@@ -364,11 +364,11 @@ describe('DynamicTableWidgetComponent', () => {
widget.addNewRow();
widget.onSaveChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(document.activeElement.id).toBe('fake-dynamic-table-add-row');
});
}));
fixture.detectChanges();
await fixture.whenStable();
expect(document.activeElement.id).toBe('fake-dynamic-table-add-row');
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable, of, throwError } from 'rxjs';
import { FormService } from './../../../../../services/form.service';
@@ -195,11 +195,11 @@ describe('DropdownEditorComponent', () => {
fixture.detectChanges();
}
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(DropdownEditorComponent);
dropDownEditorComponent = fixture.componentInstance;
element = fixture.nativeElement;
}));
});
afterEach(() => {
fixture.destroy();
@@ -207,7 +207,7 @@ describe('DropdownEditorComponent', () => {
describe('and dropdown is populated via taskId', () => {
beforeEach(async(() => {
beforeEach(() => {
stubFormService = fixture.debugElement.injector.get(FormService);
spyOn(stubFormService, 'getRestFieldValuesColumn').and.returnValue(of(fakeOptionList));
row = <DynamicTableRow> {value: {dropdown: 'one'}};
@@ -235,9 +235,9 @@ describe('DropdownEditorComponent', () => {
});
dropDownEditorComponent.table.field.isVisible = true;
fixture.detectChanges();
}));
});
it('should show visible dropdown widget', async(() => {
it('should show visible dropdown widget', () => {
expect(element.querySelector('#column-id')).toBeDefined();
expect(element.querySelector('#column-id')).not.toBeNull();
@@ -250,12 +250,12 @@ describe('DropdownEditorComponent', () => {
expect(optOne).not.toBeNull();
expect(optTwo).not.toBeNull();
expect(optThree).not.toBeNull();
}));
});
});
describe('and dropdown is populated via processDefinitionId', () => {
beforeEach(async(() => {
beforeEach(() => {
stubFormService = fixture.debugElement.injector.get(FormService);
spyOn(stubFormService, 'getRestFieldValuesColumnByProcessId').and.returnValue(of(fakeOptionList));
row = <DynamicTableRow> {value: {dropdown: 'one'}};
@@ -283,9 +283,9 @@ describe('DropdownEditorComponent', () => {
});
dropDownEditorComponent.table.field.isVisible = true;
fixture.detectChanges();
}));
});
it('should show visible dropdown widget', async(() => {
it('should show visible dropdown widget', () => {
expect(element.querySelector('#column-id')).toBeDefined();
expect(element.querySelector('#column-id')).not.toBeNull();
@@ -298,8 +298,7 @@ describe('DropdownEditorComponent', () => {
expect(optOne).not.toBeNull();
expect(optTwo).not.toBeNull();
expect(optThree).not.toBeNull();
}));
});
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { UserProcessModel } from '../../../../models';
import { Observable, of } from 'rxjs';
@@ -83,28 +83,23 @@ describe('PeopleWidgetComponent', () => {
expect(widget.getDisplayName(model)).toBe('John');
});
it('should init value from the field', async(() => {
it('should init value from the field', async () => {
widget.field.value = new UserProcessModel({
id: 'people-id',
firstName: 'John',
lastName: 'Doe'
});
spyOn(formService, 'getWorkflowUsers').and.returnValue(
new Observable((observer) => {
observer.next(null);
observer.complete();
})
);
spyOn(formService, 'getWorkflowUsers').and.returnValue(of(null));
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe');
});
}));
await fixture.whenStable();
it('should show the readonly value when the form is readonly', async(() => {
expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe');
});
it('should show the readonly value when the form is readonly', async () => {
widget.field.value = new UserProcessModel({
id: 'people-id',
firstName: 'John',
@@ -113,20 +108,15 @@ describe('PeopleWidgetComponent', () => {
widget.field.readOnly = true;
widget.field.form.readOnly = true;
spyOn(formService, 'getWorkflowUsers').and.returnValue(
new Observable((observer) => {
observer.next(null);
observer.complete();
})
);
spyOn(formService, 'getWorkflowUsers').and.returnValue(of(null));
widget.ngOnInit();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe');
expect((element.querySelector('input') as HTMLInputElement).disabled).toBeTruthy();
});
}));
await fixture.whenStable();
expect((element.querySelector('input') as HTMLInputElement).value).toBe('John Doe');
expect((element.querySelector('input') as HTMLInputElement).disabled).toBeTruthy();
});
it('should require form field to setup values on init', () => {
widget.field.value = null;
@@ -175,7 +165,7 @@ describe('PeopleWidgetComponent', () => {
{ id: 1001, firstName: 'Test01', lastName: 'Test01', email: 'test' },
{ id: 1002, firstName: 'Test02', lastName: 'Test02', email: 'test2' }];
beforeEach(async(() => {
beforeEach(() => {
spyOn(formService, 'getWorkflowUsers').and.returnValue(new Observable((observer) => {
observer.next(fakeUserResult);
observer.complete();
@@ -188,7 +178,7 @@ describe('PeopleWidgetComponent', () => {
});
fixture.detectChanges();
element = fixture.nativeElement;
}));
});
afterAll(() => {
if (fixture) {
@@ -201,32 +191,33 @@ describe('PeopleWidgetComponent', () => {
expect(element.querySelector('#people-widget-content')).not.toBeNull();
});
it('should show an error message if the user is invalid', async(() => {
it('should show an error message if the user is invalid', async () => {
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
peopleHTMLElement.focus();
peopleHTMLElement.value = 'K';
peopleHTMLElement.dispatchEvent(new Event('keyup'));
peopleHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('.adf-error-text')).not.toBeNull();
expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE');
});
}));
it('should show the people if the typed result match', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).not.toBeNull();
expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE');
});
it('should show the people if the typed result match', async () => {
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
peopleHTMLElement.focus();
peopleHTMLElement.value = 'T';
peopleHTMLElement.dispatchEvent(new Event('keyup'));
peopleHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull();
});
}));
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull();
});
it('should hide result list if input is empty', () => {
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
@@ -241,19 +232,22 @@ describe('PeopleWidgetComponent', () => {
});
});
it('should display two options if we tap one letter', async(() => {
it('should display two options if we tap one letter', async () => {
fixture.detectChanges();
await fixture.whenStable();
const peopleHTMLElement: HTMLInputElement = <HTMLInputElement> element.querySelector('input');
peopleHTMLElement.focus();
peopleHTMLElement.value = 'T';
peopleHTMLElement.dispatchEvent(new Event('keyup'));
peopleHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull();
});
}));
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-0'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('#adf-people-widget-user-1'))).not.toBeNull();
});
it('should emit peopleSelected if option is valid', async () => {
const selectEmitSpy = spyOn(widget.peopleSelected, 'emit');
@@ -262,21 +256,23 @@ describe('PeopleWidgetComponent', () => {
peopleHTMLElement.value = 'Test01 Test01';
peopleHTMLElement.dispatchEvent(new Event('keyup'));
peopleHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(selectEmitSpy).toHaveBeenCalledWith(1001);
});
await fixture.whenStable();
expect(selectEmitSpy).toHaveBeenCalledWith(1001);
});
it('should display tooltip when tooltip is set', async(() => {
it('should display tooltip when tooltip is set', async () => {
widget.field.tooltip = 'people widget';
fixture.detectChanges();
await fixture.whenStable();
const radioButtonsElement: any = element.querySelector('#people-id');
const tooltip = radioButtonsElement.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(widget.field.tooltip);
}));
});
});
});

View File

@@ -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 { Observable, of } from 'rxjs';
import { FormService } from '../../../services/form.service';
import { ContainerModel } from '../core/container.model';
@@ -150,12 +150,12 @@ describe('RadioButtonsWidgetComponent', () => {
name: 'opt-name-2'
}];
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(RadioButtonsWidgetComponent);
radioButtonWidget = fixture.componentInstance;
element = fixture.nativeElement;
stubFormService = fixture.debugElement.injector.get(FormService);
}));
});
it('should show radio buttons as text when is readonly', async () => {
radioButtonWidget.field = new FormFieldModel(new FormModel({}), {
@@ -230,7 +230,7 @@ describe('RadioButtonsWidgetComponent', () => {
expect(radioButtonWidget.field.isValid).toBe(true);
});
it('should display tooltip when tooltip is set', async(() => {
it('should display tooltip when tooltip is set', async () => {
radioButtonWidget.field = new FormFieldModel(new FormModel(), {
id: 'radio-id',
name: 'radio-name-label',
@@ -244,15 +244,17 @@ describe('RadioButtonsWidgetComponent', () => {
});
fixture.detectChanges();
await fixture.whenStable();
const radioButtonsElement: any = element.querySelector('#radio-id-opt-1');
const tooltip = radioButtonsElement.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(radioButtonWidget.field.tooltip);
}));
});
describe('and radioButton is populated via taskId', () => {
beforeEach(async(() => {
beforeEach(() => {
spyOn(stubFormService, 'getRestFieldValues').and.returnValue(of(restOption));
radioButtonWidget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' }), {
id: 'radio-id',
@@ -264,17 +266,17 @@ describe('RadioButtonsWidgetComponent', () => {
const fakeContainer = new ContainerModel(radioButtonWidget.field);
radioButtonWidget.field.form.fields.push(fakeContainer);
fixture.detectChanges();
}));
});
it('should show radio buttons', async(() => {
it('should show radio buttons', () => {
expect(element.querySelector('#radio-id')).toBeDefined();
expect(element.querySelector('#radio-id-opt-1-input')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-1')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-2-input')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-2')).not.toBeNull();
}));
});
it('should trigger field changed event on click', async(() => {
it('should trigger field changed event on click', fakeAsync(() => {
const option: HTMLElement = <HTMLElement> element.querySelector('#radio-id-opt-1-input');
expect(element.querySelector('#radio-id')).not.toBeNull();
expect(option).not.toBeNull();
@@ -287,35 +289,35 @@ describe('RadioButtonsWidgetComponent', () => {
describe('and radioButton is readonly', () => {
beforeEach(async(() => {
beforeEach(() => {
radioButtonWidget.field.readOnly = true;
fixture.detectChanges();
}));
});
it('should show radio buttons disabled', async(() => {
it('should show radio buttons disabled', () => {
expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-1"]')).toBeDefined();
expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-1"]')).not.toBeNull();
expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-2"]')).toBeDefined();
expect(element.querySelector('.mat-radio-disabled[ng-reflect-id="radio-id-opt-2"]')).not.toBeNull();
}));
});
describe('and a value is selected', () => {
beforeEach(async(() => {
beforeEach(() => {
radioButtonWidget.field.value = restOption[0].id;
fixture.detectChanges();
}));
});
it('should check the selected value', async(() => {
it('should check the selected value', () => {
expect(element.querySelector('.mat-radio-checked')).toBe(element.querySelector('mat-radio-button[ng-reflect-id="radio-id-opt-1"]'));
}));
});
});
});
});
describe('and radioButton is populated via processDefinitionId', () => {
beforeEach(async(() => {
beforeEach(() => {
radioButtonWidget.field = new FormFieldModel(new FormModel({ processDefinitionId: 'proc-id' }), {
id: 'radio-id',
name: 'radio-name',
@@ -325,15 +327,15 @@ describe('RadioButtonsWidgetComponent', () => {
spyOn(stubFormService, 'getRestFieldValuesByProcessId').and.returnValue(of(restOption));
radioButtonWidget.field.isVisible = true;
fixture.detectChanges();
}));
});
it('should show visible radio buttons', async(() => {
it('should show visible radio buttons', () => {
expect(element.querySelector('#radio-id')).toBeDefined();
expect(element.querySelector('#radio-id-opt-1-input')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-1')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-2-input')).not.toBeNull();
expect(element.querySelector('#radio-id-opt-2')).not.toBeNull();
}));
});
});
});
});

View File

@@ -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 { FormFieldTypes } from '../core/form-field-types';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
@@ -203,7 +203,7 @@ describe('TextWidgetComponent', () => {
expect(widget.field.isValid).toBe(false);
});
it('should display tooltip when tooltip is set', async(() => {
it('should display tooltip when tooltip is set', async () => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'text-id',
name: 'text-name',
@@ -213,11 +213,13 @@ describe('TextWidgetComponent', () => {
});
fixture.detectChanges();
await fixture.whenStable();
const textElement: any = element.querySelector('#text-id');
const tooltip = textElement.getAttribute('ng-reflect-message');
expect(tooltip).toEqual(widget.field.tooltip);
}));
});
});
describe('and no mask is configured on text element', () => {
@@ -237,7 +239,7 @@ describe('TextWidgetComponent', () => {
inputElement = element.querySelector<HTMLInputElement>('#text-id');
});
it('should be disabled on readonly forms', async(() => {
it('should be disabled on readonly forms', fakeAsync(() => {
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeDefined();
@@ -286,7 +288,7 @@ describe('TextWidgetComponent', () => {
expect(label.innerText).toBe('simple placeholder');
});
it('should prevent text to be written if is not allowed by the mask on keyUp event', async(() => {
it('should prevent text to be written if is not allowed by the mask on keyUp event', async () => {
expect(element.querySelector('#text-id')).not.toBeNull();
inputElement.value = 'F';
@@ -294,31 +296,32 @@ describe('TextWidgetComponent', () => {
const event: any = new Event('keyup');
event.keyCode = '70';
inputElement.dispatchEvent(event);
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
inputElement = element.querySelector<HTMLInputElement>('#text-id');
expect(inputElement.value).toBe('');
});
}));
inputElement = element.querySelector<HTMLInputElement>('#text-id');
expect(inputElement.value).toBe('');
});
it('should prevent text to be written if is not allowed by the mask on input event', async(() => {
it('should prevent text to be written if is not allowed by the mask on input event', async () => {
expect(element.querySelector('#text-id')).not.toBeNull();
inputElement.value = 'F';
widget.field.value = 'F';
inputElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
inputElement = element.querySelector<HTMLInputElement>('#text-id');
expect(inputElement.value).toBe('');
});
}));
inputElement = element.querySelector<HTMLInputElement>('#text-id');
expect(inputElement.value).toBe('');
});
it('should allow masked configured value on keyUp event', async () => {
fixture.detectChanges();
await fixture.whenStable();
it('should allow masked configured value on keyUp event', async(() => {
expect(element.querySelector('#text-id')).not.toBeNull();
inputElement.value = '1';
@@ -327,14 +330,17 @@ describe('TextWidgetComponent', () => {
event.keyCode = '49';
inputElement.dispatchEvent(event);
fixture.whenStable().then(() => {
fixture.detectChanges();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('1');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('1');
});
it('should auto-fill masked configured value on keyUp event', async () => {
fixture.detectChanges();
await fixture.whenStable();
it('should auto-fill masked configured value on keyUp event', async(() => {
expect(element.querySelector('#text-id')).not.toBeNull();
inputElement.value = '12345678';
@@ -343,12 +349,12 @@ describe('TextWidgetComponent', () => {
event.keyCode = '49';
inputElement.dispatchEvent(event);
fixture.whenStable().then(() => {
fixture.detectChanges();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('12-345,67%');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('12-345,67%');
});
});
describe('when the mask is reversed ', () => {
@@ -374,7 +380,10 @@ describe('TextWidgetComponent', () => {
TestBed.resetTestingModule();
});
it('should be able to apply the mask reversed', async(() => {
it('should be able to apply the mask reversed', async () => {
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#text-id')).not.toBeNull();
inputElement.value = '1234';
@@ -383,12 +392,12 @@ describe('TextWidgetComponent', () => {
event.keyCode = '49';
inputElement.dispatchEvent(event);
fixture.whenStable().then(() => {
fixture.detectChanges();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('12,34%');
});
}));
fixture.detectChanges();
await fixture.whenStable();
const textEle = element.querySelector<HTMLInputElement>('#text-id');
expect(textEle.value).toBe('12,34%');
});
});
describe('and a mask placeholder is configured', () => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable, of, throwError } from 'rxjs';
import { By } from '@angular/platform-browser';
@@ -234,11 +234,11 @@ describe('TypeaheadWidgetComponent', () => {
name: 'Fake Name 2'
}, { id: '3', name: 'Fake Name 3' }];
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(TypeaheadWidgetComponent);
typeaheadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
}));
});
afterEach(() => {
fixture.destroy();
@@ -247,7 +247,7 @@ describe('TypeaheadWidgetComponent', () => {
describe ('and typeahead is in readonly mode', () => {
it('should show typeahead value with input disabled', async(() => {
it('should show typeahead value with input disabled', async () => {
typeaheadWidgetComponent.field = new FormFieldModel(
new FormModel({ processVariables: [{ name: 'typeahead-id_LABEL', value: 'FakeProcessValue' }] }), {
id: 'typeahead-id',
@@ -255,15 +255,15 @@ describe('TypeaheadWidgetComponent', () => {
type: 'readonly',
params: { field: { id: 'typeahead-id', name: 'typeahead-name', type: 'typeahead' } }
});
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const readonlyInput: HTMLInputElement = <HTMLInputElement> element.querySelector('#typeahead-id');
expect(readonlyInput.disabled).toBeTruthy();
expect(readonlyInput).not.toBeNull();
expect(readonlyInput.value).toBe('FakeProcessValue');
});
}));
await fixture.whenStable();
const readonlyInput = element.querySelector<HTMLInputElement>('#typeahead-id');
expect(readonlyInput.disabled).toBeTruthy();
expect(readonlyInput).not.toBeNull();
expect(readonlyInput.value).toBe('FakeProcessValue');
});
afterEach(() => {
fixture.destroy();
@@ -273,7 +273,7 @@ describe('TypeaheadWidgetComponent', () => {
describe('and typeahead is populated via taskId', () => {
beforeEach(async(() => {
beforeEach(() => {
stubFormService = fixture.debugElement.injector.get(FormService);
spyOn(stubFormService, 'getRestFieldValues').and.returnValue(of(fakeOptionList));
typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
@@ -285,73 +285,73 @@ describe('TypeaheadWidgetComponent', () => {
});
typeaheadWidgetComponent.field.isVisible = true;
fixture.detectChanges();
}));
});
it('should show visible typeahead widget', async(() => {
it('should show visible typeahead widget', () => {
expect(element.querySelector('#typeahead-id')).toBeDefined();
expect(element.querySelector('#typeahead-id')).not.toBeNull();
}));
});
it('should show typeahead options', async(() => {
it('should show typeahead options', async () => {
const typeaheadElement = fixture.debugElement.query(By.css('#typeahead-id'));
const typeaheadHTMLElement: HTMLInputElement = <HTMLInputElement> typeaheadElement.nativeElement;
const typeaheadHTMLElement = <HTMLInputElement> typeaheadElement.nativeElement;
typeaheadHTMLElement.focus();
typeaheadWidgetComponent.value = 'F';
typeaheadHTMLElement.value = 'F';
typeaheadHTMLElement.dispatchEvent(new Event('keyup'));
typeaheadHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-1"] span'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-2"] span'))).not.toBeNull();
});
}));
it('should hide the option when the value is empty', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-1"] span'))).not.toBeNull();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-2"] span'))).not.toBeNull();
});
it('should hide the option when the value is empty', async () => {
const typeaheadElement = fixture.debugElement.query(By.css('#typeahead-id'));
const typeaheadHTMLElement: HTMLInputElement = <HTMLInputElement> typeaheadElement.nativeElement;
const typeaheadHTMLElement = <HTMLInputElement> typeaheadElement.nativeElement;
typeaheadHTMLElement.focus();
typeaheadWidgetComponent.value = 'F';
typeaheadHTMLElement.value = 'F';
typeaheadHTMLElement.dispatchEvent(new Event('keyup'));
typeaheadHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull();
typeaheadHTMLElement.focus();
typeaheadWidgetComponent.value = '';
typeaheadHTMLElement.dispatchEvent(new Event('keyup'));
typeaheadHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeNull();
});
});
}));
it('should show error message when the value is not valid', async(() => {
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).not.toBeNull();
typeaheadHTMLElement.focus();
typeaheadWidgetComponent.value = '';
typeaheadHTMLElement.dispatchEvent(new Event('keyup'));
typeaheadHTMLElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
await fixture.whenStable();
expect(fixture.debugElement.query(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeNull();
});
it('should show error message when the value is not valid', async () => {
typeaheadWidgetComponent.value = 'Fake Name';
typeaheadWidgetComponent.field.value = 'Fake Name';
typeaheadWidgetComponent.field.options = fakeOptionList;
expect(element.querySelector('.adf-error-text')).toBeNull();
const keyboardEvent = new KeyboardEvent('keypress');
typeaheadWidgetComponent.onKeyUp(keyboardEvent);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('.adf-error-text')).not.toBeNull();
expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE');
});
}));
await fixture.whenStable();
expect(element.querySelector('.adf-error-text')).not.toBeNull();
expect(element.querySelector('.adf-error-text').textContent).toContain('FORM.FIELD.VALIDATOR.INVALID_VALUE');
});
});
describe('and typeahead is populated via processDefinitionId', () => {
beforeEach(async(() => {
beforeEach(() => {
stubFormService = fixture.debugElement.injector.get(FormService);
spyOn(stubFormService, 'getRestFieldValuesByProcessId').and.returnValue(of(fakeOptionList));
typeaheadWidgetComponent.field = new FormFieldModel(new FormModel({ processDefinitionId: 'fake-process-id' }), {
@@ -363,24 +363,25 @@ describe('TypeaheadWidgetComponent', () => {
typeaheadWidgetComponent.field.emptyOption = { id: 'empty', name: 'Choose one...' };
typeaheadWidgetComponent.field.isVisible = true;
fixture.detectChanges();
}));
});
it('should show visible typeahead widget', async(() => {
it('should show visible typeahead widget', () => {
expect(element.querySelector('#typeahead-id')).toBeDefined();
expect(element.querySelector('#typeahead-id')).not.toBeNull();
}));
});
it('should show typeahead options', async(() => {
it('should show typeahead options', async () => {
const keyboardEvent = new KeyboardEvent('keypress');
typeaheadWidgetComponent.value = 'F';
typeaheadWidgetComponent.onKeyUp(keyboardEvent);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeDefined();
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-1"] span'))).toBeDefined();
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-2"] span'))).toBeDefined();
});
}));
await fixture.whenStable();
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-0"] span'))).toBeDefined();
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-1"] span'))).toBeDefined();
expect(fixture.debugElement.queryAll(By.css('[id="adf-typeahed-widget-user-2"] span'))).toBeDefined();
});
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { DebugElement } 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 { of } from 'rxjs';
import { FormService } from '../../../services/form.service';
@@ -60,7 +60,7 @@ const fakeJpgAnswer = {
describe('UploadWidgetComponent', () => {
function fakeCreationFile (name, id) {
function fakeCreationFile (name: string, id: string | number) {
return {
'id': id,
'name': name,
@@ -96,13 +96,13 @@ describe('UploadWidgetComponent', () => {
let inputElement: HTMLInputElement;
let formServiceInstance: FormService;
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(UploadWidgetComponent);
uploadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
debugElement = fixture.debugElement;
contentService = TestBed.inject(ProcessContentService);
}));
});
it('should setup with field data', () => {
const fileName = 'hello world';
@@ -152,57 +152,60 @@ describe('UploadWidgetComponent', () => {
uploadWidgetComponent.field.value = [];
});
it('should be not present in readonly forms', async(() => {
it('should be not present in readonly forms', async () => {
uploadWidgetComponent.field.form.readOnly = true;
fixture.detectChanges();
inputElement = <HTMLInputElement> element.querySelector('#upload-id');
inputElement = element.querySelector<HTMLInputElement>('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeNull();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should have the multiple attribute when is selected in parameters', async(() => {
expect(inputElement).toBeNull();
});
it('should have the multiple attribute when is selected in parameters', async () => {
uploadWidgetComponent.field.params.multiple = true;
fixture.detectChanges();
inputElement = <HTMLInputElement> element.querySelector('#upload-id');
inputElement = element.querySelector<HTMLInputElement>('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeTruthy();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should not have the multiple attribute if multiple is false', async(() => {
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeTruthy();
});
it('should not have the multiple attribute if multiple is false', async () => {
uploadWidgetComponent.field.params.multiple = false;
fixture.detectChanges();
inputElement = <HTMLInputElement> element.querySelector('#upload-id');
inputElement = element.querySelector<HTMLInputElement>('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeFalsy();
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should show the list file after upload a new content', async(() => {
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeFalsy();
});
it('should show the list file after upload a new content', async () => {
spyOn(contentService, 'createTemporaryRawRelatedContent').and.returnValue(of(fakePngAnswer));
uploadWidgetComponent.field.params.multiple = false;
fixture.detectChanges();
await fixture.whenStable();
const inputDebugElement = fixture.debugElement.query(By.css('#upload-id'));
inputDebugElement.triggerEventHandler('change', { target: { files: [filJpgFake] } });
const filesList = fixture.debugElement.query(By.css('#file-1156'));
expect(filesList).toBeDefined();
}));
});
it('should update the form after deleted a file', async(() => {
it('should update the form after deleted a file', async () => {
spyOn(contentService, 'createTemporaryRawRelatedContent').and.callFake((file: any) => {
if (file.name === 'file-fake.png') {
return of(fakePngAnswer);
@@ -218,21 +221,23 @@ describe('UploadWidgetComponent', () => {
uploadWidgetComponent.field.params.multiple = true;
spyOn(uploadWidgetComponent.field, 'updateForm');
fixture.detectChanges();
await fixture.whenStable();
const inputDebugElement = fixture.debugElement.query(By.css('#upload-id'));
inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } });
fixture.whenStable().then(() => {
fixture.detectChanges();
const deleteButton = <HTMLInputElement> element.querySelector('#file-1155-remove');
deleteButton.click();
fixture.detectChanges();
await fixture.whenStable();
expect(uploadWidgetComponent.field.updateForm).toHaveBeenCalled();
});
const deleteButton = <HTMLInputElement> element.querySelector('#file-1155-remove');
deleteButton.click();
}));
expect(uploadWidgetComponent.field.updateForm).toHaveBeenCalled();
});
it('should set has field value all the files uploaded', async(() => {
it('should set has field value all the files uploaded', async () => {
spyOn(contentService, 'createTemporaryRawRelatedContent').and.callFake((file: any) => {
if (file.name === 'file-fake.png') {
return of(fakePngAnswer);
@@ -246,149 +251,141 @@ describe('UploadWidgetComponent', () => {
});
uploadWidgetComponent.field.params.multiple = true;
fixture.detectChanges();
await fixture.whenStable();
const inputDebugElement = fixture.debugElement.query(By.css('#upload-id'));
inputDebugElement.triggerEventHandler('change', { target: { files: [filePngFake, filJpgFake] } });
fixture.whenStable().then(() => {
fixture.detectChanges();
inputElement = <HTMLInputElement> element.querySelector('#upload-id');
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(uploadWidgetComponent.field.value).not.toBeNull();
expect(uploadWidgetComponent.field.value.length).toBe(2);
expect(uploadWidgetComponent.field.value[0].id).toBe(1155);
expect(uploadWidgetComponent.field.value[1].id).toBe(1156);
expect(uploadWidgetComponent.field.json.value.length).toBe(2);
});
}));
fixture.detectChanges();
await fixture.whenStable();
it('should show all the file uploaded on multiple field', async(() => {
inputElement = <HTMLInputElement> element.querySelector('#upload-id');
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(uploadWidgetComponent.field.value).not.toBeNull();
expect(uploadWidgetComponent.field.value.length).toBe(2);
expect(uploadWidgetComponent.field.value[0].id).toBe(1155);
expect(uploadWidgetComponent.field.value[1].id).toBe(1156);
expect(uploadWidgetComponent.field.json.value.length).toBe(2);
});
it('should show all the file uploaded on multiple field', async () => {
uploadWidgetComponent.field.params.multiple = true;
uploadWidgetComponent.field.value.push(fakeJpgAnswer);
uploadWidgetComponent.field.value.push(fakePngAnswer);
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-1156');
const pngElement = element.querySelector('#file-1155');
expect(jpegElement).not.toBeNull();
expect(pngElement).not.toBeNull();
expect(jpegElement.textContent).toBe('a_jpg_file.jpg');
expect(pngElement.textContent).toBe('a_png_file.png');
});
}));
const jpegElement = element.querySelector('#file-1156');
const pngElement = element.querySelector('#file-1155');
expect(jpegElement).not.toBeNull();
expect(pngElement).not.toBeNull();
expect(jpegElement.textContent).toBe('a_jpg_file.jpg');
expect(pngElement.textContent).toBe('a_png_file.png');
});
it('should show correctly the file name when is formed with special characters', async(() => {
it('should show correctly the file name when is formed with special characters', async () => {
uploadWidgetComponent.field.value.push(fakeCreationFile('±!@#$%^&*()_+{}:”|<>?§™£-=[];\\,./.jpg', 10));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-10');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe(`±!@#$%^&*()_+{}:”|<>?§™£-=[];\\,./.jpg`);
});
}));
const jpegElement = element.querySelector('#file-10');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe(`±!@#$%^&*()_+{}:”|<>?§™£-=[];\\,./.jpg`);
});
it('should show correctly the file name when is formed with Arabic characters', async(() => {
it('should show correctly the file name when is formed with Arabic characters', async () => {
const name = 'غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg';
uploadWidgetComponent.field.value.push(fakeCreationFile(name, 11));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-11');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg');
});
}));
const jpegElement = element.querySelector('#file-11');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('غ ظ ض ذ خ ث ت ش ر ق ص ف ع س ن م ل ك ي ط ح ز و ه د ج ب ا.jpg');
});
it('should show correctly the file name when is formed with French characters', async(() => {
it('should show correctly the file name when is formed with French characters', async () => {
// cspell: disable-next
uploadWidgetComponent.field.value.push(fakeCreationFile('Àâæçéèêëïîôœùûüÿ.jpg', 12));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-12');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('Àâæçéèêëïîôœùûüÿ.jpg');
});
}));
const jpegElement = element.querySelector('#file-12');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('Àâæçéèêëïîôœùûüÿ.jpg');
});
it('should show correctly the file name when is formed with Greek characters', async(() => {
it('should show correctly the file name when is formed with Greek characters', async () => {
// cspell: disable-next
uploadWidgetComponent.field.value.push(fakeCreationFile('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg', 13));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-13');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg');
});
}));
const jpegElement = element.querySelector('#file-13');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('άέήίϊϊΐόύϋΰώθωερτψυιοπασδφγηςκλζχξωβνμ.jpg');
});
it('should show correctly the file name when is formed with Polish accented characters', async(() => {
it('should show correctly the file name when is formed with Polish accented characters', async () => {
uploadWidgetComponent.field.value.push(fakeCreationFile('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg', 14));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-14');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg');
});
}));
const jpegElement = element.querySelector('#file-14');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('Ą Ć Ę Ł Ń Ó Ś Ź Żą ć ę ł ń ó ś ź ż.jpg');
});
it('should show correctly the file name when is formed with Spanish accented characters', async(() => {
it('should show correctly the file name when is formed with Spanish accented characters', async () => {
uploadWidgetComponent.field.value.push(fakeCreationFile('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg', 15));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-15');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg');
});
}));
const jpegElement = element.querySelector('#file-15');
expect(jpegElement).not.toBeNull();
expect(jpegElement.textContent).toBe('á, é, í, ó, ú, ñ, Ñ, ü, Ü, ¿, ¡. Á, É, Í, Ó, Ú.jpg');
});
it('should show correctly the file name when is formed with Swedish characters', async(() => {
it('should show correctly the file name when is formed with Swedish characters', async () => {
// cspell: disable-next
uploadWidgetComponent.field.value.push(fakeCreationFile('Äåéö.jpg', 16));
fixture.detectChanges();
await fixture.whenStable();
fixture.whenStable().then(() => {
fixture.detectChanges();
const jpegElement = element.querySelector('#file-16');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('Äåéö.jpg');
});
}));
const jpegElement = element.querySelector('#file-16');
expect(jpegElement).not.toBeNull();
// cspell: disable-next
expect(jpegElement.textContent).toBe('Äåéö.jpg');
});
it('should remove file from field value', async(() => {
it('should remove file from field value', async () => {
uploadWidgetComponent.field.params.multiple = true;
uploadWidgetComponent.field.value.push(fakeJpgAnswer);
uploadWidgetComponent.field.value.push(fakePngAnswer);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const buttonElement = <HTMLButtonElement> element.querySelector('#file-1156-remove');
buttonElement.click();
fixture.detectChanges();
const jpegElement = element.querySelector('#file-1156');
expect(jpegElement).toBeNull();
expect(uploadWidgetComponent.field.value.length).toBe(1);
});
}));
fixture.detectChanges();
await fixture.whenStable();
const buttonElement = <HTMLButtonElement> element.querySelector('#file-1156-remove');
buttonElement.click();
fixture.detectChanges();
const jpegElement = element.querySelector('#file-1156');
expect(jpegElement).toBeNull();
expect(uploadWidgetComponent.field.value.length).toBe(1);
});
it('should emit form content clicked event on icon click', (done) => {
spyOn(contentService, 'getContentPreview').and.returnValue(of(new Blob()));

View File

@@ -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 { Validators } from '@angular/forms';
import { Router } from '@angular/router';
@@ -67,7 +67,7 @@ describe('LoginComponent', () => {
]
});
beforeEach(async(() => {
beforeEach(fakeAsync(() => {
fixture = TestBed.createComponent(LoginComponent);
element = fixture.nativeElement;
@@ -93,7 +93,7 @@ describe('LoginComponent', () => {
fixture.destroy();
});
function loginWithCredentials(username, password) {
function loginWithCredentials(username: string, password: string) {
usernameInput.value = username;
passwordInput.value = password;
@@ -175,7 +175,7 @@ describe('LoginComponent', () => {
expect(router.navigateByUrl).toHaveBeenCalledWith('some-route');
});
it('should update user preferences upon login', async(() => {
it('should update user preferences upon login', fakeAsync(() => {
spyOn(userPreferences, 'setStoragePrefix').and.callThrough();
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
@@ -465,7 +465,7 @@ describe('LoginComponent', () => {
loginWithCredentials('fake-username-CORS-error', 'fake-password');
});
it('should return CSRF error when server CSRF error occurs', async(() => {
it('should return CSRF error when server CSRF error occurs', fakeAsync(() => {
spyOn(authService, 'login')
.and.returnValue(throwError({ message: 'ERROR: Invalid CSRF-token', status: 403 }));
@@ -480,7 +480,7 @@ describe('LoginComponent', () => {
loginWithCredentials('fake-username-CSRF-error', 'fake-password');
}));
it('should return ECM read-only error when error occurs', async(() => {
it('should return ECM read-only error when error occurs', fakeAsync(() => {
spyOn(authService, 'login')
.and.returnValue(
throwError(
@@ -544,7 +544,7 @@ describe('LoginComponent', () => {
loginWithCredentials('fake-username', 'fake-password');
});
it('should emit success event after the login has succeeded and discard password', async(() => {
it('should emit success event after the login has succeeded and discard password', fakeAsync(() => {
spyOn(authService, 'login').and.returnValue(of({ type: 'type', ticket: 'ticket' }));
component.success.subscribe((event) => {
@@ -559,7 +559,7 @@ describe('LoginComponent', () => {
loginWithCredentials('fake-username', 'fake-password');
}));
it('should emit error event after the login has failed', async(() => {
it('should emit error event after the login has failed', fakeAsync(() => {
spyOn(authService, 'login').and.returnValue(throwError('Fake server error'));
component.error.subscribe((error) => {
@@ -596,7 +596,7 @@ describe('LoginComponent', () => {
expect(element.querySelector('#password').type).toEqual('password');
});
it('should emit only the username and not the password as part of the executeSubmit', async(() => {
it('should emit only the username and not the password as part of the executeSubmit', fakeAsync(() => {
spyOn(alfrescoApiService.getInstance(), 'login').and.returnValue(Promise.resolve());
component.executeSubmit.subscribe((res) => {
@@ -620,20 +620,18 @@ describe('LoginComponent', () => {
alfrescoApiService.reset();
});
it('should not show login username and password if SSO implicit flow is active', async(() => {
it('should not show login username and password if SSO implicit flow is active', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
component.ngOnInit();
fixture.detectChanges();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#username')).toBeNull();
expect(element.querySelector('#password')).toBeNull();
});
}));
it('should not render the implicitFlow button in case silentLogin is enabled', async(() => {
it('should not render the implicitFlow button in case silentLogin is enabled', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2 = <OauthConfigModel> { implicitFlow: true, silentLogin: true };
@@ -649,7 +647,7 @@ describe('LoginComponent', () => {
}));
it('should render the implicitFlow button in case silentLogin is disabled', async(() => {
it('should render the implicitFlow button in case silentLogin is disabled', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
component.ngOnInit();
@@ -661,7 +659,7 @@ describe('LoginComponent', () => {
}));
it('should not show the login base auth button', async(() => {
it('should not show the login base auth button', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
component.ngOnInit();
@@ -672,7 +670,7 @@ describe('LoginComponent', () => {
});
}));
it('should show the login SSO button', async(() => {
it('should show the login SSO button', fakeAsync(() => {
spyOn(authService, 'isOauth').and.returnValue(true);
component.ngOnInit();

View File

@@ -16,7 +16,7 @@
*/
import { TimeAgoPipe } from './time-ago.pipe';
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { UserPreferencesService } from '../services/user-preferences.service';
import { setupTestBed } from '../testing/setup-test-bed';
@@ -36,11 +36,11 @@ describe('TimeAgoPipe', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
userPreferences = TestBed.inject(UserPreferencesService);
spyOn(userPreferences, 'select').and.returnValue(of(''));
pipe = new TimeAgoPipe(userPreferences, TestBed.inject(AppConfigService));
}));
});
it('should return time difference for a given date', () => {
const date = new Date();
@@ -59,11 +59,11 @@ describe('TimeAgoPipe', () => {
describe('When a locale is given', () => {
it('should return a localised message', async(() => {
it('should return a localised message', () => {
const date = new Date();
const transformedDate = pipe.transform(date, 'de');
/* cspell:disable-next-line */
expect(transformedDate).toBe('vor ein paar Sekunden');
}));
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { ComponentFixture, TestBed, discardPeriodicTasks, fakeAsync, tick, async } from '@angular/core/testing';
import { ComponentFixture, TestBed, discardPeriodicTasks, fakeAsync, tick } from '@angular/core/testing';
import { CoreTestingModule } from '../testing/core.testing.module';
import { SearchTextInputComponent } from './search-text-input.component';
import { DebugElement } from '@angular/core';
@@ -55,12 +55,17 @@ describe('SearchTextInputComponent', () => {
describe('component rendering', () => {
it('should display a search input field when specified', async(() => {
it('should display a search input field when specified', async () => {
fixture.detectChanges();
await fixture.whenStable();
component.inputType = 'search';
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelectorAll('input[type="search"]').length).toBe(1);
}));
});
});
describe('expandable option false', () => {
@@ -246,10 +251,13 @@ describe('SearchTextInputComponent', () => {
discardPeriodicTasks();
}));
it('should set browser autocomplete to on when configured', async(() => {
it('should set browser autocomplete to on when configured', async () => {
component.autocomplete = true;
fixture.detectChanges();
await fixture.whenStable();
expect(element.querySelector('#adf-control-input').getAttribute('autocomplete')).toBe('on');
}));
});
});
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardBpm } from './auth-guard-bpm.service';
import { AuthenticationService } from './authentication.service';
@@ -51,7 +51,7 @@ describe('AuthGuardService BPM', () => {
appConfigService.config.oauth2 = {};
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async () => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -72,33 +72,33 @@ describe('AuthGuardService BPM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
}));
});
it('if the alfresco js api is logged in should canActivate be true', async(async () => {
it('if the alfresco js api is logged in should canActivate be true', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async () => {
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
appConfigService.config.auth.withCredentials = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is NOT logged in should canActivate be false', async(async () => {
it('if the alfresco js api is NOT logged in should canActivate be false', async () => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
}));
});
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async () => {
it('if the alfresco js api is NOT logged in should trigger a redirect event', async () => {
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigateByUrl');
@@ -107,31 +107,31 @@ describe('AuthGuardService BPM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async () => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = false;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async () => {
it('should redirect url if NOT logged in and isOAuth but no silentLogin configured', async () => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isBpmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
appConfigService.config.oauth2.silentLogin = undefined;
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
const route = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should set redirect url', async(() => {
it('should set redirect url', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
@@ -142,9 +142,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url'
});
expect(authService.getRedirect()).toEqual('some-url');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url;q=123' };
@@ -155,9 +155,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url;q=123'
});
expect(authService.getRedirect()).toEqual('some-url;q=123');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: '/' };
@@ -168,9 +168,9 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: '/'
});
expect(authService.getRedirect()).toEqual('/');
}));
});
it('should get redirect url from config if there is one configured', async(() => {
it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
@@ -182,7 +182,7 @@ describe('AuthGuardService BPM', () => {
provider: 'BPM', url: 'some-url'
});
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
}));
});
it('should to close the material dialog if is redirect to the login', () => {
const materialDialog = TestBed.inject(MatDialog);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardEcm } from './auth-guard-ecm.service';
import { AuthenticationService } from './authentication.service';
@@ -51,31 +51,31 @@ describe('AuthGuardService ECM', () => {
appConfigService.config.oauth2 = {};
});
it('if the alfresco js api is logged in should canActivate be true', async(async() => {
it('if the alfresco js api is logged in should canActivate be true', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(true);
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async(async() => {
it('if the alfresco js api is configured with withCredentials true should canActivate be true', async() => {
spyOn(authService, 'isBpmLoggedIn').and.returnValue(true);
appConfigService.config.auth.withCredentials = true;
const route: RouterStateSnapshot = <RouterStateSnapshot> {url : 'some-url'};
expect(await authGuard.canActivate(null, route)).toBeTruthy();
}));
});
it('if the alfresco js api is NOT logged in should canActivate be false', async(async() => {
it('if the alfresco js api is NOT logged in should canActivate be false', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
expect(await authGuard.canActivate(null, route)).toBeFalsy();
}));
});
it('if the alfresco js api is NOT logged in should trigger a redirect event', async(async() => {
it('if the alfresco js api is NOT logged in should trigger a redirect event', async() => {
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigateByUrl');
@@ -84,9 +84,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/login?redirectUrl=some-url'));
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async(async() => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuthWithoutSilentLogin', async() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -95,9 +95,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async(async() => {
it('should redirect url if the alfresco js api is NOT logged in and isOAuth with silentLogin', async() => {
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
spyOn(authService, 'isPublicUrl').and.returnValue(false);
@@ -116,9 +116,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(authService.ssoImplicitLogin).toHaveBeenCalledTimes(1);
}));
});
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async(async() => {
it('should not redirect url if NOT logged in and isOAuth but no silentLogin configured', async() => {
spyOn(router, 'navigateByUrl').and.stub();
spyOn(authService, 'isEcmLoggedIn').and.returnValue(false);
spyOn(authService, 'isOauth').and.returnValue(true);
@@ -127,9 +127,9 @@ describe('AuthGuardService ECM', () => {
expect(await authGuard.canActivate(null, route)).toBeFalsy();
expect(router.navigateByUrl).toHaveBeenCalled();
}));
});
it('should set redirect navigation commands', async(() => {
it('should set redirect navigation commands', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url' };
@@ -140,9 +140,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url'
});
expect(authService.getRedirect()).toEqual('some-url');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: 'some-url;q=123' };
@@ -153,9 +153,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url;q=123'
});
expect(authService.getRedirect()).toEqual('some-url;q=123');
}));
});
it('should set redirect navigation commands with query params', async(() => {
it('should set redirect navigation commands with query params', () => {
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
const route: RouterStateSnapshot = <RouterStateSnapshot> { url: '/' };
@@ -166,9 +166,9 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: '/'
});
expect(authService.getRedirect()).toEqual('/');
}));
});
it('should get redirect url from config if there is one configured', async(() => {
it('should get redirect url from config if there is one configured', () => {
appConfigService.config.loginRoute = 'fakeLoginRoute';
spyOn(authService, 'setRedirect').and.callThrough();
spyOn(router, 'navigateByUrl').and.stub();
@@ -180,7 +180,7 @@ describe('AuthGuardService ECM', () => {
provider: 'ECM', url: 'some-url'
});
expect(router.navigateByUrl).toHaveBeenCalledWith(router.parseUrl('/fakeLoginRoute?redirectUrl=some-url'));
}));
});
it('should to close the material dialog if is redirect to the login', () => {
const materialDialog = TestBed.inject(MatDialog);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { CommentModel } from '../models/comment.model';
import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../mock/comment-process-service.mock';
import { CommentProcessService } from './comment-process.service';
@@ -65,37 +65,40 @@ describe('Comment ProcessService Service', () => {
.returnValue(Promise.resolve({data: [fakeProcessComment, fakeProcessComment]}));
});
it('should return the correct number of comments', async(() => {
it('should return the correct number of comments', (done) => {
service.getProcessInstanceComments(processId).subscribe((tasks) => {
expect(tasks.length).toBe(2);
done();
});
}));
});
it('should return the correct comment data', async(() => {
it('should return the correct comment data', (done) => {
service.getProcessInstanceComments(processId).subscribe((comments) => {
const comment: any = comments[0];
expect(comment.id).toBe(fakeProcessComment.id);
expect(comment.created).toBe(fakeProcessComment.created);
expect(comment.message).toBe(fakeProcessComment.message);
expect(comment.createdBy.id).toBe(fakeProcessComment.createdBy.id);
done();
});
}));
});
it('should call service to fetch process instance comments', () => {
service.getProcessInstanceComments(processId);
expect(getProcessInstanceComments).toHaveBeenCalledWith(processId);
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
getProcessInstanceComments = getProcessInstanceComments.and.returnValue(Promise.reject(null));
service.getProcessInstanceComments(processId).subscribe(
() => {
},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
@@ -117,25 +120,26 @@ describe('Comment ProcessService Service', () => {
}, processId);
});
it('should return the created comment', async(() => {
it('should return the created comment', (done) => {
service.addProcessInstanceComment(processId, message).subscribe((comment) => {
expect(comment.id).toBe(fakeProcessComment.id);
expect(comment.created).toBe(fakeProcessComment.created);
expect(comment.message).toBe(fakeProcessComment.message);
expect(comment.createdBy).toBe(fakeProcessComment.createdBy);
done();
});
}));
});
it('should return a default error if no data is returned by the API', async(() => {
it('should return a default error if no data is returned by the API', (done) => {
addProcessInstanceComment = addProcessInstanceComment.and.returnValue(Promise.reject(null));
service.addProcessInstanceComment(processId, message).subscribe(
() => {
},
() => {},
(res) => {
expect(res).toBe('Server error');
done();
}
);
}));
});
});
});

View File

@@ -16,7 +16,7 @@
*/
import { EventEmitter } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.model';
import { AppConfigModule } from '../app-config/app-config.module';
import { UploadService } from './upload.service';
@@ -447,32 +447,32 @@ describe('UploadService', () => {
expect(result[0]).toBe(file2);
});
it('should call onUploadDeleted if file was deleted', async(() => {
it('should call onUploadDeleted if file was deleted', () => {
const file = <any> ({ status: FileUploadStatus.Deleted });
spyOn(service.fileUploadDeleted, 'next');
service.cancelUpload(file);
expect(service.fileUploadDeleted.next).toHaveBeenCalled();
}));
});
it('should call fileUploadError if file has error status', async(() => {
it('should call fileUploadError if file has error status', () => {
const file = <any> ({ status: FileUploadStatus.Error });
spyOn(service.fileUploadError, 'next');
service.cancelUpload(file);
expect(service.fileUploadError.next).toHaveBeenCalled();
}));
});
it('should call fileUploadCancelled if file is in pending', async(() => {
it('should call fileUploadCancelled if file is in pending', () => {
const file = <any> ({ status: FileUploadStatus.Pending });
spyOn(service.fileUploadCancelled, 'next');
service.cancelUpload(file);
expect(service.fileUploadCancelled.next).toHaveBeenCalled();
}));
});
it('Should not pass rendition if it is disabled', () => {
mockProductInfo.next({ status: { isThumbnailGenerationEnabled: false } } as EcmProductVersionModel);

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, async } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
import { AppConfigService } from '../app-config/app-config.service';
import { StorageService } from './storage.service';
@@ -177,7 +177,7 @@ describe('UserPreferencesService', () => {
describe('with language config', () => {
it('should store default textOrientation based on language', async(() => {
it('should store default textOrientation based on language', () => {
appConfig.config.languages = [
{
key: 'fake-locale-config'
@@ -187,9 +187,9 @@ describe('UserPreferencesService', () => {
alfrescoApiService.initialize();
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe('ltr');
}));
});
it('should store textOrientation based on language config direction', async(() => {
it('should store textOrientation based on language config direction', () => {
appConfig.config.languages = [
{
key: 'fake-locale-config',
@@ -200,9 +200,9 @@ describe('UserPreferencesService', () => {
alfrescoApiService.initialize();
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe('rtl');
}));
});
it('should not store textOrientation based on language ', async(() => {
it('should not store textOrientation based on language ', () => {
appConfig.config.languages = [
{
key: 'fake-locale-browser'
@@ -212,7 +212,7 @@ describe('UserPreferencesService', () => {
const textOrientation = preferences.getPropertyKey('textOrientation');
expect(storage.getItem(textOrientation)).toBe(null);
}));
});
it('should default to browser locale for textOrientation when locale is not defined in configuration', (done) => {
appConfig.config.languages = [

View File

@@ -16,7 +16,7 @@
*/
import { Component } 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 { setupTestBed } from '@alfresco/adf-core';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
@@ -58,16 +58,16 @@ describe('EmptyContentComponent', () => {
translateService = TestBed.inject(TranslateService);
});
it('should render custom title', async(() => {
it('should render custom title', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
});
}));
await fixture.whenStable();
it('should translate title and subtitle', async(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
});
it('should translate title and subtitle', async () => {
spyOn(translateService, 'get').and.callFake((key: string) => {
switch (key) {
case 'CUSTOM_TITLE':
@@ -80,17 +80,17 @@ describe('EmptyContentComponent', () => {
});
fixture.detectChanges();
fixture.whenStable().then(() => {
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
await fixture.whenStable();
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
expect(subtitle).toBeDefined('subtitle element not found');
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
});
}));
expect(title).toBeDefined('title element not found');
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
expect(subtitle).toBeDefined('subtitle element not found');
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
});
it('should render multiple subtitle elements', () => {
const subTitles = fixture.debugElement.queryAll(By.css('.adf-empty-content__text'));

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { CoreTestingModule } from '../../testing/core.testing.module';
import { ErrorContentComponent } from './error-content.component';
import { TranslationService } from '../../services/translation.service';
@@ -40,7 +40,6 @@ describe('ErrorContentComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe(' with an undefined error', () => {
@@ -55,56 +54,57 @@ describe('ErrorContentComponent', () => {
]
});
it('should create error component', async(() => {
it('should render error code', async () => {
fixture.detectChanges();
expect(errorContentComponent).toBeTruthy();
}));
await fixture.whenStable();
it('should render error code', async(() => {
fixture.detectChanges();
const errorContentElement = element.querySelector('.adf-error-content-code');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error title', async(() => {
it('should render error title', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-title');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error description', async(() => {
it('should render error description', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-description');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should render error description', async(() => {
it('should render error description', async () => {
fixture.detectChanges();
await fixture.whenStable();
const errorContentElement = element.querySelector('.adf-error-content-description');
expect(errorContentElement).not.toBeNull();
expect(errorContentElement).toBeDefined();
}));
});
it('should hide secondary button if this one has no value', async(() => {
spyOn(translateService, 'instant').and.callFake(() => {
return '';
});
it('should hide secondary button if this one has no value', async () => {
spyOn(translateService, 'instant').and.returnValue('');
fixture.detectChanges();
fixture.whenStable().then(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).toBeNull();
});
}));
await fixture.whenStable();
it('should navigate to the default error UNKNOWN if it does not find the error', async(() => {
const errorContentElement = element.querySelector('.adf-error-content-description-link');
expect(errorContentElement).toBeNull();
});
it('should navigate to the default error UNKNOWN if it does not find the error', async () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.errorCode).toBe('UNKNOWN');
});
}));
await fixture.whenStable();
expect(errorContentComponent.errorCode).toBe('UNKNOWN');
});
});
describe(' with a specific error', () => {
@@ -119,12 +119,12 @@ describe('ErrorContentComponent', () => {
]
});
it('should navigate to an error given by the route params', async(() => {
it('should navigate to an error given by the route params', async () => {
spyOn(translateService, 'instant').and.returnValue(of('404'));
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(errorContentComponent.errorCodeTranslated).toBe('404');
});
}));
await fixture.whenStable();
expect(errorContentComponent.errorCodeTranslated).toBe('404');
});
});
});

View File

@@ -18,7 +18,7 @@
import { Location } from '@angular/common';
import { SpyLocation } from '@angular/common/testing';
import { Component } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick, async } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { AlfrescoApiService, RenditionsService } from '../../services';
import { throwError } from 'rxjs';
@@ -715,7 +715,7 @@ describe('ViewerComponent', () => {
});
});
it('should emit `showViewerChange` event on close', async(() => {
it('should emit `showViewerChange` event on close', async () => {
spyOn(component.showViewerChange, 'emit');
@@ -723,11 +723,10 @@ describe('ViewerComponent', () => {
button.click();
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(component.showViewerChange.emit).toHaveBeenCalled();
});
}));
await fixture.whenStable();
expect(component.showViewerChange.emit).toHaveBeenCalled();
});
it('should not render close viewer button if it is a shared link', (done) => {
spyOn(alfrescoApiService.getInstance().core.sharedlinksApi, 'getSharedLink')