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

discussion_actions_spec.js « components « notes « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0a52c81571ed0bbd76eb4497a0ebe017324bc32e (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import createStore from '~/notes/stores';
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
import { discussionMock } from '../../../javascripts/notes/mock_data';
import DiscussionActions from '~/notes/components/discussion_actions.vue';
import ReplyPlaceholder from '~/notes/components/discussion_reply_placeholder.vue';
import ResolveDiscussionButton from '~/notes/components/discussion_resolve_button.vue';
import ResolveWithIssueButton from '~/notes/components/discussion_resolve_with_issue_button.vue';
import JumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue';

describe('DiscussionActions', () => {
  let wrapper;
  const createComponentFactory = (shallow = true) => props => {
    const localVue = createLocalVue();
    const store = createStore();
    const mountFn = shallow ? shallowMount : mount;

    wrapper = mountFn(DiscussionActions, {
      localVue,
      store,
      propsData: {
        discussion: discussionMock,
        isResolving: false,
        resolveButtonTitle: 'Resolve discussion',
        resolveWithIssuePath: '/some/issue/path',
        shouldShowJumpToNextDiscussion: true,
        ...props,
      },
    });
  };

  afterEach(() => {
    wrapper.destroy();
  });

  describe('rendering', () => {
    const createComponent = createComponentFactory();

    it('renders reply placeholder, resolve discussion button, resolve with issue button and jump to next discussion button', () => {
      createComponent();
      expect(wrapper.find(ReplyPlaceholder).exists()).toBe(true);
      expect(wrapper.find(ResolveDiscussionButton).exists()).toBe(true);
      expect(wrapper.find(ResolveWithIssueButton).exists()).toBe(true);
      expect(wrapper.find(JumpToNextDiscussionButton).exists()).toBe(true);
    });

    it('only renders reply placholder if disccusion is not resolvable', () => {
      const discussion = { ...discussionMock };
      discussion.resolvable = false;
      createComponent({ discussion });

      expect(wrapper.find(ReplyPlaceholder).exists()).toBe(true);
      expect(wrapper.find(ResolveDiscussionButton).exists()).toBe(false);
      expect(wrapper.find(ResolveWithIssueButton).exists()).toBe(false);
      expect(wrapper.find(JumpToNextDiscussionButton).exists()).toBe(false);
    });

    it('does not render resolve with issue button if resolveWithIssuePath is falsy', () => {
      createComponent({ resolveWithIssuePath: '' });

      expect(wrapper.find(ResolveWithIssueButton).exists()).toBe(false);
    });

    it('does not render jump to next discussion button if shouldShowJumpToNextDiscussion is false', () => {
      createComponent({ shouldShowJumpToNextDiscussion: false });

      expect(wrapper.find(JumpToNextDiscussionButton).exists()).toBe(false);
    });
  });

  describe('events handling', () => {
    const createComponent = createComponentFactory(false);

    beforeEach(() => {
      createComponent();
    });

    it('emits showReplyForm event when clicking on reply placeholder', () => {
      jest.spyOn(wrapper.vm, '$emit');
      wrapper
        .find(ReplyPlaceholder)
        .find('button')
        .trigger('click');
      expect(wrapper.vm.$emit).toHaveBeenCalledWith('showReplyForm');
    });

    it('emits resolve event when clicking on resolve button', () => {
      jest.spyOn(wrapper.vm, '$emit');
      wrapper
        .find(ResolveDiscussionButton)
        .find('button')
        .trigger('click');
      expect(wrapper.vm.$emit).toHaveBeenCalledWith('resolve');
    });

    it('emits jumpToNextDiscussion event when clicking on jump to next discussion button', () => {
      jest.spyOn(wrapper.vm, '$emit');
      wrapper
        .find(JumpToNextDiscussionButton)
        .find('button')
        .trigger('click');
      expect(wrapper.vm.$emit).toHaveBeenCalledWith('jumpToNextDiscussion');
    });
  });
});