Skip to content

Commit

Permalink
Updated name validator to allow hypen and whitespace character. (#179)
Browse files Browse the repository at this point in the history
* Updated name validator to allow hypen and whitespace character.

* Updated testcafe

---------

Co-authored-by: weskubo-cgi <Wesley.Kubo@gov.bc.ca>
Co-authored-by: AnumehaSrivastava05 <anumeha.saran@gmail.com>
  • Loading branch information
3 people authored Feb 16, 2023
1 parent 9910e97 commit df20fbb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/src/util/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ export function validateSecondName(secondName) {
}

/**
* Validate that input is allowed length and that it contains only alphabets
* Validate that input is allowed length and that it contains only alphabets, hyphen and whitespace
*/
function validateAlpha(input, length) {
if (input.length > length) {
return true
}
return !/[^a-zA-Z]/.test(input)
return !/[^a-z-\sA-Z]/.test(input)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,45 @@ test('Check properly filled form passes validation', async (t) => {
.contains(SUCCESS_MESSAGE)
})

test('Check hyphen and whitespace are allowed for name fields', async (t) => {
await t
.typeText(NameSearchPage.surnameInput, 'Test-Test')
.typeText(NameSearchPage.firstNameInput, 'Test Test')
.typeText(NameSearchPage.dateOfBirthInput, '20001108')
.click(NameSearchPage.radioButton)
.click(NameSearchPage.submitButton)
.wait(1000)
.expect(AlertPage.alertBannerText.textContent)
.contains(NO_SEARCH_RESULT)
// Given the page is filled out correctly
.typeText(AddVisaResidentWithoutPHNPage.groupNumberInput, '6337109')
.click(AddVisaResidentWithoutPHNPage.immigrationCodeSelect)
.click(immigrationCodeOption.withText('Student Authorization'))
.typeText(AddVisaResidentWithoutPHNPage.departmentNumberInput, '123456')
.typeText(AddVisaResidentWithoutPHNPage.visaIssueDateInput, '20210101')
.click(AddVisaResidentWithoutPHNPage.visaExpiryDateInput)
.typeText(AddVisaResidentWithoutPHNPage.visaExpiryDateInput, '20221231')

.typeText(AddVisaResidentWithoutPHNPage.residenceDateInput, '20210101')
.typeText(AddVisaResidentWithoutPHNPage.coverageEffectiveDateInput, '20210101')
.typeText(AddVisaResidentWithoutPHNPage.coverageCancellationDateInput, '20201231')
.typeText(AddVisaResidentWithoutPHNPage.telephoneInput, '7802024022')
.typeText(AddVisaResidentWithoutPHNPage.address1Input, 'Test 111 ST')
.typeText(AddVisaResidentWithoutPHNPage.cityInput, 'VICTORIA')
.click(AddVisaResidentWithoutPHNPage.provinceSelect)
.click(provinceOption.withText('British Columbia'))
.typeText(AddVisaResidentWithoutPHNPage.postalCodeInput, 'V8V8V8')
.click(AddVisaResidentWithoutPHNPage.priorResidenceCodeInput)
.click(priorResidenceCodeOption.withText('British Columbia'))

// When I click the submit button
.click(AddVisaResidentWithoutPHNPage.submitButton)
.wait(5000)
// I expect a success message
.expect(AlertPage.alertBannerText.textContent)
.contains(SUCCESS_MESSAGE)
})

test('Check invalid input field characters validation', async (t) => {
await t
.typeText(NameSearchPage.surnameInput, 'Test')
Expand Down
19 changes: 19 additions & 0 deletions frontend/tests/e2e/tests/enrollment/NameSearchTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ test('Check alpha validation for Name', async (t) => {
.contains(INVALID_SECOND_NAME_MESSAGE)
})

test('Check hyphen and whitespace are allowed for name fields ', async (t) => {
await t
// Given I have a form filled out with data
.typeText(NameSearchPage.surnameInput, 'Test-surname')
.typeText(NameSearchPage.firstNameInput, 'Test firstname')
.typeText(NameSearchPage.secondNameInput, 'Test secondname')
.typeText(NameSearchPage.dateOfBirthInput, '20211108')
.click(NameSearchPage.radioButton)
// When I click the submit button
.click(NameSearchPage.submitButton)
.wait(5000)
// I expect the warning message to display
.expect(AlertPage.alertBannerText.textContent)
.contains(MAX_RESULTS_MESSAGE)
// And the Create New PHN BUtton to be available
.expect(NameSearchPage.createNewPHNButton.exists)
.ok()
})

test('Check length validation for Name', async (t) => {
await t
// Given I have a form filled out with data
Expand Down

0 comments on commit df20fbb

Please sign in to comment.