-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: constraints limit in a strategy UI (#7555)
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...ts/FeatureStrategyConstraintAccordionList/FeatureStrategyConstraintAccordionList.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,61 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import { FeatureStrategyConstraintAccordionList } from './FeatureStrategyConstraintAccordionList'; | ||
import type { IConstraint } from 'interfaces/strategy'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const LIMIT = 5; | ||
|
||
const setupApi = () => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
resourceLimits: true, | ||
}, | ||
resourceLimits: { | ||
constraints: LIMIT, | ||
}, | ||
}); | ||
testServerRoute(server, '/api/admin/context', [{ name: 'text' }]); | ||
}; | ||
|
||
const constraints = (limit: number): IConstraint[] => | ||
Array.from(Array(limit).keys()).map(() => ({ | ||
contextName: 'test', | ||
operator: 'IN', | ||
})); | ||
|
||
test('show limit reached and disable adding new constraints', async () => { | ||
setupApi(); | ||
render( | ||
<FeatureStrategyConstraintAccordionList | ||
constraints={constraints(LIMIT)} | ||
showCreateButton={true} | ||
setConstraints={() => {}} | ||
/>, | ||
); | ||
|
||
await screen.findByText( | ||
'You have reached the limit for constraints in this strategy', | ||
); | ||
const button = await screen.findByText('Add constraint'); | ||
expect(button).toBeDisabled(); | ||
}); | ||
|
||
test('show nearing limit', async () => { | ||
setupApi(); | ||
render( | ||
<FeatureStrategyConstraintAccordionList | ||
constraints={constraints(LIMIT - 1)} | ||
showCreateButton={true} | ||
setConstraints={() => {}} | ||
/>, | ||
); | ||
|
||
await screen.findByText( | ||
'You are nearing the limit for constraints in this strategy', | ||
); | ||
const button = await screen.findByText('Add constraint'); | ||
expect(button).toBeEnabled(); | ||
}); |
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
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