summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/components/repo_tabs_spec.js
blob: 60459e90c48063618fc4141dc4e1c5ca519a8437 (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
import Vue from 'vue';
import RepoStore from '~/repo/stores/repo_store';
import repoTabs from '~/repo/components/repo_tabs.vue';

describe('RepoTabs', () => {
  const openedFiles = [{
    id: 0,
    active: true,
  }, {
    id: 1,
  }];

  function createComponent() {
    const RepoTabs = Vue.extend(repoTabs);

    return new RepoTabs().$mount();
  }

  it('renders a list of tabs', () => {
    RepoStore.openedFiles = openedFiles;

    const vm = createComponent();
    const tabs = [...vm.$el.querySelectorAll(':scope > li')];

    expect(vm.$el.id).toEqual('tabs');
    expect(tabs.length).toEqual(3);
    expect(tabs[0].classList.contains('active')).toBeTruthy();
    expect(tabs[1].classList.contains('active')).toBeFalsy();
    expect(tabs[2].classList.contains('tabs-divider')).toBeTruthy();
  });

  it('does not render a tabs list if not isMini', () => {
    RepoStore.openedFiles = [];

    const vm = createComponent();

    expect(vm.$el.innerHTML).toBeFalsy();
  });

  describe('methods', () => {
    describe('xClicked', () => {
      it('calls removeFromOpenedFiles with file obj', () => {
        const file = {};

        spyOn(RepoStore, 'removeFromOpenedFiles');

        repoTabs.methods.xClicked(file);

        expect(RepoStore.removeFromOpenedFiles).toHaveBeenCalledWith(file);
      });
    });
  });
});