summaryrefslogtreecommitdiff
path: root/spec/javascripts/reports/components/report_link_spec.js
blob: cd6911e2f59dec45aa221ab070814ecc0338bdf0 (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
import Vue from 'vue';
import component from '~/reports/components/report_link.vue';
import mountComponent from '../../helpers/vue_mount_component_helper';

describe('report link', () => {
  let vm;

  const Component = Vue.extend(component);

  afterEach(() => {
    vm.$destroy();
  });

  describe('With url', () => {
    it('renders link', () => {
      vm = mountComponent(Component, {
        issue: {
          path: 'Gemfile.lock',
          urlPath: '/Gemfile.lock',
        },
      });

      expect(vm.$el.textContent.trim()).toContain('in');
      expect(vm.$el.querySelector('a').getAttribute('href')).toEqual('/Gemfile.lock');
      expect(vm.$el.querySelector('a').textContent.trim()).toEqual('Gemfile.lock');
    });
  });

  describe('Without url', () => {
    it('does not render link', () => {
      vm = mountComponent(Component, {
        issue: {
          path: 'Gemfile.lock',
        },
      });

      expect(vm.$el.querySelector('a')).toBeNull();
      expect(vm.$el.textContent.trim()).toContain('in');
      expect(vm.$el.textContent.trim()).toContain('Gemfile.lock');
    });
  });

  describe('with line', () => {
    it('renders line  number', () => {
      vm = mountComponent(Component, {
        issue: {
          path: 'Gemfile.lock',
          urlPath:
            'https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00',
          line: 22,
        },
      });

      expect(vm.$el.querySelector('a').textContent.trim()).toContain('Gemfile.lock:22');
    });
  });

  describe('without line', () => {
    it('does not render line  number', () => {
      vm = mountComponent(Component, {
        issue: {
          path: 'Gemfile.lock',
          urlPath:
            'https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00',
        },
      });

      expect(vm.$el.querySelector('a').textContent.trim()).not.toContain(':22');
    });
  });
});