Welcome to mirror list, hosted at ThFree Co, Russian Federation.

nav_dropdown_button_spec.js « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c98aa313f407dc7a711c03f9a283b9fc1d1afddc (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
92
93
import Vue from 'vue';
import { trimText } from 'helpers/text_helper';
import { mountComponentWithStore } from 'helpers/vue_mount_component_helper';
import NavDropdownButton from '~/ide/components/nav_dropdown_button.vue';
import { createStore } from '~/ide/stores';

describe('NavDropdown', () => {
  const TEST_BRANCH_ID = 'lorem-ipsum-dolar';
  const TEST_MR_ID = '12345';
  let store;
  let vm;

  beforeEach(() => {
    store = createStore();
  });

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

  const createComponent = (props = {}) => {
    vm = mountComponentWithStore(Vue.extend(NavDropdownButton), { props, store });
    vm.$mount();
  };

  const findIcon = name => vm.$el.querySelector(`[data-testid="${name}-icon"]`);
  const findMRIcon = () => findIcon('merge-request');
  const findBranchIcon = () => findIcon('branch');

  describe('normal', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders empty placeholders, if state is falsey', () => {
      expect(trimText(vm.$el.textContent)).toEqual('- -');
    });

    it('renders branch name, if state has currentBranchId', done => {
      vm.$store.state.currentBranchId = TEST_BRANCH_ID;

      vm.$nextTick()
        .then(() => {
          expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} -`);
        })
        .then(done)
        .catch(done.fail);
    });

    it('renders mr id, if state has currentMergeRequestId', done => {
      vm.$store.state.currentMergeRequestId = TEST_MR_ID;

      vm.$nextTick()
        .then(() => {
          expect(trimText(vm.$el.textContent)).toEqual(`- !${TEST_MR_ID}`);
        })
        .then(done)
        .catch(done.fail);
    });

    it('renders branch and mr, if state has both', done => {
      vm.$store.state.currentBranchId = TEST_BRANCH_ID;
      vm.$store.state.currentMergeRequestId = TEST_MR_ID;

      vm.$nextTick()
        .then(() => {
          expect(trimText(vm.$el.textContent)).toEqual(`${TEST_BRANCH_ID} !${TEST_MR_ID}`);
        })
        .then(done)
        .catch(done.fail);
    });

    it('shows icons', () => {
      expect(findBranchIcon()).toBeTruthy();
      expect(findMRIcon()).toBeTruthy();
    });
  });

  describe('with showMergeRequests false', () => {
    beforeEach(() => {
      createComponent({ showMergeRequests: false });
    });

    it('shows single empty placeholder, if state is falsey', () => {
      expect(trimText(vm.$el.textContent)).toEqual('-');
    });

    it('shows only branch icon', () => {
      expect(findBranchIcon()).toBeTruthy();
      expect(findMRIcon()).toBe(null);
    });
  });
});