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

discussion_filter_note_spec.js « components « notes « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 52d2e7ce947c8b8da09a85a047427a3af6be1b7e (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
import Vue from 'vue';
import DiscussionFilterNote from '~/notes/components/discussion_filter_note.vue';
import eventHub from '~/notes/event_hub';

import mountComponent from '../../helpers/vue_mount_component_helper';

describe('DiscussionFilterNote component', () => {
  let vm;

  const createComponent = () => {
    const Component = Vue.extend(DiscussionFilterNote);

    return mountComponent(Component);
  };

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

  afterEach(() => {
    vm.$destroy();
  });

  describe('computed', () => {
    describe('timelineContent', () => {
      it('returns string containing instruction for switching feed type', () => {
        expect(vm.timelineContent).toBe(
          "You're only seeing <b>other activity</b> in the feed. To add a comment, switch to one of the following options.",
        );
      });
    });
  });

  describe('methods', () => {
    describe('selectFilter', () => {
      it('emits `dropdownSelect` event on `eventHub` with provided param', () => {
        spyOn(eventHub, '$emit');

        vm.selectFilter(1);

        expect(eventHub.$emit).toHaveBeenCalledWith('dropdownSelect', 1);
      });
    });
  });

  describe('template', () => {
    it('renders component container element', () => {
      expect(vm.$el.classList.contains('discussion-filter-note')).toBe(true);
    });

    it('renders comment icon element', () => {
      expect(vm.$el.querySelector('.timeline-icon svg use').getAttribute('xlink:href')).toContain(
        'comment',
      );
    });

    it('renders filter information note', () => {
      expect(vm.$el.querySelector('.timeline-content').innerText.trim()).toContain(
        "You're only seeing other activity in the feed. To add a comment, switch to one of the following options.",
      );
    });

    it('renders filter buttons', () => {
      const buttonsContainerEl = vm.$el.querySelector('.discussion-filter-actions');

      expect(buttonsContainerEl.querySelector('button:first-child').innerText.trim()).toContain(
        'Show all activity',
      );

      expect(buttonsContainerEl.querySelector('button:last-child').innerText.trim()).toContain(
        'Show comments only',
      );
    });

    it('clicking `Show all activity` button calls `selectFilter("all")` method', () => {
      const showAllBtn = vm.$el.querySelector('.discussion-filter-actions button:first-child');
      spyOn(vm, 'selectFilter');

      showAllBtn.dispatchEvent(new Event('click'));

      expect(vm.selectFilter).toHaveBeenCalledWith(0);
    });

    it('clicking `Show comments only` button calls `selectFilter("comments")` method', () => {
      const showAllBtn = vm.$el.querySelector('.discussion-filter-actions button:last-child');
      spyOn(vm, 'selectFilter');

      showAllBtn.dispatchEvent(new Event('click'));

      expect(vm.selectFilter).toHaveBeenCalledWith(1);
    });
  });
});