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

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

100 lines
3.1 KiB
JavaScript
Raw Normal View History

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
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
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);
});
describe('on checkbox click', () => {
it('switches the form value', async () => {
findInputInCheckbox().trigger('click');
2022-04-04 11:22:00 +05:30
await nextTick();
2020-11-24 15:15:51 +05:30
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
});
});
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', () => {
it('emits `toggle-integration-active` event', () => {
findGlFormCheckbox().vm.$emit('change', false);
expect(wrapper.emitted('toggle-integration-active')[1]).toEqual([false]);
});
});
2020-11-24 15:15:51 +05:30
});
});
});