diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2019-08-05 02:20:52 -0500 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-08-12 22:01:28 +0200 |
commit | 68aab284a11a3c5b261263be9f6ed914d1f46423 (patch) | |
tree | 6999adeeb1657a45b97bff1ae9b4762fe1a47d46 /spec/frontend/pages | |
parent | 49c83155ccb78284b17a9ffa47583ddace5dbd01 (diff) | |
download | gitlab-ce-68aab284a11a3c5b261263be9f6ed914d1f46423.tar.gz |
FE fetch counts async on search page load
Creates `refresh_counts` module to dynamically fetch
and load data based on attributes of HAML elements.
Diffstat (limited to 'spec/frontend/pages')
-rw-r--r-- | spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap | 7 | ||||
-rw-r--r-- | spec/frontend/pages/search/show/refresh_counts_spec.js | 35 |
2 files changed, 42 insertions, 0 deletions
diff --git a/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap b/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap new file mode 100644 index 00000000000..ce456d6c899 --- /dev/null +++ b/spec/frontend/pages/search/show/__snapshots__/refresh_counts_spec.js.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`pages/search/show/refresh_counts fetches and displays search counts 1`] = ` +"<div class=\\"badge\\">22</div> +<div class=\\"badge js-search-count\\" data-url=\\"http://test.host/search/count?search=lorem+ipsum&project_id=3&scope=issues\\">4</div> +<div class=\\"badge js-search-count\\" data-url=\\"http://test.host/search/count?search=lorem+ipsum&project_id=3&scope=merge_requests\\">5</div>" +`; diff --git a/spec/frontend/pages/search/show/refresh_counts_spec.js b/spec/frontend/pages/search/show/refresh_counts_spec.js new file mode 100644 index 00000000000..ead268b3971 --- /dev/null +++ b/spec/frontend/pages/search/show/refresh_counts_spec.js @@ -0,0 +1,35 @@ +import MockAdapter from 'axios-mock-adapter'; +import { TEST_HOST } from 'helpers/test_constants'; +import axios from '~/lib/utils/axios_utils'; +import refreshCounts from '~/pages/search/show/refresh_counts'; + +const URL = `${TEST_HOST}/search/count?search=lorem+ipsum&project_id=3`; +const urlWithScope = scope => `${URL}&scope=${scope}`; +const counts = [{ scope: 'issues', count: 4 }, { scope: 'merge_requests', count: 5 }]; +const fixture = `<div class="badge">22</div> +<div class="badge js-search-count hidden" data-url="${urlWithScope('issues')}"></div> +<div class="badge js-search-count hidden" data-url="${urlWithScope('merge_requests')}"></div>`; + +describe('pages/search/show/refresh_counts', () => { + let mock; + + beforeEach(() => { + mock = new MockAdapter(axios); + setFixtures(fixture); + }); + + afterEach(() => { + mock.restore(); + }); + + it('fetches and displays search counts', () => { + counts.forEach(({ scope, count }) => { + mock.onGet(urlWithScope(scope)).reply(200, { count }); + }); + + // assert before act behavior + return refreshCounts().then(() => { + expect(document.body.innerHTML).toMatchSnapshot(); + }); + }); +}); |