2020-11-24 15:15:51 +05:30
|
|
|
import { GlFormCheckbox } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
import ActiveCheckbox from '~/integrations/edit/components/active_checkbox.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { createStore } from '~/integrations/edit/store';
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
describe('ActiveCheckbox', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const createComponent = (customStateProps = {}, { isInheriting = false } = {}) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
wrapper = mount(ActiveCheckbox, {
|
|
|
|
store: createStore({
|
|
|
|
customState: { ...customStateProps },
|
2021-06-08 01:23:25 +05:30
|
|
|
override: !isInheriting,
|
|
|
|
defaultState: isInheriting ? {} : undefined,
|
2020-11-24 15:15:51 +05:30
|
|
|
}),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
2021-06-08 01:23:25 +05:30
|
|
|
wrapper.destroy();
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
const findGlFormCheckbox = () => wrapper.findComponent(GlFormCheckbox);
|
2020-11-24 15:15:51 +05:30
|
|
|
const findInputInCheckbox = () => findGlFormCheckbox().find('input');
|
|
|
|
|
|
|
|
describe('template', () => {
|
|
|
|
describe('is inheriting adminSettings', () => {
|
|
|
|
it('renders GlFormCheckbox as disabled', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
createComponent({}, { isInheriting: true });
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect(findGlFormCheckbox().exists()).toBe(true);
|
|
|
|
expect(findInputInCheckbox().attributes('disabled')).toBe('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
describe('when activateDisabled is true', () => {
|
|
|
|
it('renders GlFormCheckbox as disabled', () => {
|
|
|
|
createComponent({ activateDisabled: true });
|
|
|
|
|
|
|
|
expect(findGlFormCheckbox().exists()).toBe(true);
|
|
|
|
expect(findInputInCheckbox().attributes('disabled')).toBe('disabled');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe('initialActivated is `false`', () => {
|
|
|
|
beforeEach(() => {
|
2020-11-24 15:15:51 +05:30
|
|
|
createComponent({
|
|
|
|
initialActivated: false,
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it('renders GlFormCheckbox as unchecked', () => {
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(findGlFormCheckbox().exists()).toBe(true);
|
|
|
|
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
|
|
|
|
expect(findInputInCheckbox().attributes('disabled')).toBeUndefined();
|
|
|
|
});
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
it('emits `toggle-integration-active` event with `false` on mount', () => {
|
|
|
|
expect(wrapper.emitted('toggle-integration-active')[0]).toEqual([false]);
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
describe('initialActivated is true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({
|
|
|
|
initialActivated: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders GlFormCheckbox as checked', () => {
|
|
|
|
expect(findGlFormCheckbox().exists()).toBe(true);
|
|
|
|
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it('emits `toggle-integration-active` event with `true` on mount', () => {
|
|
|
|
expect(wrapper.emitted('toggle-integration-active')[0]).toEqual([true]);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on checkbox `change` event', () => {
|
2022-08-13 15:12:31 +05:30
|
|
|
it('emits `toggle-integration-active` event', async () => {
|
|
|
|
await findInputInCheckbox().setChecked(false);
|
2022-01-26 12:08:38 +05:30
|
|
|
|
|
|
|
expect(wrapper.emitted('toggle-integration-active')[1]).toEqual([false]);
|
|
|
|
});
|
|
|
|
});
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|