From 6aa21d720b16b04cd18a1241d02792a17d47650d Mon Sep 17 00:00:00 2001 From: Fernando <farias@gitlab.com> Date: Wed, 9 Sep 2020 06:35:02 -0500 Subject: [PATCH] Code reviewe changes * Add additional unit tests for props * Add additional unit tests for emitted events --- .../sast/components/analyzer_configuration.vue | 4 ++-- .../components/analyzer_configuration_spec.js | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ee/app/assets/javascripts/security_configuration/sast/components/analyzer_configuration.vue b/ee/app/assets/javascripts/security_configuration/sast/components/analyzer_configuration.vue index b814b523caa..90559aa7cc9 100644 --- a/ee/app/assets/javascripts/security_configuration/sast/components/analyzer_configuration.vue +++ b/ee/app/assets/javascripts/security_configuration/sast/components/analyzer_configuration.vue @@ -27,8 +27,8 @@ export default { }, }, methods: { - onToggle(value) { - const entity = { ...this.entity, enabled: value }; + onToggle(enabled) { + const entity = { ...this.entity, enabled }; this.$emit('input', entity); }, onConfigurationUpdate(configuration) { diff --git a/ee/spec/frontend/security_configuration/sast/components/analyzer_configuration_spec.js b/ee/spec/frontend/security_configuration/sast/components/analyzer_configuration_spec.js index b668ab19a57..e1ed40a3315 100644 --- a/ee/spec/frontend/security_configuration/sast/components/analyzer_configuration_spec.js +++ b/ee/spec/frontend/security_configuration/sast/components/analyzer_configuration_spec.js @@ -21,6 +21,7 @@ describe('AnalyzerConfiguration component', () => { }; const findInputElement = () => wrapper.find('input[type="checkbox"]'); + const findDynamicFields = () => wrapper.find(DynamicFields); afterEach(() => { wrapper.destroy(); @@ -77,7 +78,7 @@ describe('AnalyzerConfiguration component', () => { }); it('does not render the nested dynamic forms', () => { - expect(wrapper.find(DynamicFields).exists()).toBe(false); + expect(findDynamicFields().exists()).toBe(false); }); }); @@ -104,11 +105,22 @@ describe('AnalyzerConfiguration component', () => { }); it('it renders the nested dynamic forms', () => { - expect(wrapper.find(DynamicFields).exists()).toBe(true); + expect(findDynamicFields().exists()).toBe(true); + }); + + it('it emits an input event when dynamic form fields emits an input event', () => { + findDynamicFields().vm.$emit('input', analyzerEntity.configuration); + + const [[payload]] = wrapper.emitted('input'); + expect(payload).toEqual(analyzerEntity); }); it('passes the disabled prop to dynamic fields component', () => { - expect(wrapper.find(DynamicFields).vm.$attrs.disabled).toBe(!analyzerEntity.enabled); + expect(findDynamicFields().vm.$attrs.disabled).toBe(!analyzerEntity.enabled); + }); + + it('passes the entities prop to the dynamic fields component', () => { + expect(findDynamicFields().props('entities')).toBe(analyzerEntity.configuration); }); }); }); -- 2.30.9