2021-03-11 19:13:27 +05:30
|
|
|
import setHighlightClass from 'ee_else_ce/search/highlight_blob_search_result';
|
2021-01-29 00:20:46 +05:30
|
|
|
import { initSearchApp } from '~/search';
|
|
|
|
import createStore from '~/search/store';
|
|
|
|
|
|
|
|
jest.mock('~/search/store');
|
2021-02-22 17:27:13 +05:30
|
|
|
jest.mock('~/search/topbar');
|
2021-01-29 00:20:46 +05:30
|
|
|
jest.mock('~/search/sidebar');
|
2021-03-11 19:13:27 +05:30
|
|
|
jest.mock('ee_else_ce/search/highlight_blob_search_result');
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
describe('initSearchApp', () => {
|
|
|
|
let defaultLocation;
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const setUrl = (query) => {
|
2021-01-29 00:20:46 +05:30
|
|
|
window.location.href = `https://localhost:3000/search${query}`;
|
|
|
|
window.location.search = query;
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
defaultLocation = window.location;
|
|
|
|
Object.defineProperty(window, 'location', {
|
|
|
|
writable: true,
|
|
|
|
value: { href: '', search: '' },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
window.location = defaultLocation;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
search | decodedSearch
|
|
|
|
${'test'} | ${'test'}
|
|
|
|
${'%2520'} | ${'%20'}
|
|
|
|
${'test%2Bthis%2Bstuff'} | ${'test+this+stuff'}
|
|
|
|
${'test+this+stuff'} | ${'test this stuff'}
|
|
|
|
${'test+%2B+this+%2B+stuff'} | ${'test + this + stuff'}
|
|
|
|
${'test%2B+%2Bthis%2B+%2Bstuff'} | ${'test+ +this+ +stuff'}
|
|
|
|
${'test+%2520+this+%2520+stuff'} | ${'test %20 this %20 stuff'}
|
|
|
|
`('parameter decoding', ({ search, decodedSearch }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
setUrl(`?search=${search}`);
|
|
|
|
initSearchApp();
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`decodes ${search} to ${decodedSearch}`, () => {
|
|
|
|
expect(createStore).toHaveBeenCalledWith({ query: { search: decodedSearch } });
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(setHighlightClass).toHaveBeenCalledWith(decodedSearch);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|