summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/commit_sidebar/list_collapsed_spec.js
blob: 3c7d6192e2c83e835ceb5341c7f1c58cef075968 (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
import Vue from 'vue';
import store from '~/ide/stores';
import listCollapsed from '~/ide/components/commit_sidebar/list_collapsed.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file } from '../../helpers';
import { removeWhitespace } from '../../../helpers/text_helper';

describe('Multi-file editor commit sidebar list collapsed', () => {
  let vm;

  beforeEach(() => {
    const Component = Vue.extend(listCollapsed);

    vm = createComponentWithStore(Component, store, {
      files: [
        {
          ...file('file1'),
          tempFile: true,
        },
        file('file2'),
      ],
      iconName: 'staged',
      title: 'Staged',
    });

    vm.$mount();
  });

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

  it('renders added & modified files count', () => {
    expect(removeWhitespace(vm.$el.textContent).trim()).toBe('1 1');
  });

  describe('addedFilesLength', () => {
    it('returns an length of temp files', () => {
      expect(vm.addedFilesLength).toBe(1);
    });
  });

  describe('modifiedFilesLength', () => {
    it('returns an length of modified files', () => {
      expect(vm.modifiedFilesLength).toBe(1);
    });
  });

  describe('addedFilesIconClass', () => {
    it('includes multi-file-addition when addedFiles is not empty', () => {
      expect(vm.addedFilesIconClass).toContain('multi-file-addition');
    });

    it('excludes multi-file-addition when addedFiles is empty', () => {
      vm.files = [];

      expect(vm.addedFilesIconClass).not.toContain('multi-file-addition');
    });
  });

  describe('modifiedFilesClass', () => {
    it('includes multi-file-modified when addedFiles is not empty', () => {
      expect(vm.modifiedFilesClass).toContain('multi-file-modified');
    });

    it('excludes multi-file-modified when addedFiles is empty', () => {
      vm.files = [];

      expect(vm.modifiedFilesClass).not.toContain('multi-file-modified');
    });
  });
});