fix random test failing part 2 (#3395)

* fix random failing test core search/comment/auth/user

* fix node delete directive

* fix lint issues

* node restore fix

* fix comment test

* remove fdescribe

* fix tests and tslint

* fix upload test

* unsubscribe success event task test

* copy comment object during test

* use the data pipe performance improvement and standard usage

* uncomment random test

* fix comment date random failing test

* disposable unsubscribe

* fix start process

* remove fdescribe

* change start process test and remove commented code

* fix error event check double click

* clone object form test

* refactor date time test

* fix service mock

* fix test dropdown and context

* git hook lint

* fix language test

* unsubscribe documentlist event test

* fix disposable error

* fix console log service error document list

* unusbscribe search test

* clear input field

* remove wrong test
This commit is contained in:
Eugenio Romano
2018-05-29 11:18:17 +02:00
committed by Denys Vuika
parent 22006395c7
commit eb0f91c5db
43 changed files with 4475 additions and 4332 deletions

View File

@@ -64,7 +64,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 doesn\'t have a proper boolean value set', () => {
component.editable = true;
component.property.value = undefined;
component.property.editable = false;
@@ -77,7 +77,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value).toBeNull();
});
it('should render the label and value if the property is NOT editable but has a proper boolean value set' , () => {
it('should render the label and value if the property is NOT editable but has a proper boolean value set', () => {
component.editable = true;
component.property.value = false;
component.property.editable = false;
@@ -179,7 +179,7 @@ describe('CardViewBoolItemComponent', () => {
const cardViewUpdateService = TestBed.get(CardViewUpdateService);
spyOn(cardViewUpdateService, 'update');
component.changed(<MatCheckboxChange> {checked: true});
component.changed(<MatCheckboxChange> { checked: true });
expect(cardViewUpdateService.update).toHaveBeenCalledWith(component.property, true);
});
@@ -187,7 +187,7 @@ describe('CardViewBoolItemComponent', () => {
it('should update the property value after a changed', async(() => {
component.property.value = true;
component.changed(<MatCheckboxChange> {checked: false});
component.changed(<MatCheckboxChange> { checked: false });
fixture.whenStable().then(() => {
expect(component.property.value).toBe(false);
@@ -199,10 +199,11 @@ describe('CardViewBoolItemComponent', () => {
component.property.value = false;
fixture.detectChanges();
cardViewUpdateService.itemUpdated$.subscribe(
let disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.changed).toEqual({ boolkey: true });
disposableUpdate.unsubscribe();
done();
}
);

View File

@@ -63,7 +63,7 @@ describe('CardViewDateItemComponent', () => {
});
it('should NOT render the default as value if the value is empty, editable:false and displayEmpty is false', () => {
component.property = new CardViewDateItemModel ({
component.property = new CardViewDateItemModel({
label: 'Date label',
value: '',
key: 'datekey',
@@ -81,7 +81,7 @@ describe('CardViewDateItemComponent', () => {
});
it('should render the default as value if the value is empty, editable:false and displayEmpty is true', () => {
component.property = new CardViewDateItemModel ({
component.property = new CardViewDateItemModel({
label: 'Date label',
value: '',
key: 'datekey',
@@ -99,7 +99,7 @@ describe('CardViewDateItemComponent', () => {
});
it('should render the default as value if the value is empty and editable:true', () => {
component.property = new CardViewDateItemModel ({
component.property = new CardViewDateItemModel({
label: 'Date label',
value: '',
key: 'datekey',
@@ -176,15 +176,16 @@ describe('CardViewDateItemComponent', () => {
const expectedDate = moment('Jul 10 2017', 'MMM DD YY');
fixture.detectChanges();
cardViewUpdateService.itemUpdated$.subscribe(
let disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.changed).toEqual({datekey: expectedDate.toDate()});
expect(updateNotification.changed).toEqual({ datekey: expectedDate.toDate() });
disposableUpdate.unsubscribe();
done();
}
);
component.onDateChanged({value: expectedDate});
component.onDateChanged({ value: expectedDate });
});
it('should update the propery\'s value after a succesful update attempt', async(() => {
@@ -194,7 +195,7 @@ describe('CardViewDateItemComponent', () => {
const expectedDate = moment('Jul 10 2017', 'MMM DD YY');
fixture.detectChanges();
component.onDateChanged({value: expectedDate});
component.onDateChanged({ value: expectedDate });
fixture.whenStable().then(
(updateNotification) => {

View File

@@ -118,11 +118,12 @@ describe('CardViewMapItemComponent', () => {
fixture.detectChanges();
let value: any = element.querySelector('.adf-mapitem-clickable-value');
service.itemClicked$.subscribe((response) => {
let disposableUpdate = service.itemClicked$.subscribe((response) => {
expect(response.target).not.toBeNull();
expect(response.target.type).toEqual('map');
expect(response.target.clickable).toBeTruthy();
expect(response.target.displayValue).toEqual('fakeProcessName');
disposableUpdate.unsubscribe();
done();
});

View File

@@ -35,7 +35,7 @@ describe('CardViewTextItemComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CardViewTextItemComponent);
component = fixture.componentInstance;
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: 'Lorem ipsum',
key: 'textkey',
@@ -63,7 +63,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should NOT render the default as value if the value is empty, editable is false and displayEmpty is false', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -79,7 +79,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should render the default as value if the value is empty, editable is false and displayEmpty is true', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -95,7 +95,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should render the default as value if the value is empty and editable true', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -111,7 +111,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should NOT render the default as value if the value is empty, clickable is false and displayEmpty is false', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -127,7 +127,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should render the default as value if the value is empty, clickable is false and displayEmpty is true', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -143,7 +143,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should render the default as value if the value is empty and clickable true', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -158,7 +158,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should render the edit icon in case of clickable true and icon defined', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -174,7 +174,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should not render the edit icon in case of clickable true and icon undefined', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -188,7 +188,7 @@ describe('CardViewTextItemComponent', () => {
});
it('should not render the edit icon in case of clickable false and icon defined', () => {
component.property = new CardViewTextItemModel ({
component.property = new CardViewTextItemModel({
label: 'Text label',
value: '',
key: 'textkey',
@@ -314,10 +314,11 @@ describe('CardViewTextItemComponent', () => {
const expectedText = 'changed text';
fixture.detectChanges();
cardViewUpdateService.itemUpdated$.subscribe(
let disposableUpdate = cardViewUpdateService.itemUpdated$.subscribe(
(updateNotification) => {
expect(updateNotification.target).toBe(component.property);
expect(updateNotification.changed).toEqual({ textkey: expectedText });
disposableUpdate.unsubscribe();
done();
}
);

View File

@@ -41,7 +41,8 @@ export class CardViewTextItemComponent implements OnChanges {
editedValue: string;
errorMessages: string[];
constructor(private cardViewUpdateService: CardViewUpdateService) {}
constructor(private cardViewUpdateService: CardViewUpdateService) {
}
ngOnChanges(): void {
this.editedValue = this.property.value;
@@ -83,7 +84,7 @@ export class CardViewTextItemComponent implements OnChanges {
update(): void {
if (this.property.isValid(this.editedValue)) {
this.cardViewUpdateService.update(this.property, this.editedValue );
this.cardViewUpdateService.update(this.property, this.editedValue);
this.property.value = this.editedValue;
this.setEditMode(false);
} else {

View File

@@ -25,7 +25,7 @@
{{comment.message}}
</div>
<div matLine id="comment-time" class="adf-comment-message-time">
{{transformDate(comment.created)}}
{{ comment.created | adfTimeAgo: currentLocale }}
</div>
</div>
</mat-list-item>

View File

@@ -31,25 +31,25 @@ const testUser: UserProcessModel = new UserProcessModel({
lastName: 'User',
email: 'tu@domain.com'
});
const testDate = new Date();
const processCommentOne: CommentModel = new CommentModel({
id: 1,
message: 'Test Comment',
created: testDate.toDateString(),
created: new Date(),
createdBy: testUser
});
const processCommentTwo: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: testUser
});
const contentCommentUserPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
@@ -65,7 +65,7 @@ const contentCommentUserPictureDefined: CommentModel = new CommentModel({
const processCommentUserPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
@@ -78,7 +78,7 @@ const processCommentUserPictureDefined: CommentModel = new CommentModel({
const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
enabled: true,
firstName: 'some',
@@ -93,7 +93,7 @@ const contentCommentUserNoPictureDefined: CommentModel = new CommentModel({
const processCommentUserNoPictureDefined: CommentModel = new CommentModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
created: new Date(),
createdBy: {
id: '1',
firstName: 'Test',
@@ -133,13 +133,12 @@ describe('CommentListComponent', () => {
});
it('should emit row click event', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
commentList.clickRow.subscribe(selectedComment => {
expect(selectedComment.id).toEqual(1);
expect(selectedComment.message).toEqual('Test Comment');
expect(selectedComment.createdBy).toEqual(testUser);
expect(selectedComment.created).toEqual(testDate.toDateString());
expect(selectedComment.isSelected).toBeTruthy();
});
@@ -152,8 +151,10 @@ describe('CommentListComponent', () => {
it('should deselect the previous selected comment when a new one is clicked', async(() => {
processCommentOne.isSelected = true;
commentList.selectedComment = processCommentOne;
commentList.comments = [processCommentOne, processCommentTwo];
let commentOne = Object.assign({}, processCommentOne);
let commentTwo = Object.assign({}, processCommentTwo);
commentList.selectedComment = commentOne;
commentList.comments = [commentOne, commentTwo];
commentList.clickRow.subscribe(selectedComment => {
fixture.detectChanges();
@@ -178,7 +179,7 @@ describe('CommentListComponent', () => {
}));
it('should show comment message when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -190,7 +191,7 @@ describe('CommentListComponent', () => {
}));
it('should show comment user when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -201,42 +202,35 @@ describe('CommentListComponent', () => {
});
}));
it('should show comment date time when input is given', async(() => {
commentList.comments = [processCommentOne];
fixture.detectChanges();
it('comment date time should start with few seconds ago when comment date is few seconds ago', async(() => {
let commenFewSecond = Object.assign({}, processCommentOne);
commenFewSecond.created = new Date();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-time');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(commentList.transformDate(testDate.toDateString()));
expect(fixture.nativeElement.querySelector('#comment-time:empty')).toBeNull();
});
}));
it('comment date time should start with Today when comment date is today', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [commenFewSecond];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Today');
expect(element.innerText).toContain('a few seconds ago');
});
}));
it('comment date time should start with Yesterday when comment date is yesterday', async(() => {
processCommentOne.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [processCommentOne];
let commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [commentOld];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Yesterday');
expect(element.innerText).toContain('a day ago');
});
}));
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => {
processCommentOne.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [processCommentOne];
let commentOld = Object.assign({}, processCommentOne);
commentOld.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [commentOld];
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -247,7 +241,7 @@ describe('CommentListComponent', () => {
}));
it('should show user icon when input is given', async(() => {
commentList.comments = [processCommentOne];
commentList.comments = [Object.assign({}, processCommentOne)];
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@@ -19,7 +19,7 @@ import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angu
import { CommentModel } from '../models/comment.model';
import { EcmUserService } from '../userinfo/services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { DatePipe } from '@angular/common';
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
@Component({
selector: 'adf-comment-list',
@@ -40,8 +40,14 @@ export class CommentListComponent {
selectedComment: CommentModel;
constructor(private datePipe: DatePipe, public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService) {
currentLocale;
constructor(public peopleProcessService: PeopleProcessService,
public ecmUserService: EcmUserService,
public userPreferenceService: UserPreferencesService) {
userPreferenceService.select(UserPreferenceValues.Locale).subscribe((locale) => {
this.currentLocale = locale;
});
}
selectComment(comment: CommentModel): void {
@@ -78,23 +84,6 @@ export class CommentListComponent {
}
}
transformDate(aDate: string): string {
let formattedDate: string;
let givenDate = Number.parseInt(this.datePipe.transform(aDate, 'yMMdd'));
let today = Number.parseInt(this.datePipe.transform(Date.now(), 'yMMdd'));
if (givenDate === today) {
formattedDate = 'Today, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
let yesterday = Number.parseInt(this.datePipe.transform(Date.now() - 24 * 3600 * 1000, 'yMMdd'));
if (givenDate === yesterday) {
formattedDate = 'Yesterday, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
formattedDate = this.datePipe.transform(aDate, 'MMM dd y, hh:mm a');
}
}
return formattedDate;
}
private isAContentUsers(user: any): boolean {
return user.avatarId;
}

View File

@@ -22,12 +22,14 @@ import { MaterialModule } from '../material.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DataColumnModule } from '../data-column/data-column.module';
import { DataTableModule } from '../datatable/datatable.module';
import { PipeModule } from '../pipes/pipe.module';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
@NgModule({
imports: [
PipeModule,
DataColumnModule,
DataTableModule,
FormsModule,

View File

@@ -101,31 +101,46 @@ describe('ContextMenuHolderComponent', () => {
});
describe('onMenuItemClick()', () => {
const menuItem = {
model: {
disabled: false
},
subject: {
next: (val) => val
}
};
const event = {
preventDefault: () => null,
stopImmediatePropagation: () => null
};
beforeEach(() => {
spyOn(menuItem.subject, 'next');
});
it('should emit when link is not disabled', () => {
const menuItem = {
model: {
disabled: false
},
subject: {
next: (val) => val
}
};
spyOn(menuItem.subject, 'next');
const event = {
preventDefault: () => null,
stopImmediatePropagation: () => null
};
component.onMenuItemClick(<any> event, menuItem);
expect(menuItem.subject.next).toHaveBeenCalledWith(menuItem);
});
it('should not emit when link is disabled', () => {
const menuItem = {
model: {
disabled: false
},
subject: {
next: (val) => val
}
};
spyOn(menuItem.subject, 'next');
const event = {
preventDefault: () => null,
stopImmediatePropagation: () => null
};
menuItem.model.disabled = true;
component.onMenuItemClick(<any> event, menuItem);

View File

@@ -16,7 +16,7 @@
*/
import { SimpleChange, NO_ERRORS_SCHEMA, QueryList } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick, async } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { MatCheckboxChange } from '@angular/material';
import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';

View File

@@ -16,7 +16,7 @@
*/
import { Component, DebugElement, ViewChild } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NodeDeleteDirective } from './node-delete.directive';
@@ -38,7 +38,8 @@ class TestComponent {
@ViewChild(NodeDeleteDirective)
deleteDirective: NodeDeleteDirective;
onDelete(event) {}
onDelete(event) {
}
}
@Component({
@@ -89,6 +90,9 @@ describe('NodeDeleteDirective', () => {
let componentWithPermanentDelete: TestDeletePermanentComponent;
let alfrescoApi: AlfrescoApiService;
let nodeApi;
let deleteNodeSpy: any;
let purgeDeletedNodeSpy: any;
let disposableDelete: any;
setupTestBed({
imports: [
@@ -105,7 +109,12 @@ describe('NodeDeleteDirective', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.nodesApi;
deleteNodeSpy = spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
purgeDeletedNodeSpy = spyOn(nodeApi, 'purgeDeletedNode').and.returnValue(Promise.resolve());
fixture = TestBed.createComponent(TestComponent);
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
@@ -117,33 +126,30 @@ describe('NodeDeleteDirective', () => {
element = fixture.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(NodeDeleteDirective));
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.getInstance().nodes;
}));
});
afterEach(() => {
if (disposableDelete) {
disposableDelete.unsubscribe();
}
fixture.destroy();
});
describe('Delete', () => {
it('should do nothing if selection is empty', () => {
spyOn(nodeApi, 'deleteNode');
component.selection = [];
fixture.detectChanges();
element.nativeElement.click();
expect(nodeApi.deleteNode).not.toHaveBeenCalled();
expect(deleteNodeSpy).not.toHaveBeenCalled();
});
it('should process node successfully', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = <any> [{ entry: { id: '1', name: 'name1' } }];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.SINGULAR'
);
@@ -158,11 +164,11 @@ describe('NodeDeleteDirective', () => {
});
it('should notify failed node deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
deleteNodeSpy.and.returnValue(Promise.reject('error'));
component.selection = [{ entry: { id: '1', name: 'name1' } }];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.ERROR_SINGULAR'
);
@@ -177,14 +183,12 @@ describe('NodeDeleteDirective', () => {
});
it('should notify nodes deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.PLURAL'
);
@@ -199,14 +203,14 @@ describe('NodeDeleteDirective', () => {
});
it('should notify failed nodes deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
deleteNodeSpy.and.returnValue(Promise.reject('error'));
component.selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.ERROR_PLURAL'
);
@@ -221,7 +225,7 @@ describe('NodeDeleteDirective', () => {
});
it('should notify partial deletion when only one node is successful', (done) => {
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
deleteNodeSpy.and.callFake((id) => {
if (id === '1') {
return Promise.reject('error');
} else {
@@ -234,7 +238,7 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '2', name: 'name2' } }
];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.PARTIAL_SINGULAR'
);
@@ -249,7 +253,7 @@ describe('NodeDeleteDirective', () => {
});
it('should notify partial deletion when some nodes are successful', (done) => {
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
deleteNodeSpy.and.callFake((id) => {
if (id === '1') {
return Promise.reject(null);
}
@@ -269,7 +273,7 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '3', name: 'name3' } }
];
component.deleteDirective.delete.subscribe((message) => {
disposableDelete = component.deleteDirective.delete.subscribe((message) => {
expect(message).toBe(
'CORE.DELETE_NODE.PARTIAL_PLURAL'
);
@@ -284,36 +288,39 @@ describe('NodeDeleteDirective', () => {
});
it('should emit event when delete is done', (done) => {
spyOn(alfrescoApi.nodesApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = <any> [{ entry: { id: '1', name: 'name1' } }];
fixture.detectChanges();
element.nativeElement.click();
fixture.detectChanges();
component.deleteDirective.delete.subscribe(() => {
disposableDelete = component.deleteDirective.delete.subscribe(() => {
done();
});
});
it('should disable the button if no node are selected', fakeAsync(() => {
it('should disable the button if no node are selected', (done) => {
component.selection = [];
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.nativeElement.disabled).toEqual(true);
done();
});
});
expect(element.nativeElement.disabled).toEqual(true);
}));
it('should disable the button if selected node is null', fakeAsync(() => {
it('should disable the button if selected node is null', (done) => {
component.selection = null;
fixture.detectChanges();
expect(element.nativeElement.disabled).toEqual(true);
}));
fixture.whenStable().then(() => {
expect(element.nativeElement.disabled).toEqual(true);
done();
});
});
it('should enable the button if nodes are selected', fakeAsync(() => {
it('should enable the button if nodes are selected', (done) => {
component.selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } },
@@ -322,10 +329,13 @@ describe('NodeDeleteDirective', () => {
fixture.detectChanges();
expect(element.nativeElement.disabled).toEqual(false);
}));
fixture.whenStable().then(() => {
expect(element.nativeElement.disabled).toEqual(false);
done();
});
});
it('should not enable the button if adf-node-permission is present', fakeAsync(() => {
it('should not enable the button if adf-node-permission is present', (done) => {
elementWithPermissions.nativeElement.disabled = false;
componentWithPermissions.selection = [];
@@ -339,14 +349,15 @@ describe('NodeDeleteDirective', () => {
fixtureWithPermissions.detectChanges();
expect(elementWithPermissions.nativeElement.disabled).toEqual(false);
}));
fixture.whenStable().then(() => {
expect(elementWithPermissions.nativeElement.disabled).toEqual(false);
done();
});
});
describe('Permanent', () => {
it('should call the api with permanent delete option if permanent directive input is true', fakeAsync(() => {
let deleteApi = spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
it('should call the api with permanent delete option if permanent directive input is true', (done) => {
fixtureWithPermanentComponent.detectChanges();
componentWithPermanentDelete.selection = [
@@ -356,14 +367,14 @@ describe('NodeDeleteDirective', () => {
fixtureWithPermanentComponent.detectChanges();
elementWithPermanentDelete.nativeElement.click();
tick();
expect(deleteApi).toHaveBeenCalledWith('1', { permanent: true });
}));
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', fakeAsync(() => {
let deleteApi = spyOn(nodeApi, 'purgeDeletedNode').and.returnValue(Promise.resolve());
fixture.whenStable().then(() => {
expect(deleteNodeSpy).toHaveBeenCalledWith('1', { permanent: true });
done();
});
});
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', (done) => {
fixtureWithPermanentComponent.detectChanges();
componentWithPermanentDelete.selection = [
@@ -373,10 +384,12 @@ describe('NodeDeleteDirective', () => {
fixtureWithPermanentComponent.detectChanges();
elementWithPermanentDelete.nativeElement.click();
tick();
expect(deleteApi).toHaveBeenCalledWith('1');
}));
fixture.whenStable().then(() => {
expect(purgeDeletedNodeSpy).toHaveBeenCalledWith('1');
done();
});
});
});
});

View File

@@ -16,28 +16,25 @@
*/
import { Component, DebugElement } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Observable } from 'rxjs/Observable';
import { TranslationService } from '../services';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NotificationService } from '../services/notification.service';
import { NodeRestoreDirective } from './node-restore.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@Component({
template: `
<div [adf-restore]="selection"
(restore)="done()">
(restore)="doneSpy()">
</div>`
})
class TestComponent {
selection = [];
done = jasmine.createSpy('done');
doneSpy = jasmine.createSpy('doneSpy');
}
describe('NodeRestoreDirective', () => {
@@ -45,17 +42,15 @@ describe('NodeRestoreDirective', () => {
let element: DebugElement;
let component: TestComponent;
let alfrescoService: AlfrescoApiService;
let translation: TranslationService;
let notification: NotificationService;
let router: Router;
let nodesService;
let coreApi;
let directiveInstance;
let restoreNodeSpy: any;
setupTestBed({
imports: [
CoreModule.forRoot(),
RouterTestingModule
NoopAnimationsModule
],
declarations: [
TestComponent
@@ -65,7 +60,7 @@ describe('NodeRestoreDirective', () => {
]
});
beforeEach(async(() => {
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
@@ -74,18 +69,15 @@ describe('NodeRestoreDirective', () => {
alfrescoService = TestBed.get(AlfrescoApiService);
nodesService = alfrescoService.getInstance().nodes;
coreApi = alfrescoService.getInstance().core;
translation = TestBed.get(TranslationService);
notification = TestBed.get(NotificationService);
router = TestBed.get(Router);
}));
beforeEach(() => {
spyOn(translation, 'instant').and.returnValue('message');
restoreNodeSpy = spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
list: { entries: [] }
}));
});
it('should not restore when selection is empty', () => {
spyOn(nodesService, 'restoreNode');
component.selection = [];
fixture.detectChanges();
@@ -94,54 +86,47 @@ describe('NodeRestoreDirective', () => {
expect(nodesService.restoreNode).not.toHaveBeenCalled();
});
it('should not restore nodes when selection has nodes without path', () => {
spyOn(nodesService, 'restoreNode');
component.selection = [ { entry: { id: '1' } } ];
it('should not restore nodes when selection has nodes without path', (done) => {
component.selection = [{ entry: { id: '1' } }];
fixture.detectChanges();
element.triggerEventHandler('click', null);
fixture.whenStable().then(() => {
element.triggerEventHandler('click', null);
expect(nodesService.restoreNode).not.toHaveBeenCalled();
expect(nodesService.restoreNode).not.toHaveBeenCalled();
done();
});
});
it('should call restore when selection has nodes with path', fakeAsync(() => {
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
list: { entries: [] }
}));
it('should call restore when selection has nodes with path', (done) => {
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
expect(nodesService.restoreNode).toHaveBeenCalled();
}));
describe('refresh()', () => {
it('should reset selection', fakeAsync(() => {
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
list: { entries: [] }
}));
fixture.whenStable().then(() => {
expect(nodesService.restoreNode).toHaveBeenCalled();
done();
});
});
describe('reset', () => {
it('should reset selection', (done) => {
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
directiveInstance.restore.subscribe(() => {
expect(directiveInstance.selection.length).toBe(0);
done();
});
fixture.detectChanges();
expect(directiveInstance.selection.length).toBe(1);
fixture.whenStable().then(() => {
expect(directiveInstance.selection.length).toBe(1);
element.triggerEventHandler('click', null);
});
});
element.triggerEventHandler('click', null);
tick();
expect(directiveInstance.selection.length).toBe(0);
}));
it('should reset status', fakeAsync(() => {
it('should reset status', () => {
directiveInstance.restoreProcessStatus.fail = [{}];
directiveInstance.restoreProcessStatus.success = [{}];
@@ -149,39 +134,34 @@ describe('NodeRestoreDirective', () => {
expect(directiveInstance.restoreProcessStatus.fail).toEqual([]);
expect(directiveInstance.restoreProcessStatus.success).toEqual([]);
}));
});
it('should emit event on finish', fakeAsync(() => {
spyOn(directiveInstance, 'restoreNotification').and.callFake(() => null);
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
list: { entries: [] }
}));
it('should emit event on finish', (done) => {
spyOn(element.nativeElement, 'dispatchEvent');
directiveInstance.restore.subscribe(() => {
expect(component.doneSpy).toHaveBeenCalled();
done();
});
component.selection = [{ entry: { id: '1', path: ['somewhere-over-the-rainbow'] } }];
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
expect(component.done).toHaveBeenCalled();
}));
});
});
describe('notification', () => {
beforeEach(() => {
spyOn(coreApi.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve({
list: { entries: [] }
}));
});
it('should notify on multiple fails', fakeAsync(() => {
it('should notify on multiple fails', (done) => {
const error = { message: '{ "error": {} }' };
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.PARTIAL_PLURAL');
done();
});
spyOn(nodesService, 'restoreNode').and.callFake((id) => {
restoreNodeSpy.and.callFake((id) => {
if (id === '1') {
return Promise.resolve();
}
@@ -203,19 +183,18 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
});
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.PARTIAL_PLURAL',
{ number: 2 }
);
}));
it('should notify fail when restored node exist, error 409', fakeAsync(() => {
it('should notify fail when restored node exist, error 409', (done) => {
const error = { message: '{ "error": { "statusCode": 409 } }' };
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.NODE_EXISTS');
done();
});
restoreNodeSpy.and.returnValue(Promise.reject(error));
component.selection = [
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
@@ -223,19 +202,18 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
});
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.NODE_EXISTS',
{ name: 'name1' }
);
}));
it('should notify fail when restored node returns different statusCode', fakeAsync(() => {
it('should notify fail when restored node returns different statusCode', (done) => {
const error = { message: '{ "error": { "statusCode": 404 } }' };
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
restoreNodeSpy.and.returnValue(Promise.reject(error));
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.GENERIC');
done();
});
component.selection = [
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
@@ -243,19 +221,17 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
});
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.GENERIC',
{ name: 'name1' }
);
}));
it('should notify fail when restored node location is missing', fakeAsync(() => {
it('should notify fail when restored node location is missing', (done) => {
const error = { message: '{ "error": { } }' };
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.reject(error));
restoreNodeSpy.and.returnValue(Promise.reject(error));
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.LOCATION_MISSING');
done();
});
component.selection = [
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
@@ -263,17 +239,17 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
});
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.LOCATION_MISSING',
{ name: 'name1' }
);
}));
it('should notify success when restore multiple nodes', (done) => {
it('should notify success when restore multiple nodes', fakeAsync(() => {
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
spyOn(nodesService, 'restoreNode').and.callFake((id) => {
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.PLURAL');
done();
});
restoreNodeSpy.and.callFake((id) => {
if (id === '1') {
return Promise.resolve();
}
@@ -290,16 +266,15 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.PLURAL'
);
}));
});
it('should notify success on restore selected node', fakeAsync(() => {
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.throw(null) });
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
it('should notify success on restore selected node', (done) => {
directiveInstance.restore.subscribe((event) => {
expect(event.message).toEqual('CORE.RESTORE_NODE.SINGULAR');
done();
});
component.selection = [
{ entry: { id: '1', name: 'name1', path: ['somewhere-over-the-rainbow'] } }
@@ -307,36 +282,8 @@ describe('NodeRestoreDirective', () => {
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.SINGULAR',
{ name: 'name1' }
);
}));
});
it('should navigate to restored node location onAction', fakeAsync(() => {
spyOn(router, 'navigate');
spyOn(nodesService, 'restoreNode').and.returnValue(Promise.resolve());
spyOn(notification, 'openSnackMessageAction').and.returnValue({ onAction: () => Observable.of({}) });
component.selection = [
{
entry: {
id: '1',
name: 'name1',
path: {
elements: ['somewhere-over-the-rainbow']
}
}
}
];
fixture.detectChanges();
element.triggerEventHandler('click', null);
tick();
expect(router.navigate).toHaveBeenCalled();
}));
});
});

View File

@@ -18,11 +18,9 @@
/* tslint:disable:component-selector no-input-rename */
import { Directive, EventEmitter, HostListener, Input, Output } from '@angular/core';
import { Router } from '@angular/router';
import { DeletedNodeEntry, DeletedNodesPaging, PathInfoEntity } from 'alfresco-js-api';
import { DeletedNodeEntry, DeletedNodesPaging } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NotificationService } from '../services/notification.service';
import { TranslationService } from '../services/translation.service';
import 'rxjs/add/observable/from';
import 'rxjs/add/observable/zip';
@@ -52,9 +50,7 @@ export class NodeRestoreDirective {
}
constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
private router: Router,
private notification: NotificationService) {
private translation: TranslationService) {
this.restoreProcessStatus = this.processStatus();
}
@@ -65,36 +61,35 @@ export class NodeRestoreDirective {
const nodesWithPath = this.getNodesWithPath(selection);
if (selection.length && !nodesWithPath.length) {
if (selection.length && nodesWithPath.length) {
this.restoreNodesBatch(nodesWithPath)
.do((restoredNodes) => {
const status = this.processStatus(restoredNodes);
this.restoreProcessStatus.fail.push(...status.fail);
this.restoreProcessStatus.success.push(...status.success);
})
.mergeMap(() => this.getDeletedNodes())
.subscribe(
(deletedNodesList: any) => {
const { entries: nodelist } = deletedNodesList.list;
const { fail: restoreErrorNodes } = this.restoreProcessStatus;
const selectedNodes = this.diff(restoreErrorNodes, selection, false);
const remainingNodes = this.diff(selectedNodes, nodelist);
if (!remainingNodes.length) {
this.notification();
} else {
this.recover(remainingNodes);
}
}
);
} else {
this.restoreProcessStatus.fail.push(...selection);
this.restoreNotification();
this.refresh();
this.notification();
return;
}
this.restoreNodesBatch(nodesWithPath)
.do((restoredNodes) => {
const status = this.processStatus(restoredNodes);
this.restoreProcessStatus.fail.push(...status.fail);
this.restoreProcessStatus.success.push(...status.success);
})
.mergeMap(() => this.getDeletedNodes())
.subscribe(
(deletedNodesList: any) => {
const { entries: nodelist } = deletedNodesList.list;
const { fail: restoreErrorNodes } = this.restoreProcessStatus;
const selectedNodes = this.diff(restoreErrorNodes, selection, false);
const remainingNodes = this.diff(selectedNodes, nodelist);
if (!remainingNodes.length) {
this.restoreNotification();
this.refresh();
} else {
this.recover(remainingNodes);
}
}
);
}
private restoreNodesBatch(batch: DeletedNodeEntry[]): Observable<DeletedNodeEntry[]> {
@@ -133,12 +128,6 @@ export class NodeRestoreDirective {
});
}
private navigateLocation(path: PathInfoEntity) {
const parent = path.elements[path.elements.length - 1];
this.router.navigate([this.location, parent.id]);
}
private diff(selection, list, fromList = true): any {
const ids = selection.map(item => item.entry.id);
@@ -246,21 +235,19 @@ export class NodeRestoreDirective {
}
}
private restoreNotification(): void {
private notification(): void {
const status = Object.assign({}, this.restoreProcessStatus);
let message = this.getRestoreMessage();
this.reset();
const action = (status.oneSucceeded && !status.someFailed) ? this.translation.instant('CORE.RESTORE_NODE.VIEW') : '';
this.notification.openSnackMessageAction(message, action)
.onAction()
.subscribe(() => this.navigateLocation(status.success[0].entry.path));
this.restore.emit({ message: message, action: action });
}
private refresh(): void {
private reset(): void {
this.restoreProcessStatus.reset();
this.selection = [];
this.restore.emit();
}
}

View File

@@ -50,7 +50,7 @@ describe('FormFieldComponent', () => {
fixture.destroy();
});
it('should create default component instance', () => {
it('should create default component instance', (done) => {
let field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,
id: 'FAKE-TXT-WIDGET'
@@ -59,25 +59,32 @@ describe('FormFieldComponent', () => {
component.field = field;
fixture.detectChanges();
expect(component.componentRef).toBeDefined();
expect(component.componentRef.componentType).toBe(TextWidgetComponent);
fixture.whenStable().then(() => {
expect(component.componentRef).toBeDefined();
expect(component.componentRef.instance instanceof TextWidgetComponent).toBeTruthy();
done();
});
});
it('should create custom component instance', () => {
it('should create custom component instance', (done) => {
formRenderingService.setComponentTypeResolver(FormFieldTypes.AMOUNT, () => CheckboxWidgetComponent, true);
let field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,
type: FormFieldTypes.AMOUNT,
id: 'FAKE-TXT-WIDGET'
});
formRenderingService.setComponentTypeResolver(FormFieldTypes.TEXT, () => CheckboxWidgetComponent, true);
component.field = field;
fixture.detectChanges();
expect(component.componentRef).toBeDefined();
expect(component.componentRef.componentType).toBe(CheckboxWidgetComponent);
fixture.whenStable().then(() => {
expect(component.componentRef).toBeDefined();
expect(component.componentRef.instance instanceof CheckboxWidgetComponent).toBeTruthy();
done();
});
});
it('should require component type to be resolved', () => {
it('should require component type to be resolved', (done) => {
let field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,
id: 'FAKE-TXT-WIDGET'
@@ -87,11 +94,14 @@ describe('FormFieldComponent', () => {
component.field = field;
fixture.detectChanges();
expect(formRenderingService.resolveComponentType).toHaveBeenCalled();
expect(component.componentRef).toBeUndefined();
fixture.whenStable().then(() => {
expect(formRenderingService.resolveComponentType).toHaveBeenCalled();
expect(component.componentRef).toBeUndefined();
done();
});
});
it('should hide the field when it is not visible', () => {
it('should hide the field when it is not visible', (done) => {
let field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,
id: 'FAKE-TXT-WIDGET'
@@ -100,10 +110,13 @@ describe('FormFieldComponent', () => {
component.field = field;
component.field.isVisible = false;
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeTruthy();
fixture.whenStable().then(() => {
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeTruthy();
done();
});
});
it('should show the field when it is visible', () => {
it('should show the field when it is visible', (done) => {
let field = new FormFieldModel(form, {
type: FormFieldTypes.TEXT,
id: 'FAKE-TXT-WIDGET'
@@ -111,7 +124,11 @@ describe('FormFieldComponent', () => {
component.field = field;
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeFalsy();
fixture.whenStable().then(() => {
expect(fixture.nativeElement.querySelector('#field-FAKE-TXT-WIDGET-container').hidden).toBeFalsy();
done();
});
});
it('should hide a visible element', () => {

View File

@@ -226,7 +226,7 @@ describe('FormComponent', () => {
});
it('should refresh visibility when the form is loaded', () => {
spyOn(formService, 'getFormDefinitionById').and.returnValue(Observable.of(fakeForm));
spyOn(formService, 'getFormDefinitionById').and.returnValue(Observable.of(JSON.parse(JSON.stringify(fakeForm))));
const formId = '123';
formComponent.formId = formId;
@@ -816,7 +816,7 @@ describe('FormComponent', () => {
});
it('should refresh form values when data is changed', () => {
formComponent.form = new FormModel(fakeForm);
formComponent.form = new FormModel(JSON.parse(JSON.stringify(fakeForm)));
let formFields = formComponent.form.getFormFields();
let labelField = formFields.find(field => field.id === 'label');
@@ -842,7 +842,7 @@ describe('FormComponent', () => {
});
it('should refresh radio buttons value when id is given to data', () => {
formComponent.form = new FormModel(fakeForm);
formComponent.form = new FormModel(JSON.parse(JSON.stringify(fakeForm)));
let formFields = formComponent.form.getFormFields();
let radioFieldById = formFields.find(field => field.id === 'radio');

View File

@@ -46,6 +46,7 @@ describe('DateTimeWidgetComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should setup min value for date picker', () => {

View File

@@ -100,7 +100,12 @@ describe('DateWidgetComponent', () => {
describe('template check', () => {
beforeEach(() => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should show visible date widget', async(() => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
@@ -109,15 +114,8 @@ describe('DateWidgetComponent', () => {
readOnly: 'false'
});
widget.field.isVisible = true;
widget.ngOnInit();
fixture.detectChanges();
});
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should show visible date widget', async(() => {
fixture.whenStable().then(() => {
expect(element.querySelector('#date-field-id')).toBeDefined();
expect(element.querySelector('#date-field-id')).not.toBeNull();
@@ -127,11 +125,17 @@ describe('DateWidgetComponent', () => {
}));
it('should check correctly the min value with different formats', async(() => {
widget.field.value = '11-30-9999';
widget.field.dateDisplayFormat = 'MM-DD-YYYY';
widget.field.minValue = '30-12-9999';
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '11-30-9999',
type: 'date',
readOnly: 'false',
dateDisplayFormat : 'MM-DD-YYYY',
minValue : '30-12-9999'
});
widget.field.isVisible = true;
widget.ngOnInit();
widget.field.validate();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
@@ -144,7 +148,14 @@ describe('DateWidgetComponent', () => {
}));
it('should show the correct format type', async(() => {
widget.field.value = '12-30-9999';
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '12-30-9999';
type: 'date',
readOnly: 'false'
});
widget.field.isVisible = true;
widget.field.dateDisplayFormat = 'MM-DD-YYYY';
widget.ngOnInit();
fixture.detectChanges();
@@ -158,6 +169,14 @@ describe('DateWidgetComponent', () => {
}));
it('should disable date button when is readonly', async(() => {
widget.field = new FormFieldModel(new FormModel(), {
id: 'date-field-id',
name: 'date-name',
value: '9-9-9999',
type: 'date',
readOnly: 'false'
});
widget.field.isVisible = true;
widget.field.readOnly = false;
fixture.detectChanges();

View File

@@ -41,12 +41,11 @@ describe('LanguageMenuComponent', () => {
fixture.destroy();
});
it('should have the default language', () => {
fixture.detectChanges();
expect(component.languages).toEqual([{ key: 'en', label: 'English'}]);
});
it('should fetch the languages from the app config if present', () => {
fixture.detectChanges();
expect(component.languages).toEqual([{ key: 'en', label: 'English' }]);
appConfig.config.languages = [
{
key: 'fake-key-1',
@@ -58,7 +57,7 @@ describe('LanguageMenuComponent', () => {
}
];
fixture.detectChanges();
component.ngOnInit();
expect(component.languages).toEqual([
{
key: 'fake-key-1',

View File

@@ -29,10 +29,23 @@ export class AlfrescoApiServiceMock extends AlfrescoApiService {
constructor(protected appConfig: AppConfigService,
protected storage: StorageService) {
super(appConfig, storage);
this.initAlfrescoApi();
if (!this.alfrescoApi) {
this.initAlfrescoApi();
}
}
async load() {
await this.appConfig.load().then(() => {
if (!this.alfrescoApi) {
this.initAlfrescoApi();
}
});
}
async reset() {
if (this.alfrescoApi) {
this.alfrescoApi = null;
}
this.initAlfrescoApi();
}

View File

@@ -105,6 +105,9 @@ export class AlfrescoApiService {
}
async reset() {
if (this.alfrescoApi) {
this.alfrescoApi = null;
}
this.initAlfrescoApi();
}

View File

@@ -61,6 +61,7 @@ describe('AuthGuardService', () => {
it('should set redirect url', async(() => {
state.url = 'some-url';
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigate');
spyOn(authService, 'setRedirect');
@@ -75,6 +76,7 @@ describe('AuthGuardService', () => {
it('should set redirect url with query params', async(() => {
state.url = 'some-url;q=query';
appConfigService.config.loginRoute = 'login';
spyOn(router, 'navigate');
spyOn(authService, 'setRedirect');

View File

@@ -64,38 +64,43 @@ describe('AuthenticationService', () => {
});
it('[ECM] should save the remember me cookie as a session cookie after successful login', (done) => {
authService.login('fake-username', 'fake-password', false).subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password', false).subscribe(() => {
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).toBeNull();
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] should save the remember me cookie as a persistent cookie after successful login', (done) => {
authService.login('fake-username', 'fake-password', true).subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password', true).subscribe(() => {
expect(cookie['ALFRESCO_REMEMBER_ME']).not.toBeUndefined();
expect(cookie['ALFRESCO_REMEMBER_ME'].expiration).not.toBeNull();
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] should not save the remember me cookie after failed login', (done) => {
authService.login('fake-username', 'fake-password').subscribe(
(res) => {},
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
(res) => {
},
(err: any) => {
expect(cookie['ALFRESCO_REMEMBER_ME']).toBeUndefined();
disposableLogin.unsubscribe();
done();
});
@@ -140,43 +145,46 @@ describe('AuthenticationService', () => {
});
it('[ECM] should return an ECM ticket after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket');
expect(authService.isEcmLoggedIn()).toBe(true);
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] should save only ECM ticket on localStorage', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketBpm()).toBeNull();
expect(apiService.getInstance().bpmAuth.isLoggedIn()).toBeFalsy();
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
let disposableLogin = authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => {
},
(err: any) => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null);
expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe();
done();
});
@@ -196,23 +204,26 @@ describe('AuthenticationService', () => {
});
it('[ECM] should login in the ECM if no provider are defined calling the login', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] should return a ticket undefined after logout', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
authService.logout().subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogout = authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketEcm()).toBe(null);
expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe();
disposableLogout.unsubscribe();
done();
});
@@ -224,13 +235,12 @@ describe('AuthenticationService', () => {
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[ECM] ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout();
expect(authService.getTicketEcm()).toBe('fake-post-ticket');
@@ -239,9 +249,11 @@ describe('AuthenticationService', () => {
'status': 204
});
logoutPromise.subscribe(() => {
let disposableLogout = logoutPromise.subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe();
disposableLogout.unsubscribe();
done();
});
@@ -250,7 +262,7 @@ describe('AuthenticationService', () => {
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
@@ -260,19 +272,19 @@ describe('AuthenticationService', () => {
});
it('[ECM] should set/get redirectUrl when provider is ECM', () => {
authService.setRedirect({provider: 'ECM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'ECM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toEqual(['some-url']);
});
it('[ECM] should set/get redirectUrl when provider is BPM', () => {
authService.setRedirect({provider: 'BPM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'BPM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toBeNull();
});
it('[ECM] should return null as redirectUrl when redirectUrl field is not set', () => {
authService.setRedirect( null );
authService.setRedirect(null);
expect(authService.getRedirect(preferences.authType)).toBeNull();
});
@@ -303,41 +315,45 @@ describe('AuthenticationService', () => {
});
it('[BPM] should return an BPM ticket after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe((response) => {
expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
expect(authService.isBpmLoggedIn()).toBe(true);
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 200
'status': 200,
contentType: 'application/json'
});
});
it('[BPM] should save only BPM ticket on localStorage', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toBeNull();
expect(apiService.getInstance().ecmAuth.isLoggedIn()).toBeFalsy();
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
});
it('[BPM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
let disposableLogin = authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => {
},
(err: any) => {
expect(authService.isLoggedIn()).toBe(false, 'isLoggedIn');
expect(authService.getTicketBpm()).toBe(null, 'getTicketBpm');
expect(authService.isBpmLoggedIn()).toBe(false, 'isBpmLoggedIn');
disposableLogin.unsubscribe();
done();
});
@@ -347,8 +363,7 @@ describe('AuthenticationService', () => {
});
it('[BPM] ticket should be deleted only after logout request is accepted', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
let logoutPromise = authService.logout();
expect(authService.getTicketBpm()).toBe('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
@@ -357,9 +372,11 @@ describe('AuthenticationService', () => {
'status': 200
});
logoutPromise.subscribe(() => {
let disposableLogout = logoutPromise.subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.isBpmLoggedIn()).toBe(false);
disposableLogout.unsubscribe();
disposableLogin.unsubscribe();
done();
});
@@ -371,11 +388,13 @@ describe('AuthenticationService', () => {
});
it('[BPM] should return a ticket undefined after logout', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
authService.logout().subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogout = authService.logout().subscribe(() => {
expect(authService.isLoggedIn()).toBe(false);
expect(authService.getTicketBpm()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false);
disposableLogout.unsubscribe();
disposableLogin.unsubscribe();
done();
});
@@ -405,19 +424,19 @@ describe('AuthenticationService', () => {
});
it('[BPM] should set/get redirectUrl when provider is BPM', () => {
authService.setRedirect({provider: 'BPM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'BPM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toEqual(['some-url']);
});
it('[BPM] should set/get redirectUrl when provider is ECM', () => {
authService.setRedirect({provider: 'ECM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'ECM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toBeNull();
});
it('[BPM] should return null as redirectUrl when redirectUrl field is not set', () => {
authService.setRedirect( null );
authService.setRedirect(null);
expect(authService.getRedirect(preferences.authType)).toBeNull();
});
@@ -430,19 +449,20 @@ describe('AuthenticationService', () => {
});
it('[ALL] should return both ECM and BPM tickets after the login done', (done) => {
authService.login('fake-username', 'fake-password').subscribe(() => {
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.isLoggedIn()).toBe(true);
expect(authService.getTicketEcm()).toEqual('fake-post-ticket');
expect(authService.getTicketBpm()).toEqual('Basic ZmFrZS11c2VybmFtZTpmYWtlLXBhc3N3b3Jk');
expect(authService.isBpmLoggedIn()).toBe(true);
expect(authService.isEcmLoggedIn()).toBe(true);
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.at(0).respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
jasmine.Ajax.requests.at(1).respondWith({
@@ -451,7 +471,7 @@ describe('AuthenticationService', () => {
});
it('[ALL] should return login fail if only ECM call fail', (done) => {
authService.login('fake-username', 'fake-password').subscribe(
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
(res) => {
},
(err: any) => {
@@ -459,6 +479,7 @@ describe('AuthenticationService', () => {
expect(authService.getTicketEcm()).toBe(null, 'getTicketEcm');
expect(authService.getTicketBpm()).toBe(null, 'getTicketBpm');
expect(authService.isEcmLoggedIn()).toBe(false, 'isEcmLoggedIn');
disposableLogin.unsubscribe();
done();
});
@@ -472,7 +493,7 @@ describe('AuthenticationService', () => {
});
it('[ALL] should return login fail if only BPM call fail', (done) => {
authService.login('fake-username', 'fake-password').subscribe(
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
(res) => {
},
(err: any) => {
@@ -480,13 +501,14 @@ describe('AuthenticationService', () => {
expect(authService.getTicketEcm()).toBe(null);
expect(authService.getTicketBpm()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false);
disposableLogin.unsubscribe();
done();
});
jasmine.Ajax.requests.at(0).respondWith({
'status': 201,
contentType: 'application/json',
responseText: JSON.stringify({'entry': {'id': 'fake-post-ticket', 'userId': 'admin'}})
responseText: JSON.stringify({ 'entry': { 'id': 'fake-post-ticket', 'userId': 'admin' } })
});
jasmine.Ajax.requests.at(1).respondWith({
@@ -495,7 +517,7 @@ describe('AuthenticationService', () => {
});
it('[ALL] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-username', 'fake-password').subscribe(
let disposableLogin = authService.login('fake-username', 'fake-password').subscribe(
(res) => {
},
(err: any) => {
@@ -504,6 +526,7 @@ describe('AuthenticationService', () => {
expect(authService.getTicketBpm()).toBe(null);
expect(authService.isBpmLoggedIn()).toBe(false);
expect(authService.isEcmLoggedIn()).toBe(false);
disposableLogin.unsubscribe();
done();
});
@@ -517,25 +540,25 @@ describe('AuthenticationService', () => {
});
it('[ALL] should set/get redirectUrl when provider is ALL', () => {
authService.setRedirect({provider: 'ALL', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'ALL', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toEqual(['some-url']);
});
it('[ALL] should set/get redirectUrl when provider is BPM', () => {
authService.setRedirect({provider: 'BPM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'BPM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toEqual(['some-url']);
});
it('[ALL] should set/get redirectUrl when provider is ECM', () => {
authService.setRedirect({provider: 'ECM', navigation: ['some-url'] } );
authService.setRedirect({ provider: 'ECM', navigation: ['some-url'] });
expect(authService.getRedirect(preferences.authType)).toEqual(['some-url']);
});
it('[ALL] should return null as redirectUrl when redirectUrl field is not set', () => {
authService.setRedirect( null );
authService.setRedirect(null);
expect(authService.getRedirect(preferences.authType)).toBeNull();
});

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
import { AppConfigService } from '../app-config/app-config.service';
import { StorageService } from './storage.service';
@@ -32,6 +32,7 @@ describe('UserPreferencesService', () => {
let storage: StorageService;
let appConfig: AppConfigService;
let translate: TranslateService;
let changeDisposable: any;
setupTestBed({
imports: [CoreTestingModule]
@@ -50,6 +51,12 @@ describe('UserPreferencesService', () => {
translate = TestBed.get(TranslateService);
});
afterEach(() => {
if (changeDisposable) {
changeDisposable.unsubscribe();
}
});
it('should get default pagination from app config', () => {
appConfig.config.pagination.size = 0;
expect(preferences.defaults.paginationSize).toBe(defaultPaginationSize);
@@ -132,25 +139,28 @@ describe('UserPreferencesService', () => {
expect(preferences.locale).toBe('fake-store-locate');
});
it('should stream the page size value when is set', async(() => {
it('should stream the page size value when is set', (done) => {
preferences.paginationSize = 5;
preferences.onChange.subscribe((userPreferenceStatus) => {
changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => {
expect(userPreferenceStatus.PAGINATION_SIZE).toBe(5);
done();
});
}));
});
it('should stream the user preference status when changed', async(() => {
it('should stream the user preference status when changed', (done) => {
preferences.set('propertyA', 'valueA');
preferences.onChange.subscribe((userPreferenceStatus) => {
changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => {
expect(userPreferenceStatus.propertyA).toBe('valueA');
done();
});
}));
});
it('should stream only the selected attribute changes when using select', async(() => {
it('should stream only the selected attribute changes when using select', (done) => {
preferences.disableCSRF = true;
preferences.select(UserPreferenceValues.DisableCSRF).subscribe((disableCSRFFlag) => {
expect(disableCSRFFlag).toBeTruthy();
done();
});
}));
});
});