From b1fee3f4c0e709d3ec71596b92180f3e398d72af Mon Sep 17 00:00:00 2001 From: tehkai Date: Tue, 27 Aug 2024 10:55:51 -0400 Subject: [PATCH 01/10] feat(vfg): convert field-select + more tests [khcp-11336] --- .../src/components/fields/FieldSelect.vue | 246 ++++++++------- .../fields/__tests__/FieldCheckbox.cy.ts | 15 + .../fields/__tests__/FieldInput.cy.ts | 15 + .../fields/__tests__/FieldRadio.cy.ts | 20 +- .../fields/__tests__/FieldSelect.cy.ts | 294 ++++++++++++++++++ .../fields/__tests__/FieldTextArea.cy.ts | 15 + packages/core/forms/src/types/form-fields.ts | 1 + 7 files changed, 485 insertions(+), 121 deletions(-) create mode 100644 packages/core/forms/src/components/fields/__tests__/FieldSelect.cy.ts diff --git a/packages/core/forms/src/components/fields/FieldSelect.vue b/packages/core/forms/src/components/fields/FieldSelect.vue index 657d692e9b..bf73bfe7a7 100644 --- a/packages/core/forms/src/components/fields/FieldSelect.vue +++ b/packages/core/forms/src/components/fields/FieldSelect.vue @@ -1,138 +1,146 @@ - diff --git a/packages/core/forms/src/components/fields/__tests__/FieldInput.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldInput.cy.ts index 5fc52bab72..c2fc614434 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldInput.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldInput.cy.ts @@ -39,9 +39,9 @@ describe(' - FieldInput', () => { // check required state if (schema.fields[0].required) { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('exist') } else { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('not.exist') } // check help text diff --git a/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts index 2c390a9e3b..56e6460b14 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts @@ -12,6 +12,7 @@ describe(' - FieldSwitch', () => { id: fieldKey, inputType: 'text', label: fieldLabel, + required: true, }], } @@ -34,6 +35,19 @@ describe(' - FieldSwitch', () => { // check VFG label is set correctly cy.get(`.form-group-label[for="${fieldKey}"]`).should('be.visible') cy.get(`.form-group-label[for="${fieldKey}"]`).should('contain.text', fieldLabel) + + // check required state + if (schema.fields[0].required) { + cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + } else { + cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + } + + // check help text + if (schema.fields[0].help) { + cy.get(`label[for="${fieldKey}"] .info-icon`).should('be.visible') + cy.get(`label[for="${fieldKey}"]`).should('contain.text', schema.fields[0].help) + } }) it('renders default state correctly - with model', () => { From 9bd6e65d3e410bb6de0e8dfe43070ff2f6c83423 Mon Sep 17 00:00:00 2001 From: tehkai Date: Tue, 27 Aug 2024 17:30:30 -0400 Subject: [PATCH 08/10] fix(*): test selectors --- .../forms/src/components/fields/__tests__/FieldCheckbox.cy.ts | 4 ++-- .../forms/src/components/fields/__tests__/FieldRadio.cy.ts | 4 ++-- .../forms/src/components/fields/__tests__/FieldSwitch.cy.ts | 4 ++-- .../forms/src/components/fields/__tests__/FieldTextArea.cy.ts | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/forms/src/components/fields/__tests__/FieldCheckbox.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldCheckbox.cy.ts index 77b414ae28..22dabea83b 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldCheckbox.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldCheckbox.cy.ts @@ -38,9 +38,9 @@ describe(' - FieldCheckbox', () => { // check required state if (schema.fields[0].required) { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('exist') } else { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('not.exist') } // check help text diff --git a/packages/core/forms/src/components/fields/__tests__/FieldRadio.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldRadio.cy.ts index d78983544f..fc94a34cbe 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldRadio.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldRadio.cy.ts @@ -47,9 +47,9 @@ describe(' - FieldRadio', () => { // check required state if (schema.fields[0].required) { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('exist') } else { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('not.exist') } // check help text diff --git a/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts index 56e6460b14..8ca4a997ed 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldSwitch.cy.ts @@ -38,9 +38,9 @@ describe(' - FieldSwitch', () => { // check required state if (schema.fields[0].required) { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('exist') } else { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('not.exist') } // check help text diff --git a/packages/core/forms/src/components/fields/__tests__/FieldTextArea.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldTextArea.cy.ts index cdcdf3d42f..9ca6a99f22 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldTextArea.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldTextArea.cy.ts @@ -38,9 +38,9 @@ describe(' - FieldTextArea', () => { // check required state if (schema.fields[0].required) { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('exist') } else { - cy.get(`.form-group-label.required[for="${fieldKey}"]`).should('not.exist') + cy.get('.required').find(`.form-group-label[for="${fieldKey}"]`).should('not.exist') } // check help text From b465ed0e405983ab1d0e0d9ce1a36e5e678ed500 Mon Sep 17 00:00:00 2001 From: tehkai Date: Thu, 19 Sep 2024 12:42:32 -0400 Subject: [PATCH 09/10] fix(*): data-testid for items --- packages/core/forms/src/components/fields/FieldSelect.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/forms/src/components/fields/FieldSelect.vue b/packages/core/forms/src/components/fields/FieldSelect.vue index 2ddf9b6218..1f372f642e 100644 --- a/packages/core/forms/src/components/fields/FieldSelect.vue +++ b/packages/core/forms/src/components/fields/FieldSelect.vue @@ -5,6 +5,7 @@ :class="schema.fieldClasses" :disabled="disabled || undefined" :items="items" + :kpop-attributes="{ 'data-testid': `${getFieldID(schema)}-items` }" :label-attributes="{ info: schema.help }" :name="schema.inputName" :placeholder="!selectOptions.hideNoneSelectedText ? selectOptions.noneSelectedText || 'Nothing Selected' : undefined" From 736b0587907630a7786f5a641129a5c1a46fd249 Mon Sep 17 00:00:00 2001 From: tehkai Date: Mon, 23 Sep 2024 09:15:38 -0400 Subject: [PATCH 10/10] fix(*): clearable if not required --- packages/core/forms/src/components/fields/FieldSelect.vue | 1 + .../forms/src/components/fields/__tests__/FieldSelect.cy.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/forms/src/components/fields/FieldSelect.vue b/packages/core/forms/src/components/fields/FieldSelect.vue index 1f372f642e..70c9d0f2b2 100644 --- a/packages/core/forms/src/components/fields/FieldSelect.vue +++ b/packages/core/forms/src/components/fields/FieldSelect.vue @@ -3,6 +3,7 @@ :id="getFieldID(schema)" v-model="inputValue" :class="schema.fieldClasses" + :clearable="!schema.required" :disabled="disabled || undefined" :items="items" :kpop-attributes="{ 'data-testid': `${getFieldID(schema)}-items` }" diff --git a/packages/core/forms/src/components/fields/__tests__/FieldSelect.cy.ts b/packages/core/forms/src/components/fields/__tests__/FieldSelect.cy.ts index 1c0c16111c..6284c3e8cd 100644 --- a/packages/core/forms/src/components/fields/__tests__/FieldSelect.cy.ts +++ b/packages/core/forms/src/components/fields/__tests__/FieldSelect.cy.ts @@ -1,7 +1,7 @@ import type { FormSchema } from '../../../types' import FieldTester from '../../../../sandbox/FieldTester.vue' -describe(' - FieldSwitch', () => { +describe(' - FieldSelect', () => { const fieldKeys = ['https_redirect_status_code', 'protocols'] const fieldLabels = ['HTTPS Redirect Status Code', 'Protocols'] const fieldValues = [307, 'http, https']