mirror of
https://github.com/grafana/grafana.git
synced 2026-07-29 15:59:50 -05:00
search: closes dash search when selecting current dashboard (#10285)
Fixes #10231.
This commit is contained in:
@@ -6,7 +6,7 @@ describe('SearchCtrl', () => {
|
||||
search: (options: any) => {},
|
||||
getDashboardTags: () => {}
|
||||
};
|
||||
let ctrl = new SearchCtrl({}, {}, {}, <SearchSrv>searchSrvStub, { onAppEvent: () => { } });
|
||||
let ctrl = new SearchCtrl({$on: () => {}}, {}, {}, <SearchSrv>searchSrvStub);
|
||||
|
||||
describe('Given an empty result', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { SearchResultsCtrl } from '../components/search/search_results';
|
||||
import { beforeEach, afterEach } from 'test/lib/common';
|
||||
import appEvents from 'app/core/app_events';
|
||||
|
||||
jest.mock('app/core/app_events', () => {
|
||||
return {
|
||||
emit: jest.fn<any>()
|
||||
};
|
||||
});
|
||||
|
||||
describe('SearchResultsCtrl', () => {
|
||||
let ctrl;
|
||||
@@ -94,4 +102,39 @@ describe('SearchResultsCtrl', () => {
|
||||
expect(folderExpanded).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when clicking on a link in search result', () => {
|
||||
const dashPath = 'dashboard/path';
|
||||
const $location = { path: () => dashPath};
|
||||
const appEventsMock = appEvents as any;
|
||||
|
||||
describe('with the same url as current path', () => {
|
||||
beforeEach(() => {
|
||||
ctrl = new SearchResultsCtrl($location);
|
||||
const item = { url: dashPath};
|
||||
ctrl.onItemClick(item);
|
||||
});
|
||||
|
||||
it('should close the search', () => {
|
||||
expect(appEventsMock.emit.mock.calls.length).toBe(1);
|
||||
expect(appEventsMock.emit.mock.calls[0][0]).toBe('hide-dash-search');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a different url than current path', () => {
|
||||
beforeEach(() => {
|
||||
ctrl = new SearchResultsCtrl($location);
|
||||
const item = { url: 'another/path'};
|
||||
ctrl.onItemClick(item);
|
||||
});
|
||||
|
||||
it('should do nothing', () => {
|
||||
expect(appEventsMock.emit.mock.calls.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
appEventsMock.emit.mockClear();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user