mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
@@ -48,7 +48,7 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
name: 'MyDoc',
|
name: 'MyDoc',
|
||||||
isFile: true,
|
isFile: true,
|
||||||
content: {
|
content: {
|
||||||
mimetype: 'text/plain'
|
mimeType: 'text/plain'
|
||||||
},
|
},
|
||||||
createdByUser: {
|
createdByUser: {
|
||||||
displayName: 'John Doe'
|
displayName: 'John Doe'
|
||||||
@@ -62,12 +62,43 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let folderResult = {
|
||||||
|
list: {
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
entry: {
|
||||||
|
id: '123',
|
||||||
|
name: 'MyFolder',
|
||||||
|
isFile : false,
|
||||||
|
isFolder : true,
|
||||||
|
createdByUser: {
|
||||||
|
displayName: 'John Doe'
|
||||||
|
},
|
||||||
|
modifiedByUser: {
|
||||||
|
displayName: 'John Doe'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let noResult = {
|
let noResult = {
|
||||||
list: {
|
list: {
|
||||||
entries: []
|
entries: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let errorJson = {
|
||||||
|
error: {
|
||||||
|
errorKey: 'Search failed',
|
||||||
|
statusCode: 400,
|
||||||
|
briefSummary: '08220082 search failed',
|
||||||
|
stackTrace: 'For security reasons the stack trace is no longer displayed, but the property is kept for previous versions.',
|
||||||
|
descriptionURL: 'https://api-explorer.alfresco.com'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
return [
|
return [
|
||||||
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
{ provide: PLATFORM_PIPES, useValue: AlfrescoPipeTranslate, multi: true },
|
||||||
@@ -152,11 +183,10 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should display no result if no result are returned', (done) => {
|
it('should display no result if no result are returned', (done) => {
|
||||||
component.resultsEmitter.subscribe(x => {
|
component.resultsEmitter.subscribe(x => {
|
||||||
alfrescoSearchComponentFixture.detectChanges();
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
expect(element.querySelector('#search_no_result')).not.toBe(null);
|
expect(element.querySelector('#search_no_result')).not.toBeNull();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -169,31 +199,67 @@ describe('AlfrescoSearchComponent', () => {
|
|||||||
responseText: noResult
|
responseText: noResult
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should display an error if an error is encountered running the search', (done) => {
|
||||||
|
component.errorEmitter.subscribe(() => {
|
||||||
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
|
let resultsEl = element.querySelector('[data-automation-id="search_result_table"]');
|
||||||
|
let errorEl = element.querySelector('[data-automation-id="search_error_message"]');
|
||||||
|
expect(resultsEl).toBeNull();
|
||||||
|
expect(errorEl).not.toBeNull();
|
||||||
|
expect(errorEl.innerText).toBe('SEARCH.RESULTS.ERROR');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||||
|
component.ngOnChanges({searchTerm: component.searchTerm});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 500,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: errorJson
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('search result actions', () => {
|
describe('search result actions', () => {
|
||||||
|
|
||||||
it('should emit preview when file item clicked', () => {
|
it('should emit preview when file item clicked', (done) => {
|
||||||
component.results = [{
|
component.resultsEmitter.subscribe(() => {
|
||||||
entry: {
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
id: '123',
|
element.querySelector('#result_row_0').click();
|
||||||
name: 'MyDoc',
|
|
||||||
content: {
|
|
||||||
mimetype: 'text/plain'
|
|
||||||
},
|
|
||||||
isFile: true
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
alfrescoSearchComponentFixture.detectChanges(component.results[0]);
|
|
||||||
component.preview.subscribe(e => {
|
|
||||||
expect(e.value).toBe(component.results[0]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||||
|
component.ngOnChanges({searchTerm: component.searchTerm});
|
||||||
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
contentType: 'text/plain',
|
contentType: 'json',
|
||||||
responseText: '<div></div>'
|
responseText: result
|
||||||
|
});
|
||||||
|
|
||||||
|
component.preview.subscribe(e => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not emit preview when non-file item is clicked', (done) => {
|
||||||
|
spyOn(component.preview, 'emit');
|
||||||
|
component.resultsEmitter.subscribe(x => {
|
||||||
|
alfrescoSearchComponentFixture.detectChanges();
|
||||||
|
element.querySelector('#result_row_0').click();
|
||||||
|
expect(component.preview.emit).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.searchTerm = { currentValue: 'searchTerm', previousValue: ''};
|
||||||
|
component.ngOnChanges({searchTerm: component.searchTerm});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: folderResult
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -42,6 +42,9 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
resultsEmitter = new EventEmitter();
|
resultsEmitter = new EventEmitter();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
errorEmitter = new EventEmitter();
|
||||||
|
|
||||||
results: any;
|
results: any;
|
||||||
|
|
||||||
errorMessage;
|
errorMessage;
|
||||||
@@ -119,6 +122,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit {
|
|||||||
error => {
|
error => {
|
||||||
this.results = null;
|
this.results = null;
|
||||||
this.errorMessage = <any>error;
|
this.errorMessage = <any>error;
|
||||||
|
this.errorEmitter.emit(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user