summaryrefslogtreecommitdiff
path: root/spec/javascripts/repo/components/repo_edit_button_spec.js
blob: 411514009dcffb90270ade976a2e774234ac5ff5 (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
import Vue from 'vue';
import repoEditButton from '~/repo/components/repo_edit_button.vue';
import RepoStore from '~/repo/stores/repo_store';

describe('RepoEditButton', () => {
  function createComponent() {
    const RepoEditButton = Vue.extend(repoEditButton);

    return new RepoEditButton().$mount();
  }

  it('renders an edit button that toggles the view state', (done) => {
    RepoStore.isCommitable = true;
    RepoStore.changedFiles = [];
    RepoStore.binary = false;
    RepoStore.openedFiles = [{}, {}];

    const vm = createComponent();

    expect(vm.$el.tagName).toEqual('BUTTON');
    expect(vm.$el.textContent).toMatch('Edit');

    spyOn(vm, 'editCancelClicked').and.callThrough();

    vm.$el.click();

    Vue.nextTick(() => {
      expect(vm.editCancelClicked).toHaveBeenCalled();
      expect(vm.$el.textContent).toMatch('Cancel edit');
      done();
    });
  });

  it('does not render if not isCommitable', () => {
    RepoStore.isCommitable = false;

    const vm = createComponent();

    expect(vm.$el.innerHTML).toBeUndefined();
  });

  describe('methods', () => {
    describe('editCancelClicked', () => {
      it('sets dialog to open when there are changedFiles');

      it('toggles editMode and calls toggleBlobView');
    });
  });
});