summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/repo_tabs_spec.js
blob: cb785ba2cd3c4eeded0965435da48538cc102835 (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
import Vue from 'vue';
import repoTabs from '~/ide/components/repo_tabs.vue';
import createComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';

describe('RepoTabs', () => {
  const openedFiles = [file('open1'), file('open2')];
  const RepoTabs = Vue.extend(repoTabs);
  let vm;

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

  it('renders a list of tabs', done => {
    vm = createComponent(RepoTabs, {
      files: openedFiles,
      viewer: 'editor',
      hasChanges: false,
      activeFile: file('activeFile'),
      hasMergeRequest: false,
    });
    openedFiles[0].active = true;

    vm.$nextTick(() => {
      const tabs = [...vm.$el.querySelectorAll('.multi-file-tab')];

      expect(tabs.length).toEqual(2);
      expect(tabs[0].classList.contains('active')).toEqual(true);
      expect(tabs[1].classList.contains('active')).toEqual(false);

      done();
    });
  });

  describe('updated', () => {
    it('sets showShadow as true when scroll width is larger than width', done => {
      const el = document.createElement('div');
      el.innerHTML = '<div id="test-app"></div>';
      document.body.appendChild(el);

      const style = document.createElement('style');
      style.innerText = `
        .multi-file-tabs {
          width: 100px;
        }

        .multi-file-tabs .list-unstyled {
          display: flex;
          overflow-x: auto;
        }
      `;
      document.head.appendChild(style);

      vm = createComponent(
        RepoTabs,
        {
          files: [],
          viewer: 'editor',
          hasChanges: false,
          activeFile: file('activeFile'),
          hasMergeRequest: false,
        },
        '#test-app',
      );

      vm
        .$nextTick()
        .then(() => {
          expect(vm.showShadow).toEqual(false);

          vm.files = openedFiles;
        })
        .then(vm.$nextTick)
        .then(() => {
          expect(vm.showShadow).toEqual(true);

          style.remove();
          el.remove();
        })
        .then(done)
        .catch(done.fail);
    });
  });
});