2022-06-21 17:19:12 +05:30
|
|
|
import { GlFormGroup } from '@gitlab/ui';
|
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2021-01-29 00:20:46 +05:30
|
|
|
import IntegrationView from '~/profile/preferences/components/integration_view.vue';
|
|
|
|
import IntegrationHelpText from '~/vue_shared/components/integrations_help_text.vue';
|
|
|
|
import { integrationViews, userFields } from '../mock_data';
|
|
|
|
|
|
|
|
const viewProps = convertObjectPropsToCamelCase(integrationViews[0]);
|
|
|
|
|
|
|
|
describe('IntegrationView component', () => {
|
|
|
|
let wrapper;
|
|
|
|
const defaultProps = {
|
|
|
|
config: {
|
|
|
|
title: 'Foo',
|
|
|
|
label: 'Enable foo',
|
|
|
|
formName: 'foo_enabled',
|
|
|
|
},
|
|
|
|
...viewProps,
|
|
|
|
};
|
|
|
|
|
|
|
|
function createComponent(options = {}) {
|
|
|
|
const { props = {}, provide = {} } = options;
|
2022-06-21 17:19:12 +05:30
|
|
|
return mountExtended(IntegrationView, {
|
2021-01-29 00:20:46 +05:30
|
|
|
provide: {
|
|
|
|
userFields,
|
|
|
|
...provide,
|
|
|
|
},
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
const findCheckbox = () => wrapper.findByLabelText(new RegExp(defaultProps.config.label));
|
|
|
|
const findFormGroup = () => wrapper.findComponent(GlFormGroup);
|
|
|
|
const findHiddenField = () =>
|
|
|
|
wrapper.findByTestId('profile-preferences-integration-hidden-field');
|
2021-01-29 00:20:46 +05:30
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
it('should render the form group legend correctly', () => {
|
2021-01-29 00:20:46 +05:30
|
|
|
wrapper = createComponent();
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
expect(wrapper.findByText(defaultProps.config.title).exists()).toBe(true);
|
2021-01-29 00:20:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the form correctly', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(findFormGroup().exists()).toBe(true);
|
|
|
|
expect(findHiddenField().exists()).toBe(true);
|
|
|
|
expect(findCheckbox().exists()).toBe(true);
|
|
|
|
expect(findCheckbox().attributes('id')).toBe('user_foo_enabled');
|
|
|
|
expect(findCheckbox().attributes('name')).toBe('user[foo_enabled]');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the checkbox value to be set to 1', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(findCheckbox().attributes('value')).toBe('1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should have the hidden value to be set to 0', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(findHiddenField().attributes('value')).toBe('0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the checkbox value to be true', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(findCheckbox().element.checked).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the checkbox value to be false when false is provided', () => {
|
|
|
|
wrapper = createComponent({
|
|
|
|
provide: {
|
|
|
|
userFields: {
|
|
|
|
foo_enabled: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(findCheckbox().element.checked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set the checkbox value to be false when not provided', () => {
|
|
|
|
wrapper = createComponent({ provide: { userFields: {} } });
|
|
|
|
|
|
|
|
expect(findCheckbox().element.checked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the help text', () => {
|
|
|
|
wrapper = createComponent();
|
|
|
|
|
|
|
|
expect(wrapper.find(IntegrationHelpText).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|