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

73 lines
2.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
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');
});
});
describe('initialActivated is false', () => {
it('renders GlFormCheckbox as unchecked', () => {
createComponent({
initialActivated: false,
});
expect(findGlFormCheckbox().exists()).toBe(true);
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
expect(findInputInCheckbox().attributes('disabled')).toBeUndefined();
});
});
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');
await wrapper.vm.$nextTick();
expect(findGlFormCheckbox().vm.$attrs.checked).toBe(false);
});
});
});
});
});