|
|
@ -10,9 +10,10 @@ jest.spyOn(backendSrv, 'fetch'); |
|
|
|
describe('SQLSearcher', () => { |
|
|
|
describe('SQLSearcher', () => { |
|
|
|
beforeEach(() => { |
|
|
|
beforeEach(() => { |
|
|
|
searchMock.mockReset(); |
|
|
|
searchMock.mockReset(); |
|
|
|
|
|
|
|
searchMock.mockResolvedValue([]); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should call search api with correct query for general folder', async () => { |
|
|
|
it('should call search api with correct query for general folder', async () => { |
|
|
|
searchMock.mockResolvedValue([]); |
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
const query = { |
|
|
|
const query = { |
|
|
|
query: '*', |
|
|
|
query: '*', |
|
|
@ -31,9 +32,7 @@ describe('SQLSearcher', () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('should call search api with correct query based on its kinds', async () => { |
|
|
|
it('should call search api with correct folder kind when searching for *', async () => { |
|
|
|
searchMock.mockResolvedValue([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
|
|
|
|
|
|
|
|
const query = { |
|
|
|
const query = { |
|
|
@ -52,29 +51,34 @@ describe('SQLSearcher', () => { |
|
|
|
type: DashboardSearchItemType.DashFolder, |
|
|
|
type: DashboardSearchItemType.DashFolder, |
|
|
|
folderIds: [0], |
|
|
|
folderIds: [0], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
searchMock.mockClear(); |
|
|
|
it('should call search api with correct folder kind when searching for a specific term', async () => { |
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
|
|
|
|
|
|
|
|
const query2 = { |
|
|
|
const query = { |
|
|
|
query: 'test', |
|
|
|
query: 'test', |
|
|
|
kind: ['folder'], |
|
|
|
kind: ['folder'], |
|
|
|
location: 'any', |
|
|
|
location: 'any', |
|
|
|
sort: 'name_sort', |
|
|
|
sort: 'name_sort', |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await sqlSearcher.search(query2); |
|
|
|
await sqlSearcher.search(query); |
|
|
|
|
|
|
|
|
|
|
|
expect(searchMock).toHaveBeenLastCalledWith('/api/search', { |
|
|
|
expect(searchMock).toHaveBeenLastCalledWith('/api/search', { |
|
|
|
limit: 1000, |
|
|
|
limit: 1000, |
|
|
|
sort: query2.sort, |
|
|
|
sort: query.sort, |
|
|
|
query: query2.query, |
|
|
|
query: query.query, |
|
|
|
tag: undefined, |
|
|
|
tag: undefined, |
|
|
|
|
|
|
|
type: DashboardSearchItemType.DashFolder, |
|
|
|
folderIds: [0], |
|
|
|
folderIds: [0], |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
searchMock.mockClear(); |
|
|
|
it('should call search api with correct folder kind when searching with a specific uid', async () => { |
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
|
|
|
|
|
|
|
|
const query3 = { |
|
|
|
const query = { |
|
|
|
query: 'test', |
|
|
|
query: 'test', |
|
|
|
kind: ['folder'], |
|
|
|
kind: ['folder'], |
|
|
|
location: 'any', |
|
|
|
location: 'any', |
|
|
@ -82,25 +86,23 @@ describe('SQLSearcher', () => { |
|
|
|
uid: ['T202C0Tnk'], |
|
|
|
uid: ['T202C0Tnk'], |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await sqlSearcher.search(query3); |
|
|
|
await sqlSearcher.search(query); |
|
|
|
|
|
|
|
|
|
|
|
expect(searchMock).toHaveBeenLastCalledWith('/api/search', { |
|
|
|
expect(searchMock).toHaveBeenLastCalledWith('/api/search', { |
|
|
|
limit: 1000, |
|
|
|
limit: 1000, |
|
|
|
sort: query3.sort, |
|
|
|
sort: query.sort, |
|
|
|
query: query3.query, |
|
|
|
query: query.query, |
|
|
|
tag: undefined, |
|
|
|
tag: undefined, |
|
|
|
dashboardUID: query3.uid, |
|
|
|
dashboardUID: query.uid, |
|
|
|
|
|
|
|
type: DashboardSearchItemType.DashFolder, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
it('starred should call search api with correct query', async () => { |
|
|
|
it('starred should call search api with correct query', async () => { |
|
|
|
searchMock.mockResolvedValue([]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
|
|
|
|
|
|
|
|
const query = { |
|
|
|
const query = { |
|
|
|
query: 'test', |
|
|
|
query: 'test', |
|
|
|
kind: ['folder'], |
|
|
|
|
|
|
|
location: 'any', |
|
|
|
location: 'any', |
|
|
|
sort: 'name_sort', |
|
|
|
sort: 'name_sort', |
|
|
|
uid: ['T202C0Tnk'], |
|
|
|
uid: ['T202C0Tnk'], |
|
|
@ -126,7 +128,6 @@ describe('SQLSearcher', () => { |
|
|
|
{ from: 50, expectedPage: 2 }, |
|
|
|
{ from: 50, expectedPage: 2 }, |
|
|
|
{ from: 150, expectedPage: 4 }, |
|
|
|
{ from: 150, expectedPage: 4 }, |
|
|
|
])('should search page $expectedPage when skipping $from results', async ({ from, expectedPage }) => { |
|
|
|
])('should search page $expectedPage when skipping $from results', async ({ from, expectedPage }) => { |
|
|
|
searchMock.mockResolvedValue([]); |
|
|
|
|
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
const sqlSearcher = new SQLSearcher(); |
|
|
|
|
|
|
|
|
|
|
|
await sqlSearcher.search({ |
|
|
|
await sqlSearcher.search({ |
|
|
|