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

abuse_report_discussion_spec.js « notes « components « abuse_report « admin « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fdc049725a4850676ba2dd94777ce19849e0f8d9 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import ToggleRepliesWidget from '~/notes/components/toggle_replies_widget.vue';
import TimelineEntryItem from '~/vue_shared/components/notes/timeline_entry_item.vue';
import AbuseReportDiscussion from '~/admin/abuse_report/components/notes/abuse_report_discussion.vue';
import AbuseReportNote from '~/admin/abuse_report/components/notes/abuse_report_note.vue';
import AbuseReportAddNote from '~/admin/abuse_report/components/notes/abuse_report_add_note.vue';

import {
  mockAbuseReport,
  mockDiscussionWithNoReplies,
  mockDiscussionWithReplies,
} from '../../mock_data';

describe('Abuse Report Discussion', () => {
  let wrapper;
  const mockAbuseReportId = mockAbuseReport.report.globalId;

  const findAbuseReportNote = () => wrapper.findComponent(AbuseReportNote);
  const findAbuseReportNotes = () => wrapper.findAllComponents(AbuseReportNote);
  const findTimelineEntryItem = () => wrapper.findComponent(TimelineEntryItem);
  const findToggleRepliesWidget = () => wrapper.findComponent(ToggleRepliesWidget);
  const findAbuseReportAddNote = () => wrapper.findComponent(AbuseReportAddNote);

  const createComponent = ({
    discussion = mockDiscussionWithNoReplies,
    abuseReportId = mockAbuseReportId,
  } = {}) => {
    wrapper = shallowMount(AbuseReportDiscussion, {
      propsData: {
        discussion,
        abuseReportId,
      },
    });
  };

  describe('Default', () => {
    beforeEach(() => {
      createComponent();
    });

    it('should show the abuse report note', () => {
      expect(findAbuseReportNote().exists()).toBe(true);

      expect(findAbuseReportNote().props()).toMatchObject({
        abuseReportId: mockAbuseReportId,
        note: mockDiscussionWithNoReplies[0],
        showReplyButton: true,
      });
    });

    it('should not show timeline entry item component', () => {
      expect(findTimelineEntryItem().exists()).toBe(false);
    });

    it('should not show the toggle replies widget wrapper when there are no replies', () => {
      expect(findToggleRepliesWidget().exists()).toBe(false);
    });

    it('should not show the comment form there are no replies', () => {
      expect(findAbuseReportAddNote().exists()).toBe(false);
    });
  });

  describe('When the main comments has replies', () => {
    beforeEach(() => {
      createComponent({
        discussion: mockDiscussionWithReplies,
      });
    });

    it('should show the toggle replies widget', () => {
      expect(findToggleRepliesWidget().exists()).toBe(true);
    });

    it('the number of replies should be equal to the response length', () => {
      expect(findAbuseReportNotes()).toHaveLength(3);
    });

    it('should collapse when we click on toggle replies widget', async () => {
      findToggleRepliesWidget().vm.$emit('toggle');
      await nextTick();
      expect(findAbuseReportNotes()).toHaveLength(1);
    });

    it('should show the comment form', () => {
      expect(findAbuseReportAddNote().exists()).toBe(true);

      expect(findAbuseReportAddNote().props()).toMatchObject({
        abuseReportId: mockAbuseReportId,
        discussionId: mockDiscussionWithReplies[0].discussion.id,
        isNewDiscussion: false,
      });
    });

    it('should show the reply button only for the main comment', () => {
      expect(findAbuseReportNotes().at(0).props('showReplyButton')).toBe(true);

      expect(findAbuseReportNotes().at(1).props('showReplyButton')).toBe(false);
      expect(findAbuseReportNotes().at(2).props('showReplyButton')).toBe(false);
    });
  });

  describe('Replying to a comment when it has no replies', () => {
    beforeEach(() => {
      createComponent();
    });

    it('should show comment form when `startReplying` is emitted', async () => {
      expect(findAbuseReportAddNote().exists()).toBe(false);

      findAbuseReportNote().vm.$emit('startReplying');
      await nextTick();

      expect(findAbuseReportAddNote().exists()).toBe(true);
      expect(findAbuseReportAddNote().props('showCommentForm')).toBe(true);
    });

    it('should hide the comment form when `cancelEditing` is emitted', async () => {
      findAbuseReportNote().vm.$emit('startReplying');
      await nextTick();

      findAbuseReportAddNote().vm.$emit('cancelEditing');
      await nextTick();

      expect(findAbuseReportAddNote().exists()).toBe(false);
    });
  });

  describe('Replying to a comment with replies', () => {
    beforeEach(() => {
      createComponent({
        discussion: mockDiscussionWithReplies,
      });
    });

    it('should show reply textarea, but not comment form', () => {
      expect(findAbuseReportAddNote().exists()).toBe(true);
      expect(findAbuseReportAddNote().props('showCommentForm')).toBe(false);
    });

    it('should show comment form when reply button on main comment is clicked', async () => {
      findAbuseReportNotes().at(0).vm.$emit('startReplying');
      await nextTick();

      expect(findAbuseReportAddNote().props('showCommentForm')).toBe(true);
    });
  });
});