From 1c99db5a74ea73abf718260147888953385092d0 Mon Sep 17 00:00:00 2001 From: Heidrun Wiemold Date: Wed, 18 Oct 2023 16:48:54 +0200 Subject: [PATCH 1/2] refactor(refs T29004): re-add label tests - the label tests (that were disabled after refactoring the label props to be a single object) are fixed and enabled again - some more tests that were disabled in DpInput.spec.js for unknown reasons are enabled again as well --- tests/form/DpCheckbox.spec.js | 2 ++ tests/form/DpInput.spec.js | 51 ++++++++++++++++++----------------- tests/form/DpSelect.spec.js | 3 ++- tests/form/shared/Label.js | 10 ++++--- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/tests/form/DpCheckbox.spec.js b/tests/form/DpCheckbox.spec.js index 334c9886d..39be01393 100644 --- a/tests/form/DpCheckbox.spec.js +++ b/tests/form/DpCheckbox.spec.js @@ -10,6 +10,8 @@ describe('DpCheckbox', () => { } }) + runLabelTests(wrapper) + const checkbox = wrapper.find('input[type="checkbox"]') runBooleanAttrTests(wrapper, checkbox, 'required') runBooleanAttrTests(wrapper, checkbox, 'disabled') diff --git a/tests/form/DpInput.spec.js b/tests/form/DpInput.spec.js index 5c21888cf..cdad57c48 100644 --- a/tests/form/DpInput.spec.js +++ b/tests/form/DpInput.spec.js @@ -1,23 +1,24 @@ import { runBooleanAttrTests, runStringAttrTests } from './shared/Attributes' +import { runLabelTests } from './shared/Label' import DpInput from '~/components/DpInput' import { shallowMount } from '@vue/test-utils' describe('DpInput', () => { - // const wrapper = shallowMount(DpInput, { - // propsData: { - // id: 'inputId' - // } - // }) - // RunLabelTests(wrapper) + const wrapper = shallowMount(DpInput, { + propsData: { + id: 'inputId' + } + }) + runLabelTests(wrapper) - // const input = wrapper.find('input[type="text"]') - // runBooleanAttrTests(wrapper, input, 'required') - // runBooleanAttrTests(wrapper, input, 'disabled') - // runBooleanAttrTests(wrapper, input, 'readonly') - // runStringAttrTests(wrapper, input, 'placeholder', 'This is a placeholder.', 'data-dp-validate-error') - // runStringAttrTests(wrapper, input, 'dataDpValidateError', 'Bitte füllen Sie alle Pflichtfelder(*) korrekt aus.', 'data-dp-validate-error') - // runStringAttrTests(wrapper, input, 'dataDpValidateIf', '#r_getEvaluation', 'data-dp-validate-if') - // runStringAttrTests(wrapper, input, 'dataDpValidateShouldEqual', 'This is a placeholder.', 'data-dp-validate-should-equal') + const input = wrapper.find('input[type="text"]') + runBooleanAttrTests(wrapper, input, 'required') + runBooleanAttrTests(wrapper, input, 'disabled') + runBooleanAttrTests(wrapper, input, 'readonly') + runStringAttrTests(wrapper, input, 'placeholder', 'This is a placeholder.', 'placeholder') + runStringAttrTests(wrapper, input, 'dataDpValidateError', 'Bitte füllen Sie alle Pflichtfelder(*) korrekt aus.', 'data-dp-validate-error') + runStringAttrTests(wrapper, input, 'dataDpValidateIf', '#r_getEvaluation', 'data-dp-validate-if') + runStringAttrTests(wrapper, input, 'dataDpValidateShouldEqual', 'This is a placeholder.', 'data-dp-validate-should-equal') it('emits an event on input with the new value as argument', async () => { const newValue = 'some text' @@ -32,15 +33,15 @@ describe('DpInput', () => { expect(componentWrapper.emitted().input[0][0]).toEqual(newValue) }) - // it('emits an event on keydown enter', () => { - // const componentWrapper = shallowMount(DpInput, { - // propsData: { - // id: 'inputId' - // } - // }) - // - // const input = componentWrapper.find('input') - // input.trigger('keydown.enter') - // expect(componentWrapper.emitted().enter).toBeDefined() - // }) + it('emits an event on keydown enter', () => { + const componentWrapper = shallowMount(DpInput, { + propsData: { + id: 'inputId' + } + }) + + const input = componentWrapper.find('input') + input.trigger('keydown.enter') + expect(componentWrapper.emitted().enter).toBeDefined() + }) }) diff --git a/tests/form/DpSelect.spec.js b/tests/form/DpSelect.spec.js index b3ada441b..7b2938558 100644 --- a/tests/form/DpSelect.spec.js +++ b/tests/form/DpSelect.spec.js @@ -1,6 +1,7 @@ import DpSelect from '~/components/DpSelect' import { de } from '~/components/shared/translations' import { runBooleanAttrTests } from './shared/Attributes' +import { runLabelTests } from './shared/Label' import shallowMountWithGlobalMocks from '../../jest/shallowMountWithGlobalMocks' @@ -18,7 +19,7 @@ describe('DpSelect', () => { const wrapper = shallowMountWithGlobalMocks(DpSelect, { propsData: { options } }) - // RunLabelTests(wrapper) + runLabelTests(wrapper) const select = wrapper.find('select') runBooleanAttrTests(wrapper, select, 'disabled') diff --git a/tests/form/shared/Label.js b/tests/form/shared/Label.js index bc6cb0ba7..5cf6c5148 100644 --- a/tests/form/shared/Label.js +++ b/tests/form/shared/Label.js @@ -1,14 +1,18 @@ const runLabelTests = (wrapper) => describe('ComponentWithLabel', () => { it('displays a label if label is defined', async () => { - const label = 'someLabel' + const label = { + text: 'someLabel' + } await wrapper.setProps({ label: label }) const labelStub = wrapper.find('dp-label-stub') expect(labelStub.exists()).toBe(true) - expect(labelStub.attributes('text')).toBe(label) + expect(labelStub.attributes('text')).toBe(label.text) }) it('does not display a label if label is not defined', async () => { - const label = '' + const label = { + text: '' + } await wrapper.setProps({ label: label }) const labelStub = wrapper.find('dp-label-stub') From a7edf57810d4d8cbdb47cc88781d95051c3bc9c2 Mon Sep 17 00:00:00 2001 From: Heidrun Wiemold Date: Wed, 18 Oct 2023 17:02:34 +0200 Subject: [PATCH 2/2] docs(refs T29004): add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a778b81db..769dda4b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Since v0.0.10, this Changelog is formatted according to the [Common Changelog][c ## UNRELEASED +### Added +- ([#591](https://github.com/demos-europe/demosplan-ui/pull/591)) Add label tests for form components ([@hwiem](https://github.com/hwiem)) + ## v0.2.1 - 2023-10-18 ### Changed