summaryrefslogtreecommitdiff
path: root/spec/frontend/create_cluster/gke_cluster/components/gke_submit_button_spec.js
blob: 9401ba83ef45d6754e646dca8082d7bcb30a7bc7 (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
import Vuex from 'vuex';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import GkeSubmitButton from '~/create_cluster/gke_cluster/components/gke_submit_button.vue';

const localVue = createLocalVue();

localVue.use(Vuex);

describe('GkeSubmitButton', () => {
  let wrapper;
  let store;
  let hasValidData;

  const buildStore = () =>
    new Vuex.Store({
      getters: {
        hasValidData,
      },
    });

  const buildWrapper = () =>
    shallowMount(GkeSubmitButton, {
      store,
      localVue,
    });

  const bootstrap = () => {
    store = buildStore();
    wrapper = buildWrapper();
  };

  beforeEach(() => {
    hasValidData = jest.fn();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('is disabled when hasValidData is false', () => {
    hasValidData.mockReturnValueOnce(false);
    bootstrap();

    expect(wrapper.attributes('disabled')).toBe('disabled');
  });

  it('is not disabled when hasValidData is true', () => {
    hasValidData.mockReturnValueOnce(true);
    bootstrap();

    expect(wrapper.attributes('disabled')).toBeFalsy();
  });
});