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

mr_widget_merging_spec.js « states « components « vue_merge_request_widget « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 328c013436885199606e614def8a3d74fb283b43 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import simplePoll from '~/lib/utils/simple_poll';
import MrWidgetMerging from '~/vue_merge_request_widget/components/states/mr_widget_merging.vue';
import BoldText from '~/vue_merge_request_widget/components/bold_text.vue';
import { STATUS_MERGED } from '~/issues/constants';
import { fetchUserCounts } from '~/super_sidebar/user_counts_fetch';

jest.mock('~/super_sidebar/user_counts_fetch');
jest.mock('~/lib/utils/simple_poll', () =>
  jest.fn().mockImplementation(jest.requireActual('~/lib/utils/simple_poll').default),
);

describe('MRWidgetMerging', () => {
  let wrapper;

  const pollMock = jest.fn().mockResolvedValue();

  const GlEmoji = { template: '<img />' };
  const createComponent = () => {
    wrapper = shallowMount(MrWidgetMerging, {
      propsData: {
        mr: {
          targetBranchPath: '/branch-path',
          targetBranch: 'branch',
          transitionStateMachine() {},
        },
        service: {
          poll: pollMock,
        },
      },
      stubs: {
        GlEmoji,
      },
    });
  };

  it('renders information about merge request being merged', () => {
    createComponent();

    const message = wrapper.findComponent(BoldText).props('message');
    expect(message).toContain('Merging!');
  });

  describe('initiateMergePolling', () => {
    beforeEach(createComponent);

    it('should call simplePoll', () => {
      expect(simplePoll).toHaveBeenCalledWith(expect.any(Function), { timeout: 0 });
    });

    it('should call handleMergePolling', () => {
      expect(pollMock).toHaveBeenCalled();
    });
  });

  describe('on successful merge', () => {
    it('should re-fetch user counts', async () => {
      pollMock.mockResolvedValueOnce({ data: { state: STATUS_MERGED } });
      createComponent();

      await nextTick();

      expect(fetchUserCounts).toHaveBeenCalled();
    });
  });
});