2020-07-10 03:08:53 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
2020-07-17 03:09:14 +00:00
|
|
|
|
2020-07-10 03:08:53 +00:00
|
|
|
import { GlFormCheckbox, GlFormInput } from '@gitlab/ui';
|
|
|
|
|
2020-07-17 03:09:14 +00:00
|
|
|
import JiraIssuesFields from '~/integrations/edit/components/jira_issues_fields.vue';
|
|
|
|
|
2020-07-10 03:08:53 +00:00
|
|
|
describe('JiraIssuesFields', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
2020-07-14 18:09:55 +00:00
|
|
|
showJiraIssuesIntegration: true,
|
2020-07-10 03:08:53 +00:00
|
|
|
editProjectPath: '/edit',
|
|
|
|
};
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
const createComponent = (props) => {
|
2020-07-10 03:08:53 +00:00
|
|
|
wrapper = mount(JiraIssuesFields, {
|
|
|
|
propsData: { ...defaultProps, ...props },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapper) {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const findEnableCheckbox = () => wrapper.find(GlFormCheckbox);
|
|
|
|
const findProjectKey = () => wrapper.find(GlFormInput);
|
2020-07-14 18:09:55 +00:00
|
|
|
const expectedBannerText = 'This is a Premium feature';
|
2020-07-10 03:08:53 +00:00
|
|
|
|
|
|
|
describe('template', () => {
|
2020-07-14 18:09:55 +00:00
|
|
|
describe('upgrade banner for non-Premium user', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ initialProjectKey: '', showJiraIssuesIntegration: false });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows upgrade banner', () => {
|
|
|
|
expect(wrapper.text()).toContain(expectedBannerText);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not show checkbox and input field', () => {
|
|
|
|
expect(findEnableCheckbox().exists()).toBe(false);
|
|
|
|
expect(findProjectKey().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-10 03:08:53 +00:00
|
|
|
describe('Enable Jira issues checkbox', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ initialProjectKey: '' });
|
|
|
|
});
|
|
|
|
|
2020-07-14 18:09:55 +00:00
|
|
|
it('does not show upgrade banner', () => {
|
|
|
|
expect(wrapper.text()).not.toContain(expectedBannerText);
|
|
|
|
});
|
|
|
|
|
2020-07-10 03:08:53 +00:00
|
|
|
// As per https://vuejs.org/v2/guide/forms.html#Checkbox-1,
|
|
|
|
// browsers don't include unchecked boxes in form submissions.
|
|
|
|
it('includes issues_enabled as false even if unchecked', () => {
|
2020-08-28 12:10:37 +00:00
|
|
|
expect(wrapper.find('input[name="service[issues_enabled]"]').exists()).toBe(true);
|
2020-07-10 03:08:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('disables project_key input', () => {
|
|
|
|
expect(findProjectKey().attributes('disabled')).toBe('disabled');
|
|
|
|
});
|
|
|
|
|
2020-07-14 18:09:55 +00:00
|
|
|
it('does not require project_key', () => {
|
|
|
|
expect(findProjectKey().attributes('required')).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2020-07-10 03:08:53 +00:00
|
|
|
describe('on enable issues', () => {
|
|
|
|
it('enables project_key input', () => {
|
|
|
|
findEnableCheckbox().vm.$emit('input', true);
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(findProjectKey().attributes('disabled')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
2020-07-14 18:09:55 +00:00
|
|
|
|
|
|
|
it('requires project_key input', () => {
|
|
|
|
findEnableCheckbox().vm.$emit('input', true);
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(findProjectKey().attributes('required')).toBe('required');
|
|
|
|
});
|
|
|
|
});
|
2020-07-10 03:08:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('contains link to editProjectPath', () => {
|
|
|
|
createComponent();
|
|
|
|
|
2020-08-28 12:10:37 +00:00
|
|
|
expect(wrapper.find(`a[href="${defaultProps.editProjectPath}"]`).exists()).toBe(true);
|
2020-07-10 03:08:53 +00:00
|
|
|
});
|
2020-09-02 12:10:35 +00:00
|
|
|
|
|
|
|
describe('GitLab issues warning', () => {
|
|
|
|
const expectedText = 'Consider disabling GitLab issues';
|
|
|
|
|
|
|
|
it('contains warning when GitLab issues is enabled', () => {
|
|
|
|
createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(expectedText);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not contain warning when GitLab issues is disabled', () => {
|
|
|
|
createComponent({ gitlabIssuesEnabled: false });
|
|
|
|
|
|
|
|
expect(wrapper.text()).not.toContain(expectedText);
|
|
|
|
});
|
|
|
|
});
|
2020-07-10 03:08:53 +00:00
|
|
|
});
|
|
|
|
});
|