Repository navigation
feat(Flags): Show flag dependencies on the Value tab #8989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+357
−32
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1cd8492
feat(Flags): Show flag dependencies on the Value tab
khvn26 a8623a1
Merge remote-tracking branch 'origin/main' into feat/flag-dependencie…
khvn26 d94364b
test(Flags): Match only the open tab's banner in the dependencies E2E
khvn26 e709f60
refactor(Flags): Count prerequisites met with the design system's chip
khvn26 f312f12
fix(Flags): Declare showing the Dependencies tab once
khvn26 bd4c754
fix(Flags): Name the prerequisites met in the Dependencies tab's name
khvn26 5ced137
fix(Flags): Read flag states for the current environment only
khvn26 8d74c07
fix(Flags): Read flag states from every page of the feature list
khvn26 8ecf60a
fix(Flags): Clear save errors when following links to the Dependencie…
khvn26 7eeb80a
test(Flags): Cover following every page of a list
khvn26 3f4b8f1
test(Flags): Assert a failed page returns only its error
khvn26 aad90ce
fix(Flags): Stop the prerequisites chip taking the tab's height
khvn26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,83 @@ | ||
| jest.mock('common/services/useProjectFlag', () => ({ | ||
| useGetProjectFlagsQuery: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('common/hooks/useProjectEnvironments', () => ({ | ||
| useProjectEnvironments: jest.fn(), | ||
| })) | ||
|
|
||
| import { useFeatureStates } from 'common/hooks/useFeatureStates' | ||
| import { useGetProjectFlagsQuery } from 'common/services/useProjectFlag' | ||
| import { useProjectEnvironments } from 'common/hooks/useProjectEnvironments' | ||
| import { ProjectFlag } from 'common/types/responses' | ||
|
|
||
| const mockUseGetProjectFlagsQuery = | ||
| useGetProjectFlagsQuery as jest.MockedFunction<typeof useGetProjectFlagsQuery> | ||
| const mockUseProjectEnvironments = | ||
| useProjectEnvironments as jest.MockedFunction<typeof useProjectEnvironments> | ||
|
|
||
| const enabledFeature = { | ||
| environment_feature_state: { enabled: true }, | ||
| id: 1, | ||
| } as unknown as ProjectFlag | ||
|
|
||
| describe('useFeatureStates', () => { | ||
| beforeEach(() => { | ||
| mockUseProjectEnvironments.mockReturnValue({ | ||
| error: undefined, | ||
| getEnvironmentIdFromKey: () => 2, | ||
| isLoading: false, | ||
| } as any) | ||
| }) | ||
|
|
||
| it("ignores another environment's list while this one's loads", () => { | ||
| // Given | ||
| mockUseGetProjectFlagsQuery.mockReturnValue({ | ||
| currentData: undefined, | ||
| data: { results: [enabledFeature] }, | ||
| isError: false, | ||
| isLoading: false, | ||
| } as any) | ||
|
|
||
| // When | ||
| const states = useFeatureStates({ environmentId: 'key', projectId: 1 }) | ||
|
|
||
| // Then | ||
| expect(states.isLoading).toBe(true) | ||
| expect(states.features).toEqual([]) | ||
| }) | ||
|
|
||
| it('requests project flags for the resolved environment', () => { | ||
| // Given | ||
| mockUseGetProjectFlagsQuery.mockReturnValue({ | ||
| currentData: { results: [] }, | ||
| isError: false, | ||
| isLoading: false, | ||
| } as any) | ||
|
|
||
| // When | ||
| useFeatureStates({ environmentId: 'key', projectId: 1 }) | ||
|
|
||
| // Then | ||
| expect(mockUseGetProjectFlagsQuery).toHaveBeenCalledWith( | ||
| { environment: 2, project: '1' }, | ||
| { skip: false }, | ||
| ) | ||
| }) | ||
|
|
||
| it("reads this environment's list once loaded", () => { | ||
| // Given | ||
| mockUseGetProjectFlagsQuery.mockReturnValue({ | ||
| currentData: { results: [enabledFeature] }, | ||
| isError: false, | ||
| isLoading: false, | ||
| } as any) | ||
|
|
||
| // When | ||
| const states = useFeatureStates({ environmentId: 'key', projectId: 1 }) | ||
|
|
||
| // Then | ||
| expect(states.isLoading).toBe(false) | ||
| expect(states.isEnabled(1)).toBe(true) | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
| import { recursivePageGet } from 'common/utils/recursivePageGet' | ||
|
|
||
| describe('recursivePageGet', () => { | ||
| it('follows next links, concatenating the pages', async () => { | ||
| // Given | ||
| const baseQuery = jest | ||
| .fn() | ||
| .mockResolvedValueOnce({ | ||
| data: { | ||
| count: 3, | ||
| next: 'items/?page=2', | ||
| previous: null, | ||
| results: [1, 2], | ||
| }, | ||
| }) | ||
| .mockResolvedValueOnce({ | ||
| data: { count: 3, next: null, previous: 'items/?page=1', results: [3] }, | ||
| }) | ||
|
|
||
| // When | ||
| const res = await recursivePageGet<number>('items/?page=1', null, baseQuery) | ||
|
|
||
| // Then | ||
| expect(baseQuery.mock.calls.map(([arg]) => arg)).toEqual([ | ||
| { method: 'GET', url: 'items/?page=1' }, | ||
| { method: 'GET', url: 'items/?page=2' }, | ||
| ]) | ||
| expect(res.data?.results).toEqual([1, 2, 3]) | ||
| }) | ||
|
|
||
| it('returns the error of a failing page', async () => { | ||
| // Given | ||
| const error = { status: 500 } | ||
| const baseQuery = jest | ||
| .fn() | ||
| .mockResolvedValueOnce({ | ||
| data: { count: 3, next: 'items/?page=2', previous: null, results: [1] }, | ||
| }) | ||
| .mockResolvedValueOnce({ error }) | ||
|
|
||
| // When | ||
| const res = await recursivePageGet<number>('items/?page=1', null, baseQuery) | ||
|
|
||
| // Then | ||
| expect(res).toEqual({ error }) | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.