summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/repo_file_spec.js
blob: ff391cb43513626e021d683b111ac9e3c70507bd (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
import Vue from 'vue';
import store from '~/ide/stores';
import repoFile from '~/ide/components/repo_file.vue';
import router from '~/ide/ide_router';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers';

describe('RepoFile', () => {
  let vm;

  function createComponent(propsData) {
    const RepoFile = Vue.extend(repoFile);

    vm = createComponentWithStore(RepoFile, store, propsData);

    vm.$mount();
  }

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

  it('renders link, icon and name', () => {
    createComponent({
      file: file('t4'),
      level: 0,
    });

    const name = vm.$el.querySelector('.ide-file-name');

    expect(name.href).toMatch('');
    expect(name.textContent.trim()).toEqual(vm.file.name);
  });

  it('fires clickFile when the link is clicked', done => {
    spyOn(router, 'push');
    createComponent({
      file: file('t3'),
      level: 0,
    });

    vm.$el.querySelector('.file-name').click();

    setTimeout(() => {
      expect(router.push).toHaveBeenCalledWith(`/project${vm.file.url}`);

      done();
    });
  });

  describe('locked file', () => {
    let f;

    beforeEach(() => {
      f = file('locked file');
      f.file_lock = {
        user: {
          name: 'testuser',
          updated_at: new Date(),
        },
      };

      createComponent({
        file: f,
        level: 0,
      });
    });

    it('renders lock icon', () => {
      expect(vm.$el.querySelector('.file-status-icon')).not.toBeNull();
    });

    it('renders a tooltip', () => {
      expect(
        vm.$el.querySelector('.ide-file-name span:nth-child(2)').dataset
          .originalTitle,
      ).toContain('Locked by testuser');
    });
  });
});