Skip to content

Commit

Permalink
fix: key validating in single mode
Browse files Browse the repository at this point in the history
  • Loading branch information
4dr1en committed Oct 4, 2024
1 parent 024e3fd commit a97e526
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/synapse-bridge/src/patterns/NirField/NirField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export default defineComponent({
numberErrors: [] as string[],
keyErrors: [] as string[],
isSingleField: false,
}
},
watch: {
Expand All @@ -126,14 +124,16 @@ export default defineComponent({
this.keyValue = newValue.slice(NUMBER_LENGTH, DOUBLE_FIELD)
this.validateNumberValue(this.numberValue)
this.validateKeyValue(this.keyValue)
if (!this.isSingleField) {
this.validateKeyValue(this.keyValue)
}
},
},
},
created(): void {
this.isSingleField = this.nirLength === SINGLE_FIELD
},
computed: {
isSingleField(): boolean {
return this.nirLength === SINGLE_FIELD
},
textFieldOptions() {
return deepMerge(config, this.$attrs)
},
Expand All @@ -159,6 +159,9 @@ export default defineComponent({
* Generate the validation rules for the key field
*/
keyRules(): ValidationRule[] {
if (this.isSingleField) {
return []
}
let rules = [
exactLength(KEY_LENGTH, true, {
default: locales.errorLengthKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,22 @@ describe('NirField', () => {
expect(wrapper.text()).toContain(locales.errorRequiredNumber)
expect(wrapper.text()).toContain(locales.errorRequiredKey)
})

it('do not validate the key field in single field mode', async () => {
const wrapper = mount(NirField, {
global: {
plugins: [vuetify],
},
propsData: {
modelValue: '1234567890123',
nirLength: 13,
required: true,
},
})

await wrapper.setProps({ modelValue: '' })

expect(wrapper.text()).toContain(locales.errorRequiredNumber)
expect(wrapper.text()).not.toContain(locales.errorRequiredKey)
});
})

0 comments on commit a97e526

Please sign in to comment.