summaryrefslogtreecommitdiff
path: root/spec/frontend/content_editor/components/wrappers/image_spec.js
blob: 7b057f9cabc3e453ad57042020958a5683a95491 (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
import { GlLoadingIcon } from '@gitlab/ui';
import { NodeViewWrapper } from '@tiptap/vue-2';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ImageWrapper from '~/content_editor/components/wrappers/image.vue';

describe('content/components/wrappers/image', () => {
  let wrapper;

  const createWrapper = async (nodeAttrs = {}) => {
    wrapper = shallowMountExtended(ImageWrapper, {
      propsData: {
        node: {
          attrs: nodeAttrs,
        },
      },
    });
  };
  const findImage = () => wrapper.findByTestId('image');
  const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);

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

  it('renders a node-view-wrapper with display-inline-block class', () => {
    createWrapper();

    expect(wrapper.findComponent(NodeViewWrapper).classes()).toContain('gl-display-inline-block');
  });

  it('renders an image that displays the node src', () => {
    const src = 'foobar.png';

    createWrapper({ src });

    expect(findImage().attributes().src).toBe(src);
  });

  describe('when uploading', () => {
    beforeEach(() => {
      createWrapper({ uploading: true });
    });

    it('renders a gl-loading-icon component', () => {
      expect(findLoadingIcon().exists()).toBe(true);
    });

    it('adds gl-opacity-5 class selector to image', () => {
      expect(findImage().classes()).toContain('gl-opacity-5');
    });
  });

  describe('when not uploading', () => {
    beforeEach(() => {
      createWrapper({ uploading: false });
    });

    it('does not render a gl-loading-icon component', () => {
      expect(findLoadingIcon().exists()).toBe(false);
    });

    it('does not add gl-opacity-5 class selector to image', () => {
      expect(findImage().classes()).not.toContain('gl-opacity-5');
    });
  });
});