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

toggle_replies_widget_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: 8c3696e88b7c65c0d8778e429c1ed9c1aadac317 (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
import { mountExtended } from 'helpers/vue_test_utils_helper';
import ToggleRepliesWidget from '~/notes/components/toggle_replies_widget.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
import { note } from '../mock_data';

describe('toggle replies widget for notes', () => {
  let wrapper;

  const deepCloneObject = (obj) => JSON.parse(JSON.stringify(obj));

  const noteFromOtherUser = deepCloneObject(note);
  noteFromOtherUser.author.username = 'fatihacet';

  const noteFromAnotherUser = deepCloneObject(note);
  noteFromAnotherUser.author.username = 'mgreiling';
  noteFromAnotherUser.author.name = 'Mike Greiling';

  const replies = [note, note, note, noteFromOtherUser, noteFromAnotherUser];

  const findCollapseToggleButton = () =>
    wrapper.findByRole('button', { text: ToggleRepliesWidget.i18n.collapseReplies });
  const findExpandToggleButton = () =>
    wrapper.findByRole('button', { text: ToggleRepliesWidget.i18n.expandReplies });
  const findRepliesButton = () => wrapper.findByRole('button', { text: '5 replies' });
  const findTimeAgoTooltip = () => wrapper.findComponent(TimeAgoTooltip);
  const findUserAvatarLink = () => wrapper.findAllComponents(UserAvatarLink);
  const findUserLink = () => wrapper.findByRole('link', { text: noteFromAnotherUser.author.name });

  const mountComponent = ({ collapsed = false }) =>
    mountExtended(ToggleRepliesWidget, { propsData: { replies, collapsed } });

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

  describe('collapsed state', () => {
    beforeEach(() => {
      wrapper = mountComponent({ collapsed: true });
    });

    it('renders collapsed state elements', () => {
      expect(findExpandToggleButton().exists()).toBe(true);
      expect(findUserAvatarLink()).toHaveLength(3);
      expect(findRepliesButton().exists()).toBe(true);
      expect(wrapper.text()).toContain('Last reply by');
      expect(findUserLink().exists()).toBe(true);
      expect(findTimeAgoTooltip().exists()).toBe(true);
    });

    it('emits "toggle" event when expand toggle button is clicked', () => {
      findExpandToggleButton().trigger('click');

      expect(wrapper.emitted('toggle')).toEqual([[]]);
    });

    it('emits "toggle" event when replies button is clicked', () => {
      findRepliesButton().trigger('click');

      expect(wrapper.emitted('toggle')).toEqual([[]]);
    });
  });

  describe('expanded state', () => {
    beforeEach(() => {
      wrapper = mountComponent({ collapsed: false });
    });

    it('renders expanded state elements', () => {
      expect(findCollapseToggleButton().exists()).toBe(true);
    });

    it('emits "toggle" event when collapse toggle button is clicked', () => {
      findCollapseToggleButton().trigger('click');

      expect(wrapper.emitted('toggle')).toEqual([[]]);
    });
  });
});