-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/delete-project-tokens-when-removing-la…
…st-project
- Loading branch information
Showing
28 changed files
with
714 additions
and
245 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
frontend/src/component/feature/CreateFeature/CreateFeature.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,77 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
import CreateFeature from './CreateFeature'; | ||
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
|
||
const server = testServerSetup(); | ||
|
||
const setupApi = ({ | ||
flagCount, | ||
flagLimit, | ||
}: { flagCount: number; flagLimit: number }) => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
resourceLimits: true, | ||
}, | ||
resourceLimits: { | ||
featureFlags: flagLimit, | ||
}, | ||
}); | ||
|
||
testServerRoute(server, '/api/admin/search/features', { | ||
total: flagCount, | ||
features: Array.from({ length: flagCount }).map((_, i) => ({ | ||
name: `flag-${i}`, | ||
})), | ||
}); | ||
}; | ||
|
||
test("should allow you to create feature flags when you're below the global limit", async () => { | ||
setupApi({ flagLimit: 3, flagCount: 2 }); | ||
|
||
render( | ||
<Routes> | ||
<Route | ||
path='/projects/:projectId/create-toggle' | ||
element={<CreateFeature />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/create-toggle', | ||
permissions: [{ permission: CREATE_FEATURE }], | ||
}, | ||
); | ||
|
||
await waitFor(async () => { | ||
const button = await screen.findByRole('button', { | ||
name: /create feature flag/i, | ||
}); | ||
expect(button).not.toBeDisabled(); | ||
}); | ||
}); | ||
|
||
test("should not allow you to create API tokens when you're at the global limit", async () => { | ||
setupApi({ flagLimit: 3, flagCount: 3 }); | ||
|
||
render( | ||
<Routes> | ||
<Route | ||
path='/projects/:projectId/create-toggle' | ||
element={<CreateFeature />} | ||
/> | ||
</Routes>, | ||
{ | ||
route: '/projects/default/create-toggle', | ||
permissions: [{ permission: CREATE_FEATURE }], | ||
}, | ||
); | ||
|
||
await waitFor(async () => { | ||
const button = await screen.findByRole('button', { | ||
name: /create feature flag/i, | ||
}); | ||
expect(button).toBeDisabled(); | ||
}); | ||
}); |
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
12 changes: 6 additions & 6 deletions
12
...eateFeature/isFeatureLimitReached.test.ts → ...ture/isProjectFeatureLimitReached.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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { isFeatureLimitReached } from './CreateFeature'; | ||
import { isProjectFeatureLimitReached } from './CreateFeature'; | ||
|
||
test('isFeatureLimitReached should return false when featureLimit is null', async () => { | ||
expect(isFeatureLimitReached(null, 5)).toBe(false); | ||
expect(isProjectFeatureLimitReached(null, 5)).toBe(false); | ||
}); | ||
|
||
test('isFeatureLimitReached should return false when featureLimit is undefined', async () => { | ||
expect(isFeatureLimitReached(undefined, 5)).toBe(false); | ||
expect(isProjectFeatureLimitReached(undefined, 5)).toBe(false); | ||
}); | ||
|
||
test('isFeatureLimitReached should return false when featureLimit is smaller current feature count', async () => { | ||
expect(isFeatureLimitReached(6, 5)).toBe(false); | ||
expect(isProjectFeatureLimitReached(6, 5)).toBe(false); | ||
}); | ||
|
||
test('isFeatureLimitReached should return true when featureLimit is smaller current feature count', async () => { | ||
expect(isFeatureLimitReached(4, 5)).toBe(true); | ||
expect(isProjectFeatureLimitReached(4, 5)).toBe(true); | ||
}); | ||
|
||
test('isFeatureLimitReached should return true when featureLimit is equal to current feature count', async () => { | ||
expect(isFeatureLimitReached(5, 5)).toBe(true); | ||
expect(isProjectFeatureLimitReached(5, 5)).toBe(true); | ||
}); |
71 changes: 71 additions & 0 deletions
71
frontend/src/component/feature/CreateFeature/useFlagLimits.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,71 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useFlagLimits } from './CreateFeature'; | ||
import { vi } from 'vitest'; | ||
|
||
vi.mock('hooks/useUiFlag', async (importOriginal) => { | ||
const actual = await importOriginal(); | ||
return { | ||
...(actual as {}), | ||
useUiFlag: (flag: string) => flag === 'resourceLimits', | ||
}; | ||
}); | ||
|
||
test('if both global and project-level limits are reached, then the error message shows the message for instance-wide limits', () => { | ||
const { result } = renderHook(() => | ||
useFlagLimits({ | ||
global: { limit: 1, count: 1 }, | ||
project: { limit: 1, count: 1 }, | ||
}), | ||
); | ||
|
||
expect(result.current).toMatchObject({ | ||
globalFlagLimitReached: true, | ||
projectFlagLimitReached: true, | ||
limitMessage: expect.stringContaining('instance-wide limit'), | ||
}); | ||
}); | ||
|
||
test('if only global level is reached, the projectFlagLimitReached property is false', () => { | ||
const { result } = renderHook(() => | ||
useFlagLimits({ | ||
global: { limit: 1, count: 1 }, | ||
project: { limit: 1, count: 0 }, | ||
}), | ||
); | ||
|
||
expect(result.current).toMatchObject({ | ||
globalFlagLimitReached: true, | ||
projectFlagLimitReached: false, | ||
limitMessage: expect.stringContaining('instance-wide limit'), | ||
}); | ||
}); | ||
|
||
test('if only the project limit is reached, the limit message talks about the project limit', () => { | ||
const { result } = renderHook(() => | ||
useFlagLimits({ | ||
global: { limit: 2, count: 1 }, | ||
project: { limit: 1, count: 1 }, | ||
}), | ||
); | ||
|
||
expect(result.current).toMatchObject({ | ||
globalFlagLimitReached: false, | ||
projectFlagLimitReached: true, | ||
limitMessage: expect.stringContaining('project limit'), | ||
}); | ||
}); | ||
|
||
test('if neither limit is reached, the limit message is undefined', () => { | ||
const { result } = renderHook(() => | ||
useFlagLimits({ | ||
global: { limit: 1, count: 0 }, | ||
project: { limit: 1, count: 0 }, | ||
}), | ||
); | ||
|
||
expect(result.current).toMatchObject({ | ||
globalFlagLimitReached: false, | ||
projectFlagLimitReached: false, | ||
limitMessage: undefined, | ||
}); | ||
}); |
66 changes: 0 additions & 66 deletions
66
frontend/src/component/feature/CreateFeatureButton/CreateFeatureButton.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.