debian-mirror-gitlab/spec/frontend/integrations/edit/components/trigger_field_spec.js

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

97 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-07-23 23:45:48 +05:30
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils';
2023-03-17 16:20:25 +05:30
import { GlFormCheckbox, GlFormInput } from '@gitlab/ui';
2022-07-23 23:45:48 +05:30
import TriggerField from '~/integrations/edit/components/trigger_field.vue';
import { integrationTriggerEventTitles } from '~/integrations/constants';
describe('TriggerField', () => {
let wrapper;
const defaultProps = {
event: { name: 'push_events' },
2023-03-17 16:20:25 +05:30
type: 'gitlab_slack_application',
2022-07-23 23:45:48 +05:30
};
2023-03-17 16:20:25 +05:30
const mockField = { name: 'push_channel' };
2022-07-23 23:45:48 +05:30
const createComponent = ({ props = {}, isInheriting = false } = {}) => {
wrapper = shallowMount(TriggerField, {
propsData: { ...defaultProps, ...props },
computed: {
isInheriting: () => isInheriting,
},
});
};
const findGlFormCheckbox = () => wrapper.findComponent(GlFormCheckbox);
2023-03-17 16:20:25 +05:30
const findGlFormInput = () => wrapper.findComponent(GlFormInput);
2022-07-23 23:45:48 +05:30
const findHiddenInput = () => wrapper.find('input[type="hidden"]');
describe('template', () => {
it('renders enabled GlFormCheckbox', () => {
createComponent();
expect(findGlFormCheckbox().attributes('disabled')).toBeUndefined();
});
it('when isInheriting is true, renders disabled GlFormCheckbox', () => {
createComponent({ isInheriting: true });
2023-07-09 08:55:56 +05:30
expect(findGlFormCheckbox().attributes('disabled')).toBeDefined();
2022-07-23 23:45:48 +05:30
});
it('renders correct title', () => {
createComponent();
expect(findGlFormCheckbox().text()).toMatchInterpolatedText(
integrationTriggerEventTitles[defaultProps.event.name],
);
});
it('sets default value for hidden input', () => {
createComponent();
expect(findHiddenInput().attributes('value')).toBe('false');
});
2023-03-17 16:20:25 +05:30
it('renders hidden GlFormInput', () => {
createComponent({
props: {
event: { name: 'push_events', field: mockField },
},
});
expect(findGlFormInput().exists()).toBe(true);
expect(findGlFormInput().isVisible()).toBe(false);
});
describe('checkbox is selected', () => {
it('renders visible GlFormInput', async () => {
createComponent({
props: {
event: { name: 'push_events', field: mockField },
},
});
await findGlFormCheckbox().vm.$emit('input', true);
expect(findGlFormInput().exists()).toBe(true);
expect(findGlFormInput().isVisible()).toBe(true);
});
});
2022-07-23 23:45:48 +05:30
it('toggles value of hidden input on checkbox input', async () => {
createComponent({
props: { event: { name: 'push_events', value: true } },
});
await nextTick;
expect(findHiddenInput().attributes('value')).toBe('true');
await findGlFormCheckbox().vm.$emit('input', false);
expect(findHiddenInput().attributes('value')).toBe('false');
});
});
});