BigW Consortium Gitlab

repo_edit_button_spec.js 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
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;
14
    RepoStore.changedFiles = [];
Jacob Schatz committed
15 16
    RepoStore.binary = false;
    RepoStore.openedFiles = [{}, {}];
17 18 19 20 21 22

    const vm = createComponent();

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

Jacob Schatz committed
23
    spyOn(vm, 'editCancelClicked').and.callThrough();
Bryce Johnson committed
24
    spyOn(vm, 'toggleProjectRefsForm');
25 26 27 28

    vm.$el.click();

    Vue.nextTick(() => {
Jacob Schatz committed
29
      expect(vm.editCancelClicked).toHaveBeenCalled();
Bryce Johnson committed
30
      expect(vm.toggleProjectRefsForm).toHaveBeenCalled();
31 32 33 34 35 36 37 38 39 40 41 42 43 44
      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', () => {
Jacob Schatz committed
45 46
    describe('editCancelClicked', () => {
      it('sets dialog to open when there are changedFiles');
47

Jacob Schatz committed
48
      it('toggles editMode and calls toggleBlobView');
49 50 51
    });
  });
});