Skip to content

Commit

Permalink
Merge pull request #490 from eve-git/14439
Browse files Browse the repository at this point in the history
validate NR
  • Loading branch information
eve-git authored Apr 26, 2023
2 parents 3134b5e + 20961fe commit b4007ed
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "business-edit-ui",
"version": "4.3.3",
"version": "4.3.4",
"private": true,
"appName": "Edit UI",
"sbcName": "SBC Common Components",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,12 @@ export default class CorrectNameRequest extends Mixins(CommonMixin, NameRequestM
}
private isValidNrNumber (value: string): boolean {
const VALID_FORMAT = new RegExp(/^(NR )\d{7}$/)
return VALID_FORMAT.test(value)
const VALID_FORMAT = new RegExp(/^(NR)?\s*(\d{7})$/)
if (VALID_FORMAT.test(value)) {
this.nameRequestNumber = 'NR ' + value.match(VALID_FORMAT)[2]
return true
}
return false
}
private validateEmailFormat (value: string): boolean {
Expand Down
82 changes: 82 additions & 0 deletions tests/unit/CorrectNameRequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,56 @@ describe('CorrectNameRequest', () => {
await flushPromises()

expect(wrapper.vm.isFormValid).toBe(true)
expect(wrapper.vm.nameRequestNumber).toEqual('NR 1234567')
})

it('verifies inputs when valid', async () => {
const wrapper = wrapperFactory()

// Verify Invalid before input
expect(wrapper.vm.isFormValid).toBe(false)

wrapper.vm.nameRequestNumber = 'NR 1234567'
wrapper.vm.applicantPhone = '123 456 7890'
wrapper.vm.applicantEmail = '[email protected]'

await flushPromises()

expect(wrapper.vm.isFormValid).toBe(true)
expect(wrapper.vm.nameRequestNumber).toEqual('NR 1234567')
})

it('verifies inputs when valid', async () => {
const wrapper = wrapperFactory()

// Verify Invalid before input
expect(wrapper.vm.isFormValid).toBe(false)

wrapper.vm.nameRequestNumber = '1234567'
wrapper.vm.applicantPhone = '123 456 7890'
wrapper.vm.applicantEmail = '[email protected]'

await flushPromises()

expect(wrapper.vm.isFormValid).toBe(true)
expect(wrapper.vm.nameRequestNumber).toEqual('NR 1234567')
})

// the spaces between 'NR' and the numbers are ignored
it('verifies valid NR input', async () => {
const wrapper = wrapperFactory()

// Verify Invalid before input
expect(wrapper.vm.isFormValid).toBe(false)

wrapper.vm.nameRequestNumber = 'NR 1234567'
wrapper.vm.applicantPhone = '123 456 7890'
wrapper.vm.applicantEmail = '[email protected]'

await flushPromises()

expect(wrapper.vm.isFormValid).toBe(true)
expect(wrapper.vm.nameRequestNumber).toEqual('NR 1234567')
})

it('verifies invalid NR', async () => {
Expand All @@ -92,6 +142,38 @@ describe('CorrectNameRequest', () => {
expect(wrapper.vm.isFormValid).toBe(false)
})

// the leading or trailing spaces of a NR are invalid
it('verifies invalid NR', async () => {
const wrapper = wrapperFactory()

// Verify Invalid before input
expect(wrapper.vm.isFormValid).toBe(false)

wrapper.vm.nameRequestNumber = ' NR 1234567'
wrapper.vm.applicantPhone = '123 456 7890'
wrapper.vm.applicantEmail = '[email protected]'

await flushPromises()

expect(wrapper.vm.isFormValid).toBe(false)
})

// the leading or trailing spaces are invalid
it('verifies invalid NR', async () => {
const wrapper = wrapperFactory()

// Verify Invalid before input
expect(wrapper.vm.isFormValid).toBe(false)

wrapper.vm.nameRequestNumber = 'NR 1234567 '
wrapper.vm.applicantPhone = '123 456 7890'
wrapper.vm.applicantEmail = '[email protected]'

await flushPromises()

expect(wrapper.vm.isFormValid).toBe(false)
})

it('verifies invalid email', async () => {
const wrapper = wrapperFactory()

Expand Down

0 comments on commit b4007ed

Please sign in to comment.