- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: Limit environments component (#7548)
- Loading branch information
Showing
4 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
frontend/src/component/environments/CreateEnvironment/CreateEnvironment.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 { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from '../../../utils/testServer'; | ||
import CreateEnvironment from './CreateEnvironment'; | ||
import { ADMIN } from '../../providers/AccessProvider/permissions'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = ({ | ||
resourceLimits, | ||
limit, | ||
environments, | ||
}: { resourceLimits: boolean; limit: number; environments: number }) => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
resourceLimits, | ||
}, | ||
resourceLimits: { | ||
environments: limit, | ||
}, | ||
}); | ||
|
||
testServerRoute(server, '/api/admin/environments', { | ||
environments: [...Array(environments).keys()].map((i) => ({ | ||
name: `environment${i}`, | ||
})), | ||
}); | ||
}; | ||
|
||
test('show limit reached info', async () => { | ||
setupApi({ environments: 1, limit: 1, resourceLimits: true }); | ||
render(<CreateEnvironment />, { permissions: [{ permission: ADMIN }] }); | ||
|
||
await screen.findByText('You have reached the limit for environments'); | ||
const createButton = await screen.findByText('Create environment', { | ||
selector: 'button', | ||
}); | ||
expect(createButton).toBeDisabled(); | ||
}); | ||
|
||
test('show approaching limit info', async () => { | ||
setupApi({ environments: 9, limit: 10, resourceLimits: true }); | ||
render(<CreateEnvironment />, { permissions: [{ permission: ADMIN }] }); | ||
|
||
await screen.findByText('You are nearing the limit for environments'); | ||
const createButton = await screen.findByText('Create environment', { | ||
selector: 'button', | ||
}); | ||
expect(createButton).toBeEnabled(); | ||
}); | ||
|
||
test('show limit reached info - no resource limits component', async () => { | ||
setupApi({ environments: 1, limit: 1, resourceLimits: false }); | ||
render(<CreateEnvironment />); | ||
|
||
await screen.findByText('Go back'); | ||
}); |
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