summaryrefslogtreecommitdiff
path: root/spec/javascripts/notes/components/note_actions_spec.js
blob: b102b7aecf7ad8d26cd2a1f8b323f3fa8881bb07 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import Vue from 'vue';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import createStore from '~/notes/stores';
import noteActions from '~/notes/components/note_actions.vue';
import { userDataMock } from '../mock_data';

describe('noteActions', () => {
  let wrapper;
  let store;

  beforeEach(() => {
    store = createStore();
  });

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

  describe('user is logged in', () => {
    let props;

    beforeEach(() => {
      props = {
        accessLevel: 'Maintainer',
        authorId: 26,
        canDelete: true,
        canEdit: true,
        canAwardEmoji: true,
        canReportAsAbuse: true,
        noteId: '539',
        noteUrl: 'https://localhost:3000/group/project/merge_requests/1#note_1',
        reportAbusePath:
          '/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F7%23note_539&user_id=26',
      };

      store.dispatch('setUserData', userDataMock);

      const localVue = createLocalVue();
      wrapper = shallowMount(noteActions, {
        store,
        propsData: props,
        localVue,
        sync: false,
      });
    });

    it('should render access level badge', () => {
      expect(
        wrapper
          .find('.note-role')
          .text()
          .trim(),
      ).toEqual(props.accessLevel);
    });

    it('should render emoji link', () => {
      expect(wrapper.find('.js-add-award').exists()).toBe(true);
    });

    describe('actions dropdown', () => {
      it('should be possible to edit the comment', () => {
        expect(wrapper.find('.js-note-edit').exists()).toBe(true);
      });

      it('should be possible to report abuse to GitLab', () => {
        expect(wrapper.find(`a[href="${props.reportAbusePath}"]`).exists()).toBe(true);
      });

      it('should be possible to copy link to a note', () => {
        expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(true);
      });

      it('should not show copy link action when `noteUrl` prop is empty', done => {
        wrapper.setProps({
          ...props,
          noteUrl: '',
        });

        Vue.nextTick()
          .then(() => {
            expect(wrapper.find('.js-btn-copy-note-link').exists()).toBe(false);
          })
          .then(done)
          .catch(done.fail);
      });

      it('should be possible to delete comment', () => {
        expect(wrapper.find('.js-note-delete').exists()).toBe(true);
      });
    });
  });

  describe('user is not logged in', () => {
    let props;

    beforeEach(() => {
      store.dispatch('setUserData', {});
      props = {
        accessLevel: 'Maintainer',
        authorId: 26,
        canDelete: false,
        canEdit: false,
        canAwardEmoji: false,
        canReportAsAbuse: false,
        noteId: '539',
        noteUrl: 'https://localhost:3000/group/project/merge_requests/1#note_1',
        reportAbusePath:
          '/abuse_reports/new?ref_url=http%3A%2F%2Flocalhost%3A3000%2Fgitlab-org%2Fgitlab-ce%2Fissues%2F7%23note_539&user_id=26',
      };
      const localVue = createLocalVue();
      wrapper = shallowMount(noteActions, {
        store,
        propsData: props,
        localVue,
        sync: false,
      });
    });

    it('should not render emoji link', () => {
      expect(wrapper.find('.js-add-award').exists()).toBe(false);
    });

    it('should not render actions dropdown', () => {
      expect(wrapper.find('.more-actions').exists()).toBe(false);
    });
  });
});