debian-mirror-gitlab/spec/frontend/clusters/forms/components/integration_form_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import { GlToggle, GlButton } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2021-03-11 19:13:27 +05:30
import Vuex from 'vuex';
2020-10-24 23:57:45 +05:30
import IntegrationForm from '~/clusters/forms/components/integration_form.vue';
import { createStore } from '~/clusters/forms/stores/index';
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2020-10-24 23:57:45 +05:30
describe('ClusterIntegrationForm', () => {
let wrapper;
const defaultStoreValues = {
enabled: true,
editable: true,
environmentScope: '*',
baseDomain: 'testDomain',
};
const createWrapper = (storeValues = defaultStoreValues) => {
wrapper = shallowMount(IntegrationForm, {
store: createStore(storeValues),
provide: {
autoDevopsHelpPath: 'topics/autodevops/index',
2022-07-16 23:28:13 +05:30
externalEndpointHelpPath: 'user/project/clusters/index.md#base-domain',
2020-10-24 23:57:45 +05:30
},
});
};
const destroyWrapper = () => {
wrapper.destroy();
wrapper = null;
};
2022-08-27 11:52:29 +05:30
const findSubmitButton = () => wrapper.findComponent(GlButton);
const findGlToggle = () => wrapper.findComponent(GlToggle);
2020-10-24 23:57:45 +05:30
afterEach(() => {
destroyWrapper();
});
describe('rendering', () => {
beforeEach(() => createWrapper());
it('enables toggle if editable is true', () => {
2021-04-17 20:07:23 +05:30
expect(findGlToggle().props()).toMatchObject({
disabled: false,
label: IntegrationForm.i18n.toggleLabel,
});
2020-10-24 23:57:45 +05:30
});
2021-04-17 20:07:23 +05:30
2020-10-24 23:57:45 +05:30
it('sets the envScope to default', () => {
expect(wrapper.find('[id="cluster_environment_scope"]').attributes('value')).toBe('*');
});
it('sets the baseDomain to default', () => {
expect(wrapper.find('[id="cluster_base_domain"]').attributes('value')).toBe('testDomain');
});
describe('when editable is false', () => {
beforeEach(() => {
createWrapper({ ...defaultStoreValues, editable: false });
});
it('disables toggle if editable is false', () => {
expect(findGlToggle().props('disabled')).toBe(true);
});
it('does not render the save button', () => {
expect(findSubmitButton().exists()).toBe(false);
});
});
});
describe('reactivity', () => {
beforeEach(() => createWrapper());
2022-04-04 11:22:00 +05:30
it('enables the submit button on changing toggle to different value', async () => {
await nextTick();
// setData is a bad approach because it changes the internal implementation which we should not touch
// but our GlFormInput lacks the ability to set a new value.
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ toggleEnabled: !defaultStoreValues.enabled });
expect(findSubmitButton().props('disabled')).toBe(false);
2020-10-24 23:57:45 +05:30
});
2022-04-04 11:22:00 +05:30
it('enables the submit button on changing input values', async () => {
await nextTick();
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
await wrapper.setData({ envScope: `${defaultStoreValues.environmentScope}1` });
expect(findSubmitButton().props('disabled')).toBe(false);
2020-10-24 23:57:45 +05:30
});
});
});