summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/merge_requests/item_spec.js
blob: 750948cae3c82aef33c0a6109dd9266b0d32d310 (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
import Vue from 'vue';
import router from '~/ide/ide_router';
import Item from '~/ide/components/merge_requests/item.vue';
import mountCompontent from '../../../helpers/vue_mount_component_helper';

describe('IDE merge request item', () => {
  const Component = Vue.extend(Item);
  let vm;

  beforeEach(() => {
    vm = mountCompontent(Component, {
      item: {
        iid: 1,
        projectPathWithNamespace: 'gitlab-org/gitlab-ce',
        title: 'Merge request title',
      },
      currentId: '1',
      currentProjectId: 'gitlab-org/gitlab-ce',
    });
  });

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

  it('renders merge requests data', () => {
    expect(vm.$el.textContent).toContain('Merge request title');
    expect(vm.$el.textContent).toContain('gitlab-org/gitlab-ce!1');
  });

  it('renders link with href', () => {
    const expectedHref = router.resolve(`/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`).href;
    expect(vm.$el).toMatch('a');
    expect(vm.$el).toHaveAttr('href', expectedHref);
  });

  it('renders icon if ID matches currentId', () => {
    expect(vm.$el.querySelector('.ic-mobile-issue-close')).not.toBe(null);
  });

  it('does not render icon if ID does not match currentId', done => {
    vm.currentId = '2';

    vm.$nextTick(() => {
      expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);

      done();
    });
  });

  it('does not render icon if project ID does not match', done => {
    vm.currentProjectId = 'test/test';

    vm.$nextTick(() => {
      expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);

      done();
    });
  });
});