-
-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
frontend/src/hooks/api/getters/useConstraintsValidation/useConstraintsValidation.test.tsx
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,57 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { IConstraint } from 'interfaces/strategy'; // Assuming you have your component in this path | ||
import { FC } from 'react'; | ||
import { useConstraintsValidation } from './useConstraintsValidation'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const TestComponent: FC<{ constraints: IConstraint[] }> = ({ constraints }) => { | ||
const valid = useConstraintsValidation(constraints); | ||
|
||
return <div>{valid ? 'Valid' : 'Invalid'}</div>; | ||
}; | ||
|
||
it('should display Valid when constraints are valid', async () => { | ||
testServerRoute( | ||
server, | ||
'/api/admin/constraints/validate', | ||
{ data: 'OK' }, | ||
'post' | ||
); | ||
|
||
const validConstraints: IConstraint[] = [ | ||
{ | ||
value: 'test', | ||
values: ['test'], | ||
operator: 'IN', | ||
contextName: 'irrelevant', | ||
}, | ||
{ | ||
value: 'test', | ||
values: ['test'], | ||
operator: 'IN', | ||
contextName: 'irrelevant', | ||
}, | ||
]; | ||
|
||
render(<TestComponent constraints={validConstraints} />); | ||
|
||
await screen.findByText('Valid'); | ||
}); | ||
|
||
it('should display Invalid when constraints are invalid', async () => { | ||
const emptyValueAndValues: IConstraint[] = [ | ||
{ value: '', values: [], operator: 'IN', contextName: 'irrelevant' }, | ||
{ | ||
value: '', | ||
values: [], | ||
operator: 'IN', | ||
contextName: 'irrelevant', | ||
}, | ||
]; | ||
|
||
render(<TestComponent constraints={emptyValueAndValues} />); | ||
|
||
await screen.findByText('Invalid'); | ||
}); |
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