Commit 0b9ff82f authored by Fernando's avatar Fernando

Apply maintainer patch

* Patch reworks the disabled prop check by checking
attribute on fieldset element
parent 38e8e2b7
import { shallowMount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import DynamicFields from 'ee/security_configuration/sast/components/dynamic_fields.vue'; import DynamicFields from 'ee/security_configuration/sast/components/dynamic_fields.vue';
import { makeEntities } from './helpers'; import { makeEntities } from './helpers';
describe('DynamicFields component', () => { describe('DynamicFields component', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = (props = {}, mountFn = shallowMount) => {
wrapper = shallowMount(DynamicFields, { wrapper = mountFn(DynamicFields, {
propsData: { propsData: {
...props, ...props,
}, },
...@@ -34,6 +34,21 @@ describe('DynamicFields component', () => { ...@@ -34,6 +34,21 @@ describe('DynamicFields component', () => {
}); });
}); });
describe.each([true, false])('given the disabled prop is %p', disabled => {
beforeEach(() => {
createComponent({ entities: [], disabled }, mount);
});
it('uses a fieldset as the root element', () => {
expect(wrapper.element.tagName).toBe('FIELDSET');
});
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset#attr-disabled
it(`${disabled ? 'sets' : 'does not set'} the disabled attribute on the root element`, () => {
expect('disabled' in wrapper.attributes()).toBe(disabled);
});
});
describe('given valid entities', () => { describe('given valid entities', () => {
let entities; let entities;
let fields; let fields;
...@@ -44,17 +59,6 @@ describe('DynamicFields component', () => { ...@@ -44,17 +59,6 @@ describe('DynamicFields component', () => {
fields = findFields(); fields = findFields();
}); });
describe.each([true, false])('when the disabled prop is %s', disabled => {
beforeEach(() => {
entities = makeEntities(3);
createComponent({ entities, disabled });
});
it(`it is passed a disabled prop set to ${disabled}`, () => {
expect(wrapper.props('disabled')).toBe(disabled);
});
});
it('renders each field with the correct component', () => { it('renders each field with the correct component', () => {
entities.forEach((entity, i) => { entities.forEach((entity, i) => {
const field = fields.at(i); const field = fields.at(i);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment