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

159 lines
4.6 KiB
JavaScript
Raw Normal View History

2020-05-24 23:13:21 +05:30
import { GlFormGroup, GlFormCheckbox, GlFormInput } from '@gitlab/ui';
2021-09-04 01:27:46 +05:30
import { mountExtended } from 'helpers/vue_test_utils_helper';
2020-10-24 23:57:45 +05:30
import TriggerFields from '~/integrations/edit/components/trigger_fields.vue';
2020-05-24 23:13:21 +05:30
describe('TriggerFields', () => {
let wrapper;
const defaultProps = {
type: 'slack',
};
2020-07-28 23:09:34 +05:30
const createComponent = (props, isInheriting = false) => {
2021-09-04 01:27:46 +05:30
wrapper = mountExtended(TriggerFields, {
2020-05-24 23:13:21 +05:30
propsData: { ...defaultProps, ...props },
2020-07-28 23:09:34 +05:30
computed: {
isInheriting: () => isInheriting,
},
2020-05-24 23:13:21 +05:30
});
};
afterEach(() => {
2021-09-04 01:27:46 +05:30
wrapper.destroy();
2020-05-24 23:13:21 +05:30
});
2021-09-04 01:27:46 +05:30
const findTriggerLabel = () => wrapper.findByTestId('trigger-fields-group').find('label');
2020-07-28 23:09:34 +05:30
const findAllGlFormGroups = () => wrapper.find('#trigger-fields').findAll(GlFormGroup);
2021-09-04 01:27:46 +05:30
const findAllGlFormCheckboxes = () => wrapper.findAllComponents(GlFormCheckbox);
const findAllGlFormInputs = () => wrapper.findAllComponents(GlFormInput);
2020-05-24 23:13:21 +05:30
2021-03-08 18:12:59 +05:30
describe.each([true, false])('template, isInheriting = `%p`', (isInheriting) => {
2020-05-24 23:13:21 +05:30
it('renders a label with text "Trigger"', () => {
createComponent();
2021-09-04 01:27:46 +05:30
const triggerLabel = findTriggerLabel();
2020-05-24 23:13:21 +05:30
expect(triggerLabel.exists()).toBe(true);
expect(triggerLabel.text()).toBe('Trigger');
});
describe('events without field property', () => {
const events = [
{
title: 'push',
name: 'push_event',
description: 'Event on push',
value: true,
},
{
title: 'merge_request',
name: 'merge_requests_event',
description: 'Event on merge_request',
value: false,
},
];
beforeEach(() => {
2020-07-28 23:09:34 +05:30
createComponent(
{
events,
},
isInheriting,
);
2020-05-24 23:13:21 +05:30
});
it('does not render GlFormInput for each event', () => {
expect(findAllGlFormInputs().exists()).toBe(false);
});
it('renders GlFormInput with description for each event', () => {
2021-09-04 01:27:46 +05:30
const groups = findAllGlFormGroups();
2020-05-24 23:13:21 +05:30
expect(groups).toHaveLength(2);
groups.wrappers.forEach((group, index) => {
expect(group.find('small').text()).toBe(events[index].description);
});
});
2020-07-28 23:09:34 +05:30
it(`renders GlFormCheckbox and corresponding hidden input for each event, which ${
isInheriting ? 'is' : 'is not'
} disabled`, () => {
const checkboxes = findAllGlFormGroups();
2020-05-24 23:13:21 +05:30
const expectedResults = [
{ labelText: 'Push', inputName: 'service[push_event]' },
{ labelText: 'Merge Request', inputName: 'service[merge_requests_event]' },
];
expect(checkboxes).toHaveLength(2);
checkboxes.wrappers.forEach((checkbox, index) => {
2020-07-28 23:09:34 +05:30
const checkBox = checkbox.find(GlFormCheckbox);
2020-05-24 23:13:21 +05:30
expect(checkbox.find('label').text()).toBe(expectedResults[index].labelText);
2020-07-28 23:09:34 +05:30
expect(checkbox.find('[type=hidden]').attributes('name')).toBe(
expectedResults[index].inputName,
);
expect(checkbox.find('[type=hidden]').attributes('value')).toBe(
events[index].value.toString(),
);
expect(checkBox.vm.$attrs.disabled).toBe(isInheriting);
expect(checkBox.vm.$attrs.checked).toBe(events[index].value);
2020-05-24 23:13:21 +05:30
});
});
});
2020-07-28 23:09:34 +05:30
describe('events with field property, isInheriting = `%p`', () => {
2020-05-24 23:13:21 +05:30
const events = [
{
field: {
name: 'push_channel',
value: '',
},
},
{
field: {
name: 'merge_request_channel',
value: 'gitlab-development',
},
},
];
beforeEach(() => {
2020-07-28 23:09:34 +05:30
createComponent(
{
events,
},
isInheriting,
);
2020-05-24 23:13:21 +05:30
});
it('renders GlFormCheckbox for each event', () => {
expect(findAllGlFormCheckboxes()).toHaveLength(2);
});
2020-07-28 23:09:34 +05:30
it(`renders GlFormInput for each event, which ${
isInheriting ? 'is' : 'is not'
} readonly`, () => {
2020-05-24 23:13:21 +05:30
const fields = findAllGlFormInputs();
const expectedResults = [
{
name: 'service[push_channel]',
2021-09-04 01:27:46 +05:30
placeholder: '#general, #development',
2020-05-24 23:13:21 +05:30
},
{
name: 'service[merge_request_channel]',
2021-09-04 01:27:46 +05:30
placeholder: '#general, #development',
2020-05-24 23:13:21 +05:30
},
];
expect(fields).toHaveLength(2);
fields.wrappers.forEach((field, index) => {
expect(field.attributes()).toMatchObject(expectedResults[index]);
2020-07-28 23:09:34 +05:30
expect(field.vm.$attrs.readonly).toBe(isInheriting);
2020-05-24 23:13:21 +05:30
expect(field.vm.$attrs.value).toBe(events[index].field.value);
});
});
});
});
});