summaryrefslogtreecommitdiff
path: root/spec/frontend/issue_show/components/pinned_links_spec.js
blob: 50041667a61fc6946e7e55a43dfbbdc4e4edcff1 (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
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlLink } from '@gitlab/ui';
import PinnedLinks from '~/issue_show/components/pinned_links.vue';

const localVue = createLocalVue();

const plainZoomUrl = 'https://zoom.us/j/123456789';
const vanityZoomUrl = 'https://gitlab.zoom.us/j/123456789';
const startZoomUrl = 'https://zoom.us/s/123456789';
const personalZoomUrl = 'https://zoom.us/my/hunter-zoloman';
const randomUrl = 'https://zoom.us.com';

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

  const link = {
    get text() {
      return wrapper.find(GlLink).text();
    },
    get href() {
      return wrapper.find(GlLink).attributes('href');
    },
  };

  const createComponent = props => {
    wrapper = shallowMount(localVue.extend(PinnedLinks), {
      localVue,
      sync: false,
      propsData: {
        descriptionHtml: '',
        ...props,
      },
    });
  };

  it('displays Zoom link', () => {
    createComponent({
      descriptionHtml: `<a href="${plainZoomUrl}">Zoom</a>`,
    });

    expect(link.text).toBe('Join Zoom meeting');
  });

  it('detects plain Zoom link', () => {
    createComponent({
      descriptionHtml: `<a href="${plainZoomUrl}">Zoom</a>`,
    });

    expect(link.href).toBe(plainZoomUrl);
  });

  it('detects vanity Zoom link', () => {
    createComponent({
      descriptionHtml: `<a href="${vanityZoomUrl}">Zoom</a>`,
    });

    expect(link.href).toBe(vanityZoomUrl);
  });

  it('detects Zoom start meeting link', () => {
    createComponent({
      descriptionHtml: `<a href="${startZoomUrl}">Zoom</a>`,
    });

    expect(link.href).toBe(startZoomUrl);
  });

  it('detects personal Zoom room link', () => {
    createComponent({
      descriptionHtml: `<a href="${personalZoomUrl}">Zoom</a>`,
    });

    expect(link.href).toBe(personalZoomUrl);
  });

  it('only renders final Zoom link in description', () => {
    createComponent({
      descriptionHtml: `<a href="${plainZoomUrl}">Zoom</a><a href="${vanityZoomUrl}">Zoom</a>`,
    });

    expect(link.href).toBe(vanityZoomUrl);
  });

  it('does not render for other links', () => {
    createComponent({
      descriptionHtml: `<a href="${randomUrl}">Some other link</a>`,
    });

    expect(wrapper.find(GlLink).exists()).toBe(false);
  });
});