-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
display normalized name in the input field (#26)
* update code style to remove warnings and errors * display normalized name in the input field --------- Co-authored-by: Patrick Wang <[email protected]>
- Loading branch information
1 parent
944c688
commit dde646a
Showing
4 changed files
with
100 additions
and
76 deletions.
There are no files selected for viewing
55 changes: 31 additions & 24 deletions
55
btr-web/btr-common-components/components/bcros/inputs/FullNameField.vue
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 |
---|---|---|
@@ -1,25 +1,32 @@ | ||
<template> | ||
<UFormGroup :label="label" name="fullName"> | ||
<UInput | ||
:id="id" | ||
type="text" | ||
v-bind="$attrs" | ||
:value="modelValue" | ||
color="gray" | ||
class="border-b-[2px] bg-gray-100" | ||
variant="none" | ||
@input="$emit('update:modelValue', $event.target.value)" | ||
/> | ||
</UFormGroup> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
defineEmits<{(e: 'update:modelValue', value: string): void}>() | ||
defineProps({ | ||
label: { type: [String], default: '' }, | ||
id: { type: String, required: true }, | ||
modelValue: { type: String, default: '' } | ||
}) | ||
</script> | ||
|
||
<UFormGroup :label="label" name="fullName"> | ||
<UInput | ||
:id="id" | ||
type="text" | ||
v-bind="$attrs" | ||
:value="modelValue" | ||
color="gray" | ||
class="border-b-[2px] bg-gray-100" | ||
variant="none" | ||
@input="$emit('update:modelValue', $event.target.value)" | ||
@blur="normalizeInput" | ||
/> | ||
</UFormGroup> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { normalizeName } from '~/utils/validation/form_inputs' | ||
const emit = defineEmits<{(e: 'update:modelValue', value: string): void}>() | ||
const props = defineProps({ | ||
label: { type: [String], default: '' }, | ||
id: { type: String, required: true }, | ||
modelValue: { type: String, default: '' } | ||
}) | ||
const normalizeInput = () => { | ||
const normalizedValue = normalizeName(props.modelValue) | ||
emit('update:modelValue', normalizedValue) | ||
} | ||
</script> |
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 |
---|---|---|
|
@@ -33,75 +33,88 @@ describe('forms -> validate that form component work inside form', () => { | |
it('test the validation rule for the maximum name length', () => { | ||
cy.on('uncaught:exception', (err) => { | ||
expect(err.message).to.include('The legal name must not exceed 150 characters') | ||
return false; | ||
return false | ||
}) | ||
|
||
const email = '[email protected]'; | ||
const invalidLongName = 'a'.repeat(151); | ||
const validLongName = ' ' + 'a'.repeat(150) + ' '; | ||
cy.get('#testEmail').type(email); | ||
const email = '[email protected]' | ||
const invalidLongName = 'a'.repeat(151) | ||
const validLongName = ' ' + 'a'.repeat(150) + ' ' | ||
cy.get('#testEmail').type(email) | ||
|
||
cy.get('#testFullName').type(invalidLongName); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name must not exceed 150 characters').should('exist'); | ||
cy.get('#testFullName').type(invalidLongName) | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name must not exceed 150 characters').should('exist') | ||
|
||
cy.get('#testFullName').clear().type(validLongName).blur(); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name must not exceed 150 characters').should('not.exist'); | ||
}); | ||
cy.get('#testFullName').clear().type(validLongName).blur() | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name must not exceed 150 characters').should('not.exist') | ||
}) | ||
|
||
|
||
it('test the validation rule for the minimum name length', () => { | ||
cy.on('uncaught:exception', (err) => { | ||
expect(err.message).to.include('The legal name should contain at least one character') | ||
return false; | ||
return false | ||
}) | ||
|
||
const email = '[email protected]'; | ||
const singleCharacter = 'a'; | ||
cy.get('#testEmail').type(email); | ||
const email = '[email protected]' | ||
const singleCharacter = 'a' | ||
cy.get('#testEmail').type(email) | ||
|
||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name should contain at least one character').should('exist'); | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name should contain at least one character').should('exist') | ||
|
||
cy.get('#testFullName').type(singleCharacter).blur(); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name should contain at least one character').should('not.exist'); | ||
}); | ||
cy.get('#testFullName').type(singleCharacter).blur() | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name should contain at least one character').should('not.exist') | ||
}) | ||
|
||
|
||
it('test the validation rule for special character', () => { | ||
cy.on('uncaught:exception', (err) => { | ||
expect(err.message).to.include('The legal name should not contain special character') | ||
return false; | ||
return false | ||
}) | ||
|
||
const email = '[email protected]'; | ||
const invalidName = 'first - last'; | ||
const validName = 'first last'; | ||
cy.get('#testEmail').type(email); | ||
const email = '[email protected]' | ||
const invalidName = 'first - last' | ||
const validName = 'first last' | ||
cy.get('#testEmail').type(email) | ||
|
||
cy.get('#testFullName').type(invalidName); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name should not contain special character').should('exist'); | ||
cy.get('#testFullName').type(invalidName) | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name should not contain special character').should('exist') | ||
|
||
cy.get('#testFullName').clear().type(validName).blur(); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.contains('The legal name should not contain special character').should('not.exist'); | ||
}); | ||
cy.get('#testFullName').clear().type(validName).blur() | ||
cy.get('#exampleSubmitButton').click() | ||
cy.contains('The legal name should not contain special character').should('not.exist') | ||
}) | ||
|
||
|
||
it('the full name field should accept UTF-8 characters', () => { | ||
cy.contains('Full Legal Name:') | ||
const email = '[email protected]'; | ||
cy.get('#testEmail').type(email); | ||
const email = '[email protected]' | ||
cy.get('#testEmail').type(email) | ||
|
||
const name1 = 'François'; | ||
const name2 = 'José 玛丽'; | ||
const name1 = 'François' | ||
const name2 = 'José 玛丽' | ||
|
||
cy.get('#testFullName').type(name1); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.get('#testFullName').clear().type(name2).blur(); | ||
cy.get('#exampleSubmitButton').click(); | ||
cy.get('#testFullName').type(name1) | ||
cy.get('#exampleSubmitButton').click() | ||
cy.get('#testFullName').clear().type(name2).blur() | ||
cy.get('#exampleSubmitButton').click() | ||
}); | ||
|
||
|
||
it('the displayed name should be normalized', () => { | ||
const email = '[email protected]' | ||
cy.get('#testEmail').type(email) | ||
|
||
const name = ' First name M Last name ' | ||
const normailizeName = 'First name M Last name' | ||
cy.get('#testFullName').type(name) | ||
cy.get('#testFullName').invoke('val').should('eq', name) | ||
cy.get('#testFullName').blur() | ||
cy.get('#testFullName').invoke('val').should('eq', normailizeName) | ||
}); | ||
}) |
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