summaryrefslogtreecommitdiff
path: root/spec/javascripts/ide/components/ide_spec.js
blob: 7bfcfc905727b6196b993432fd9aa35fd1dabca5 (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
import Vue from 'vue';
import Mousetrap from 'mousetrap';
import store from '~/ide/stores';
import ide from '~/ide/components/ide.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { file, resetStore } from '../helpers';

describe('ide component', () => {
  let vm;

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

    vm = createComponentWithStore(Component, store, {
      emptyStateSvgPath: 'svg',
      noChangesStateSvgPath: 'svg',
      committedStateSvgPath: 'svg',
    }).$mount();
  });

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

    resetStore(vm.$store);
  });

  it('does not render panel right when no files open', () => {
    expect(vm.$el.querySelector('.panel-right')).toBeNull();
  });

  it('renders panel right when files are open', done => {
    vm.$store.state.trees['abcproject/mybranch'] = {
      tree: [file()],
    };

    Vue.nextTick(() => {
      expect(vm.$el.querySelector('.panel-right')).toBeNull();

      done();
    });
  });

  describe('file finder', () => {
    beforeEach(done => {
      spyOn(vm, 'toggleFileFinder');

      vm.$store.state.fileFindVisible = true;

      vm.$nextTick(done);
    });

    it('calls toggleFileFinder on `t` key press', done => {
      Mousetrap.trigger('t');

      vm
        .$nextTick()
        .then(() => {
          expect(vm.toggleFileFinder).toHaveBeenCalled();
        })
        .then(done)
        .catch(done.fail);
    });

    it('calls toggleFileFinder on `command+p` key press', done => {
      Mousetrap.trigger('command+p');

      vm
        .$nextTick()
        .then(() => {
          expect(vm.toggleFileFinder).toHaveBeenCalled();
        })
        .then(done)
        .catch(done.fail);
    });

    it('calls toggleFileFinder on `ctrl+p` key press', done => {
      Mousetrap.trigger('ctrl+p');

      vm
        .$nextTick()
        .then(() => {
          expect(vm.toggleFileFinder).toHaveBeenCalled();
        })
        .then(done)
        .catch(done.fail);
    });

    it('always allows `command+p` to trigger toggleFileFinder', () => {
      expect(
        vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'command+p'),
      ).toBe(false);
    });

    it('always allows `ctrl+p` to trigger toggleFileFinder', () => {
      expect(
        vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 'ctrl+p'),
      ).toBe(false);
    });

    it('onlys handles `t` when focused in input-field', () => {
      expect(
        vm.mousetrapStopCallback(null, vm.$el.querySelector('.dropdown-input-field'), 't'),
      ).toBe(true);
    });
  });
});