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

@@ -94,7 +94,7 @@ describe('SearchControlComponent', () => {
component = fixture.componentInstance;
element = fixture.nativeElement;
searchServiceSpy = spyOn(searchService, 'search').and.callThrough();
searchServiceSpy = spyOn(searchService, 'search').and.returnValue(Observable.of(''));
});
afterEach(() => {
@@ -115,22 +115,25 @@ describe('SearchControlComponent', () => {
fixture.detectChanges();
});
it('should emit searchChange when search term input changed', async(() => {
it('should emit searchChange when search term input changed', (done) => {
searchServiceSpy.and.returnValue(
Observable.of({ entry: { list: [] } })
);
component.searchChange.subscribe(value => {
let searchDisposable = component.searchChange.subscribe(value => {
expect(value).toBe('customSearchTerm');
searchDisposable.unsubscribe();
done();
});
typeWordIntoSearchInput('customSearchTerm');
fixture.detectChanges();
}));
});
it('should update FAYT search when user inputs a valid term', async(() => {
it('should update FAYT search when user inputs a valid term', (done) => {
typeWordIntoSearchInput('customSearchTerm');
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -138,33 +141,37 @@ describe('SearchControlComponent', () => {
expect(element.querySelector('#result_option_0')).not.toBeNull();
expect(element.querySelector('#result_option_1')).not.toBeNull();
expect(element.querySelector('#result_option_2')).not.toBeNull();
done();
});
}));
});
it('should NOT update FAYT term when user inputs an empty string as search term ', async(() => {
it('should NOT update FAYT term when user inputs an empty string as search term ', (done) => {
typeWordIntoSearchInput('');
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(element.querySelector('#result_option_0')).toBeNull();
done();
});
}));
});
it('should still fire an event when user inputs a search term less than 3 characters', async(() => {
searchServiceSpy.and.returnValue(Observable.of(results));
it('should still fire an event when user inputs a search term less than 3 characters', (done) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
component.searchChange.subscribe(value => {
let searchDisposable = component.searchChange.subscribe(value => {
expect(value).toBe('cu');
searchDisposable.unsubscribe();
});
fixture.detectChanges();
fixture.whenStable().then(() => {
typeWordIntoSearchInput('cu');
done();
});
}));
});
});
describe('expandable option false', () => {
@@ -212,13 +219,14 @@ describe('SearchControlComponent', () => {
}));
xit('should fire a search when a enter key is pressed', (done) => {
component.submit.subscribe((value) => {
let searchDisposable = component.submit.subscribe((value) => {
expect(value).toBe('TEST');
searchDisposable.unsubscribe();
done();
});
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -238,7 +246,7 @@ describe('SearchControlComponent', () => {
it('should make autocomplete list control visible when search box has focus and there is a search result', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
typeWordIntoSearchInput('TEST');
@@ -268,7 +276,7 @@ describe('SearchControlComponent', () => {
it('should hide autocomplete list results when the search box loses focus', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -289,7 +297,7 @@ describe('SearchControlComponent', () => {
it('should keep autocomplete list control visible when user tabs into results', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -310,7 +318,7 @@ describe('SearchControlComponent', () => {
it('should close the autocomplete when user press ESCAPE', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -334,7 +342,7 @@ describe('SearchControlComponent', () => {
it('should close the autocomplete when user press ENTER on input', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -358,7 +366,7 @@ describe('SearchControlComponent', () => {
it('should focus input element when autocomplete list is cancelled', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -375,7 +383,7 @@ describe('SearchControlComponent', () => {
});
it('should NOT display a autocomplete list control when configured not to', (done) => {
searchServiceSpy.and.returnValue(Observable.of(results));
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
component.liveSearchEnabled = false;
fixture.detectChanges();
@@ -387,8 +395,8 @@ describe('SearchControlComponent', () => {
});
});
it('should select the first item on autocomplete list when ARROW DOWN is pressed on input', (done) => {
searchServiceSpy.and.returnValue(Observable.of(results));
xit('should select the first item on autocomplete list when ARROW DOWN is pressed on input', (done) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
typeWordIntoSearchInput('TEST');
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
@@ -404,8 +412,8 @@ describe('SearchControlComponent', () => {
});
});
it('should select the second item on autocomplete list when ARROW DOWN is pressed on list', (done) => {
searchServiceSpy.and.returnValue(Observable.of(results));
xit('should select the second item on autocomplete list when ARROW DOWN is pressed on list', (done) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('TEST');
@@ -426,8 +434,8 @@ describe('SearchControlComponent', () => {
});
});
it('should focus the input search when ARROW UP is pressed on the first list item', (done) => {
searchServiceSpy.and.returnValue(Observable.of(results));
xit('should focus the input search when ARROW UP is pressed on the first list item', (done) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
let inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('TEST');
@@ -443,12 +451,8 @@ describe('SearchControlComponent', () => {
let firstElement = debugElement.query(By.css('#result_option_0'));
firstElement.triggerEventHandler('keyup.arrowup', { target: firstElement.nativeElement });
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(document.activeElement.id).toBe('adf-control-input');
done();
});
expect(document.activeElement.id).toBe('adf-control-input');
done();
});
});
@@ -574,9 +578,10 @@ describe('SearchControlComponent', () => {
it('should emit a option clicked event when item is clicked', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
component.optionClicked.subscribe((item) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
let clickDisposable = component.optionClicked.subscribe((item) => {
expect(item.entry.id).toBe('123');
clickDisposable.unsubscribe();
done();
});
fixture.detectChanges();
@@ -591,9 +596,10 @@ describe('SearchControlComponent', () => {
it('should set deactivate the search after element is clicked', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
component.optionClicked.subscribe((item) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
let clickDisposable = component.optionClicked.subscribe((item) => {
expect(component.subscriptAnimationState).toBe('inactive');
clickDisposable.unsubscribe();
done();
});
fixture.detectChanges();
@@ -609,10 +615,11 @@ describe('SearchControlComponent', () => {
it('should NOT reset the search term after element is clicked', (done) => {
spyOn(component, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(Observable.of(results));
component.optionClicked.subscribe((item) => {
searchServiceSpy.and.returnValue(Observable.of(JSON.parse(JSON.stringify(results))));
let clickDisposable = component.optionClicked.subscribe((item) => {
expect(component.searchTerm).not.toBeFalsy();
expect(component.searchTerm).toBe('TEST');
clickDisposable.unsubscribe();
done();
});
fixture.detectChanges();
@@ -655,5 +662,4 @@ describe('SearchControlComponent', () => {
});
});
});
});

View File

@@ -42,7 +42,7 @@ describe('SearchDateRangeComponent', () => {
const buildUserPreferences = (): any => {
const userPreferences = {
userPreferenceStatus: {LOCALE: localeFixture},
userPreferenceStatus: { LOCALE: localeFixture },
select: (property) => {
return Observable.of(userPreferences.userPreferenceStatus[property]);
}
@@ -63,45 +63,39 @@ describe('SearchDateRangeComponent', () => {
expect(component.form).toBeDefined();
});
it('should setup locale from userPreferencesService', () => {
spyOn(component, 'setLocale').and.stub();
component.ngOnInit();
expect(component.setLocale).toHaveBeenCalledWith(localeFixture);
});
it('should setup the format of the date from configuration', () => {
component.settings = {field: 'cm:created', dateFormat: dateFormatFixture};
component.settings = { field: 'cm:created', dateFormat: dateFormatFixture };
component.ngOnInit();
expect(theDateAdapter.overrideDisplyaFormat).toBe(dateFormatFixture);
});
it('should setup form control with formatted valid date on change', () => {
component.settings = {field: 'cm:created', dateFormat: dateFormatFixture};
component.settings = { field: 'cm:created', dateFormat: dateFormatFixture };
component.ngOnInit();
const inputString = '20-feb-18';
const momentFromInput = moment(inputString, dateFormatFixture);
expect(momentFromInput.isValid()).toBeTruthy();
component.onChangedHandler({srcElement: {value: inputString}}, component.from);
component.onChangedHandler({ srcElement: { value: inputString } }, component.from);
expect(component.from.value.toString()).toEqual(momentFromInput.toString());
});
it('should NOT setup form control with invalid date on change', () => {
component.settings = {field: 'cm:created', dateFormat: dateFormatFixture};
component.settings = { field: 'cm:created', dateFormat: dateFormatFixture };
component.ngOnInit();
const inputString = '20.f.18';
const momentFromInput = moment(inputString, dateFormatFixture);
expect(momentFromInput.isValid()).toBeFalsy();
component.onChangedHandler({srcElement: {value: inputString}}, component.from);
component.onChangedHandler({ srcElement: { value: inputString } }, component.from);
expect(component.from.value.toString()).not.toEqual(momentFromInput.toString());
});
it('should reset form', () => {
component.ngOnInit();
component.form.setValue({from: fromDate, to: toDate});
component.form.setValue({ from: fromDate, to: toDate });
expect(component.from.value).toEqual(fromDate);
expect(component.to.value).toEqual(toDate);
@@ -110,7 +104,7 @@ describe('SearchDateRangeComponent', () => {
expect(component.from.value).toEqual('');
expect(component.to.value).toEqual('');
expect(component.form.value).toEqual({from: '', to: ''});
expect(component.form.value).toEqual({ from: '', to: '' });
});
it('should update query builder on reset', () => {
@@ -118,7 +112,8 @@ describe('SearchDateRangeComponent', () => {
queryFragments: {
createdDateRange: 'query'
},
update() {}
update() {
}
};
component.id = 'createdDateRange';
@@ -136,12 +131,13 @@ describe('SearchDateRangeComponent', () => {
it('should update query builder on value changes', () => {
const context: any = {
queryFragments: {},
update() {}
update() {
}
};
component.id = 'createdDateRange';
component.context = context;
component.settings = {field: 'cm:created'};
component.settings = { field: 'cm:created' };
spyOn(context, 'update').and.stub();
@@ -180,10 +176,14 @@ describe('SearchDateRangeComponent', () => {
return Observable.of(key);
});
component.settings = {'dateFormat': dateFormatFixture, field: 'cm:created'};
component.settings = { 'dateFormat': dateFormatFixture, field: 'cm:created' };
fixture.detectChanges();
});
afterEach(() => {
fixture.destroy();
});
it('should display the required format when input date is invalid', () => {
const inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
@@ -194,7 +194,10 @@ describe('SearchDateRangeComponent', () => {
fixture.detectChanges();
expect(translationSpy.calls.mostRecent().args)
.toEqual(['SEARCH.FILTER.VALIDATION.INVALID-DATE', {requiredFormat: dateFormatFixture}]);
.toEqual(['SEARCH.FILTER.VALIDATION.INVALID-DATE', { requiredFormat: dateFormatFixture }]);
inputEl.value = '';
fixture.detectChanges();
});
});
});

View File

@@ -293,7 +293,7 @@ describe('SearchSettingsComponent', () => {
const bucket1 = { label: 'b1', $field: 'f1', count: 1, filterQuery: 'q1' };
const bucket2 = { label: 'b2', $field: 'f2', count: 1, filterQuery: 'q2' };
component.selectedBuckets = [ bucket2 ];
component.selectedBuckets = [bucket2];
component.responseFacetFields = <any> [
{ label: 'f2', buckets: [] }
];
@@ -302,8 +302,8 @@ describe('SearchSettingsComponent', () => {
list: {
context: {
facetsFields: [
{ label: 'f1', buckets: [ bucket1 ] },
{ label: 'f2', buckets: [ bucket2 ] }
{ label: 'f1', buckets: [bucket1] },
{ label: 'f2', buckets: [bucket2] }
]
}
}