-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vfg): convert field-text-area [khcp-11338] (#1570)
Convert FieldTextArea to use kongponents for [KHCP-11338](https://konghq.atlassian.net/browse/KHCP-11338).
- Loading branch information
1 parent
8959349
commit 5271f1b
Showing
4 changed files
with
208 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
packages/core/forms/src/components/fields/__tests__/FieldTextArea.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import type { FormSchema } from '../../../types' | ||
import FieldTester from '../../../../sandbox/FieldTester.vue' | ||
|
||
describe('<FieldTester /> - FieldTextArea', () => { | ||
const fieldKey = 'personality' | ||
const fieldLabel = 'Personality' | ||
const fieldValue = 'The cutest and smartest cat in the world.' | ||
const schema: FormSchema = { | ||
fields: [{ | ||
type: 'text-area', | ||
model: fieldKey, | ||
id: fieldKey, | ||
label: fieldLabel, | ||
}], | ||
} | ||
|
||
it('renders default state correctly - without model', () => { | ||
cy.mount(FieldTester, { | ||
props: { | ||
schema, | ||
}, | ||
}) | ||
|
||
cy.get('.field-tester-container').should('exist') | ||
|
||
// check VFG input value | ||
cy.get(`#${fieldKey}`).should('be.visible') | ||
cy.get(`#${fieldKey}`).should('have.value', '') | ||
|
||
// initial model is empty after load | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('not.exist') | ||
|
||
// 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) | ||
}) | ||
|
||
it('renders default state correctly - with model', () => { | ||
cy.mount(FieldTester, { | ||
props: { | ||
schema, | ||
model: { | ||
[fieldKey]: fieldValue, | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('.field-tester-container').should('exist') | ||
|
||
// check VFG input value | ||
cy.get(`#${fieldKey}`).should('be.visible') | ||
cy.get(`#${fieldKey}`).should('have.value', fieldValue) | ||
|
||
// check field test form model matches | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('be.visible') | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('contain.text', fieldValue) | ||
}) | ||
|
||
it('handles input changes', () => { | ||
const editText = ' But also a little devil.' | ||
cy.mount(FieldTester, { | ||
props: { | ||
schema, | ||
model: { | ||
[fieldKey]: fieldValue, | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('.field-tester-container').should('exist') | ||
|
||
// edit the input value | ||
cy.get(`#${fieldKey}`).should('be.visible') | ||
cy.get(`#${fieldKey}`).type(editText) | ||
|
||
// check VFG input value | ||
cy.get(`#${fieldKey}`).should('have.value', fieldValue + editText) | ||
// check field test form model | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('contain.text', fieldValue + editText) | ||
}) | ||
|
||
it('handles programmatic input changes', () => { | ||
const updatedFieldValue = 'The cutest and smartest cat in the world. But also a little devil.' | ||
|
||
cy.mount(FieldTester, { | ||
props: { | ||
schema, | ||
model: { | ||
[fieldKey]: fieldValue, | ||
}, | ||
modifiedModel: { | ||
[fieldKey]: updatedFieldValue, | ||
}, | ||
}, | ||
}) | ||
|
||
cy.get('.field-tester-container').should('exist') | ||
|
||
// initial value loaded | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('be.visible') | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('contain.text', fieldValue) | ||
|
||
// programmatic update | ||
cy.getTestId('tester-update-button').should('be.visible') | ||
cy.getTestId('tester-update-button').click() | ||
|
||
// check VFG input value | ||
cy.get(`#${fieldKey}`).should('have.value', updatedFieldValue) | ||
// check field test form model also matches | ||
cy.getTestId(`field-tester-form-model-${fieldKey}-value`).should('contain.text', updatedFieldValue) | ||
}) | ||
}) |