Welcome to mirror list, hosted at ThFree Co, Russian Federation.

refresh_counts_spec.js « show « search « pages « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81c9bf743085bc52852e44246b8d92c62acd0f1a (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
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();
    });
  });
});