summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_shared/components/rich_content_editor/modals/insert_video_modal_spec.js
blob: d59d4cc1de9cf6d5aafc6933d8e4d07bf6e5a9e4 (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
import { shallowMount } from '@vue/test-utils';
import { GlModal } from '@gitlab/ui';
import InsertVideoModal from '~/vue_shared/components/rich_content_editor/modals/insert_video_modal.vue';

describe('Insert Video Modal', () => {
  let wrapper;

  const findModal = () => wrapper.find(GlModal);
  const findUrlInput = () => wrapper.find({ ref: 'urlInput' });

  const triggerInsertVideo = (url) => {
    const preventDefault = jest.fn();
    findUrlInput().vm.$emit('input', url);
    findModal().vm.$emit('primary', { preventDefault });
  };

  beforeEach(() => {
    wrapper = shallowMount(InsertVideoModal);
  });

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

  describe('when content is loaded', () => {
    it('renders a modal component', () => {
      expect(findModal().exists()).toBe(true);
    });

    it('renders an input to add a URL', () => {
      expect(findUrlInput().exists()).toBe(true);
    });
  });

  describe('insert video', () => {
    it.each`
      url                                       | emitted
      ${'https://www.youtube.com/embed/someId'} | ${[['https://www.youtube.com/embed/someId']]}
      ${'https://www.youtube.com/watch?v=1234'} | ${[['https://www.youtube.com/embed/1234']]}
      ${'::youtube.com/invalid/url'}            | ${undefined}
    `('formats the url correctly', ({ url, emitted }) => {
      triggerInsertVideo(url);
      expect(wrapper.emitted('insertVideo')).toEqual(emitted);
    });
  });
});