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

discussion_notes_replies_wrapper_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: 8d5ea108b50d7154b28d66c096693fd71f515172 (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
import { mount } from '@vue/test-utils';
import DiscussionNotesRepliesWrapper from '~/notes/components/discussion_notes_replies_wrapper.vue';

const TEST_CHILDREN = '<li>Hello!</li><li>World!</li>';

// We have to wrap our SUT with a TestComponent because multiple roots are possible
// because it's a functional component.
const TestComponent = {
  components: { DiscussionNotesRepliesWrapper },
  template: `<ul><discussion-notes-replies-wrapper v-bind="$attrs">${TEST_CHILDREN}</discussion-notes-replies-wrapper></ul>`,
};

describe('DiscussionNotesRepliesWrapper', () => {
  let wrapper;

  const createComponent = (props = {}) => {
    wrapper = mount(TestComponent, {
      propsData: props,
    });
  };

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

  describe('when normal discussion', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders children directly', () => {
      expect(wrapper.element.outerHTML).toEqual(`<ul>${TEST_CHILDREN}</ul>`);
    });
  });

  describe('when diff discussion', () => {
    beforeEach(() => {
      createComponent({
        isDiffDiscussion: true,
      });
    });

    it('wraps children with notes', () => {
      const notes = wrapper.find('li.discussion-collapsible ul.notes');

      expect(notes.exists()).toBe(true);
      expect(notes.element.outerHTML).toEqual(`<ul class="notes">${TEST_CHILDREN}</ul>`);
    });
  });
});