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

item_spec.js « file_finder « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a4a97efb95fc6b3c10c056ca4ed6ffe7c96a37c (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import Vue from 'vue';
import createComponent from 'helpers/vue_mount_component_helper';
import { file } from 'jest/ide/helpers';
import ItemComponent from '~/vue_shared/components/file_finder/item.vue';

describe('File finder item spec', () => {
  const Component = Vue.extend(ItemComponent);
  let vm;
  let localFile;

  beforeEach(() => {
    localFile = {
      ...file(),
      name: 'test file',
      path: 'test/file',
    };

    vm = createComponent(Component, {
      file: localFile,
      focused: true,
      searchText: '',
      index: 0,
    });
  });

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

  it('renders file name & path', () => {
    expect(vm.$el.textContent).toContain('test file');
    expect(vm.$el.textContent).toContain('test/file');
  });

  describe('focused', () => {
    it('adds is-focused class', () => {
      expect(vm.$el.classList).toContain('is-focused');
    });

    it('does not have is-focused class when not focused', (done) => {
      vm.focused = false;

      vm.$nextTick(() => {
        expect(vm.$el.classList).not.toContain('is-focused');

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

  describe('changed file icon', () => {
    it('does not render when not a changed or temp file', () => {
      expect(vm.$el.querySelector('.diff-changed-stats')).toBe(null);
    });

    it('renders when a changed file', (done) => {
      vm.file.changed = true;

      vm.$nextTick(() => {
        expect(vm.$el.querySelector('.diff-changed-stats')).not.toBe(null);

        done();
      });
    });

    it('renders when a temp file', (done) => {
      vm.file.tempFile = true;

      vm.$nextTick(() => {
        expect(vm.$el.querySelector('.diff-changed-stats')).not.toBe(null);

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

  it('emits event when clicked', () => {
    jest.spyOn(vm, '$emit').mockImplementation(() => {});

    vm.$el.click();

    expect(vm.$emit).toHaveBeenCalledWith('click', vm.file);
  });

  describe('path', () => {
    let el;

    beforeEach((done) => {
      vm.searchText = 'file';

      el = vm.$el.querySelector('.diff-changed-file-path');

      vm.$nextTick(done);
    });

    it('highlights text', () => {
      expect(el.querySelectorAll('.highlighted').length).toBe(4);
    });

    it('adds ellipsis to long text', (done) => {
      vm.file.path = new Array(70)
        .fill()
        .map((_, i) => `${i}-`)
        .join('');

      vm.$nextTick(() => {
        expect(el.textContent).toBe(`...${vm.file.path.substr(vm.file.path.length - 60)}`);
        done();
      });
    });
  });

  describe('name', () => {
    let el;

    beforeEach((done) => {
      vm.searchText = 'file';

      el = vm.$el.querySelector('.diff-changed-file-name');

      vm.$nextTick(done);
    });

    it('highlights text', () => {
      expect(el.querySelectorAll('.highlighted').length).toBe(4);
    });

    it('does not add ellipsis to long text', (done) => {
      vm.file.name = new Array(70)
        .fill()
        .map((_, i) => `${i}-`)
        .join('');

      vm.$nextTick(() => {
        expect(el.textContent).not.toBe(`...${vm.file.name.substr(vm.file.name.length - 60)}`);
        done();
      });
    });
  });
});