dashlist: handle recent dashboards removed from backend

This commit is contained in:
Marcus Efraimsson
2017-11-28 09:07:28 +01:00
parent 368a4d7aed
commit 8f4ad1e496
2 changed files with 30 additions and 2 deletions
+5 -2
View File
@@ -38,8 +38,11 @@ export class SearchSrv {
return this.backendSrv.search({ dashboardIds: dashIds }).then(result => {
return dashIds.map(orderId => {
return this.transformToViewModel(_.find(result, { id: orderId }));
}).filter(item => !item.isStarred);
return _.find(result, { id: orderId });
}).filter(hit => hit && !hit.isStarred)
.map(hit => {
return this.transformToViewModel(hit);
});
});
}
+25
View File
@@ -53,6 +53,31 @@ describe('SearchSrv', () => {
expect(results[0].items[0].title).toBe('first but second');
expect(results[0].items[1].title).toBe('second but first');
});
describe('and 3 recent dashboards removed in backend', () => {
let results;
beforeEach(() => {
backendSrvMock.search = jest
.fn()
.mockReturnValueOnce(
Promise.resolve([{ id: 2, title: 'two' }, { id: 1, title: 'one' }]),
)
.mockReturnValue(Promise.resolve([]));
impressionSrv.getDashboardOpened = jest.fn().mockReturnValue([4, 5, 1, 2, 3]);
return searchSrv.search({ query: '' }).then(res => {
results = res;
});
});
it('should return 2 dashboards', () => {
expect(results[0].items.length).toBe(2);
expect(results[0].items[0].id).toBe(1);
expect(results[0].items[1].id).toBe(2);
});
});
});
describe('With starred dashboards', () => {