-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented conditional validation rule apply & custom validators
- Loading branch information
1 parent
e471f81
commit 7cb51fe
Showing
11 changed files
with
236 additions
and
18 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
10 changes: 7 additions & 3 deletions
10
packages/ui/src/components/organisms/Form/Validator/utils/get-validator/get-validator.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
1 change: 1 addition & 0 deletions
1
packages/ui/src/components/organisms/Form/Validator/utils/remove-validator/index.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 @@ | ||
export * from './remove-validator'; |
5 changes: 5 additions & 0 deletions
5
...ges/ui/src/components/organisms/Form/Validator/utils/remove-validator/remove-validator.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,5 @@ | ||
import { validatorsExtends } from '../../validators'; | ||
|
||
export const removeValidator = (type: string) => { | ||
delete validatorsExtends[type]; | ||
}; |
51 changes: 51 additions & 0 deletions
51
.../components/organisms/Form/Validator/utils/remove-validator/remove-validator.unit.test.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,51 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
import { removeValidator } from './remove-validator'; | ||
|
||
vi.mock('../../validators', () => ({ | ||
validatorsExtends: {}, | ||
})); | ||
|
||
describe('removeValidator', async () => { | ||
const validatorsExtends = vi.mocked(await import('../../validators')).validatorsExtends; | ||
|
||
beforeEach(() => { | ||
// Clear validators before each test | ||
Object.keys(validatorsExtends).forEach(key => { | ||
delete validatorsExtends[key]; | ||
}); | ||
}); | ||
|
||
it('should remove validator from validatorsExtends', () => { | ||
// Setup | ||
const mockValidator = vi.fn(); | ||
validatorsExtends['test'] = mockValidator; | ||
expect(validatorsExtends['test']).toBe(mockValidator); | ||
|
||
// Execute | ||
removeValidator('test'); | ||
|
||
// Verify | ||
expect(validatorsExtends['test']).toBeUndefined(); | ||
}); | ||
|
||
it('should not throw error when removing non-existent validator', () => { | ||
expect(() => { | ||
removeValidator('nonexistent'); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('should only remove specified validator', () => { | ||
// Setup | ||
const mockValidator1 = vi.fn(); | ||
const mockValidator2 = vi.fn(); | ||
validatorsExtends['test1'] = mockValidator1; | ||
validatorsExtends['test2'] = mockValidator2; | ||
|
||
// Execute | ||
removeValidator('test1'); | ||
|
||
// Verify | ||
expect(validatorsExtends['test1']).toBeUndefined(); | ||
expect(validatorsExtends['test2']).toBe(mockValidator2); | ||
}); | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/ui/src/components/organisms/Form/Validator/utils/validate/helpers.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,6 @@ | ||
import jsonLogic from 'json-logic-js'; | ||
import { IValidationRule } from '../../types'; | ||
|
||
export const isShouldApplyValidation = (rule: IValidationRule, context: object) => { | ||
return Boolean(jsonLogic.apply(rule.value, context)); | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule data-migrations
updated
from 79ee88 to 7c197a