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

stage_button_spec.js « commit_sidebar « components « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b59de4dac0ee72978796b531de5afec0959fca30 (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
import Vue from 'vue';
import store from '~/ide/stores';
import stageButton from '~/ide/components/commit_sidebar/stage_button.vue';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { file, resetStore } from '../../helpers';

describe('IDE stage file button', () => {
  let vm;
  let f;

  beforeEach(() => {
    const Component = Vue.extend(stageButton);
    f = file();

    vm = createComponentWithStore(Component, store, {
      path: f.path,
    });

    jest.spyOn(vm, 'stageChange').mockImplementation(() => {});
    jest.spyOn(vm, 'discardFileChanges').mockImplementation(() => {});

    vm.$mount();
  });

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

    resetStore(vm.$store);
  });

  it('renders button to discard & stage', () => {
    expect(vm.$el.querySelectorAll('.btn-blank').length).toBe(2);
  });

  it('calls store with stage button', () => {
    vm.$el.querySelectorAll('.btn')[0].click();

    expect(vm.stageChange).toHaveBeenCalledWith(f.path);
  });

  it('calls store with discard button', () => {
    vm.$el.querySelector('.btn-danger').click();

    expect(vm.discardFileChanges).toHaveBeenCalledWith(f.path);
  });
});