summaryrefslogtreecommitdiff
path: root/spec/frontend/search/index_spec.js
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/search/index_spec.js')
-rw-r--r--spec/frontend/search/index_spec.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/frontend/search/index_spec.js b/spec/frontend/search/index_spec.js
new file mode 100644
index 00000000000..8a86cc4c52a
--- /dev/null
+++ b/spec/frontend/search/index_spec.js
@@ -0,0 +1,47 @@
+import { initSearchApp } from '~/search';
+import createStore from '~/search/store';
+
+jest.mock('~/search/store');
+jest.mock('~/search/sidebar');
+jest.mock('~/search/group_filter');
+
+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 } });
+ });
+ });
+});