blob: 1992a7f4437f1c92e2bd3993ece4ff737328510e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import setHighlightClass from 'ee_else_ce/search/highlight_blob_search_result';
import { initSearchApp } from '~/search';
import createStore from '~/search/store';
jest.mock('~/search/store');
jest.mock('~/search/topbar');
jest.mock('~/search/sidebar');
jest.mock('ee_else_ce/search/highlight_blob_search_result');
describe('initSearchApp', () => {
let defaultLocation;
const setUrl = (query) => {
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 } });
expect(setHighlightClass).toHaveBeenCalledWith(decodedSearch);
});
});
});
|