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

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

204 lines
7.4 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';
2023-01-13 00:05:48 +05:30
import { placeholderForType } from 'jh_else_ce/integrations/constants';
2021-09-04 01:27:46 +05:30
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');
2022-10-11 01:57:18 +05:30
const findAllGlFormGroups = () => wrapper.find('#trigger-fields').findAllComponents(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
2023-01-13 00:05:48 +05:30
describe('placeholder text on the event fields and default values', () => {
const dummyFieldPlaceholder = '#foo';
const integrationTypes = {
INTEGRATION_TYPE_SLACK: 'slack',
INTEGRATION_TYPE_SLACK_APPLICATION: 'gitlab_slack_application',
INTEGRATION_TYPE_MATTERMOST: 'mattermost',
INTEGRATION_TYPE_NON_EXISTING: 'non_existing',
};
it.each`
integrationType | fieldPlaceholder | expectedPlaceholder
${integrationTypes.INTEGRATION_TYPE_SLACK} | ${undefined} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_SLACK]}
${integrationTypes.INTEGRATION_TYPE_SLACK} | ${''} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_SLACK]}
${integrationTypes.INTEGRATION_TYPE_SLACK} | ${dummyFieldPlaceholder} | ${dummyFieldPlaceholder}
${integrationTypes.INTEGRATION_TYPE_SLACK_APPLICATION} | ${undefined} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_SLACK_APPLICATION]}
${integrationTypes.INTEGRATION_TYPE_SLACK_APPLICATION} | ${''} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_SLACK_APPLICATION]}
${integrationTypes.INTEGRATION_TYPE_SLACK_APPLICATION} | ${dummyFieldPlaceholder} | ${dummyFieldPlaceholder}
${integrationTypes.INTEGRATION_TYPE_MATTERMOST} | ${undefined} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_MATTERMOST]}
${integrationTypes.INTEGRATION_TYPE_MATTERMOST} | ${''} | ${placeholderForType[integrationTypes.INTEGRATION_TYPE_MATTERMOST]}
${integrationTypes.INTEGRATION_TYPE_MATTERMOST} | ${dummyFieldPlaceholder} | ${dummyFieldPlaceholder}
${integrationTypes.INTEGRATION_TYPE_NON_EXISTING} | ${undefined} | ${undefined}
${integrationTypes.INTEGRATION_TYPE_NON_EXISTING} | ${''} | ${undefined}
${integrationTypes.INTEGRATION_TYPE_NON_EXISTING} | ${dummyFieldPlaceholder} | ${dummyFieldPlaceholder}
`(
'passed down correct placeholder for "$integrationType" type and "$fieldPlaceholder" placeholder on the field',
({ integrationType, fieldPlaceholder, expectedPlaceholder }) => {
createComponent({
type: integrationType,
events: [
{
field: {
name: 'foo',
value: '',
placeholder: fieldPlaceholder,
},
},
],
});
const field = wrapper.findComponent(GlFormInput);
expect(field.attributes('placeholder')).toBe(expectedPlaceholder);
},
);
});
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 = [
{
2022-05-07 20:08:51 +05:30
title: 'Push',
2020-05-24 23:13:21 +05:30
name: 'push_event',
description: 'Event on push',
value: true,
},
{
2022-05-07 20:08:51 +05:30
title: 'Merge request',
2020-05-24 23:13:21 +05:30
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]' },
2022-05-07 20:08:51 +05:30
{ labelText: 'Merge request', inputName: 'service[merge_requests_event]' },
2020-05-24 23:13:21 +05:30
];
expect(checkboxes).toHaveLength(2);
checkboxes.wrappers.forEach((checkbox, index) => {
2022-10-11 01:57:18 +05:30
const checkBox = checkbox.findComponent(GlFormCheckbox);
2020-07-28 23:09:34 +05:30
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);
});
});
});
});
});