summaryrefslogtreecommitdiff
path: root/spec/frontend/notes/components/note_attachment_spec.js
blob: 9d1051676e174b1b50c5857a45ae12022668a435 (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
import { shallowMount } from '@vue/test-utils';
import NoteAttachment from '~/notes/components/note_attachment.vue';

describe('Issue note attachment', () => {
  let wrapper;

  const findImage = () => wrapper.find({ ref: 'attachmentImage' });
  const findUrl = () => wrapper.find({ ref: 'attachmentUrl' });

  const createComponent = attachment => {
    wrapper = shallowMount(NoteAttachment, {
      propsData: {
        attachment,
      },
    });
  };

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

  it('renders attachment image if it is passed in attachment prop', () => {
    createComponent({
      image: 'test-image',
    });

    expect(findImage().exists()).toBe(true);
  });

  it('renders attachment url if it is passed in attachment prop', () => {
    createComponent({
      url: 'test-url',
    });

    expect(findUrl().exists()).toBe(true);
  });

  it('does not render image and url if attachment object is empty', () => {
    createComponent({});

    expect(findImage().exists()).toBe(false);
    expect(findUrl().exists()).toBe(false);
  });
});