-
Notifications
You must be signed in to change notification settings - Fork 13.1k
ConfigFormGithubCollapse: Hide github features section if nothing is available #113410
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
Open
ywzheng1
wants to merge
1
commit into
main
Choose a base branch
from
ywzheng1/git-sync-hide-empty-github-features-section
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−48
Open
Changes from all commits
Commits
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
ConfigFormGithubCollapse: Hide github features section if nothing is …
…available. Added unit tests
- Loading branch information
commit 7af379779b0b21b771ba4ee2301e4e1866f5a0dd
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
110 changes: 110 additions & 0 deletions
110
public/app/features/provisioning/Config/ConfigFormGithubCollapse.test.tsx
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,110 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { UseFormRegister } from 'react-hook-form'; | ||
| import { MemoryRouter } from 'react-router-dom-v5-compat'; | ||
|
|
||
| import { useGetFrontendSettingsQuery } from 'app/api/clients/provisioning/v0alpha1'; | ||
|
|
||
| import { checkImageRenderer, checkImageRenderingAllowed, checkPublicAccess } from '../GettingStarted/features'; | ||
| import { RepositoryFormData } from '../types'; | ||
|
|
||
| import { ConfigFormGithubCollapse } from './ConfigFormGithubCollapse'; | ||
|
|
||
| jest.mock('app/api/clients/provisioning/v0alpha1', () => ({ | ||
| useGetFrontendSettingsQuery: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../GettingStarted/features', () => ({ | ||
| checkImageRenderer: jest.fn(), | ||
| checkPublicAccess: jest.fn(), | ||
| checkImageRenderingAllowed: jest.fn(), | ||
| })); | ||
|
|
||
| const mockUseGetFrontendSettingsQuery = useGetFrontendSettingsQuery as jest.MockedFunction< | ||
| typeof useGetFrontendSettingsQuery | ||
| >; | ||
| const mockCheckImageRenderer = checkImageRenderer as jest.MockedFunction<typeof checkImageRenderer>; | ||
| const mockCheckPublicAccess = checkPublicAccess as jest.MockedFunction<typeof checkPublicAccess>; | ||
| const mockCheckImageRenderingAllowed = checkImageRenderingAllowed as jest.MockedFunction< | ||
| typeof checkImageRenderingAllowed | ||
| >; | ||
|
|
||
| type SetupOptions = { | ||
| isPublic?: boolean; | ||
| hasImageRenderer?: boolean; | ||
| imageRenderingAllowed?: boolean; | ||
| settingsData?: unknown; | ||
| }; | ||
|
|
||
| function setup(options: SetupOptions = {}) { | ||
| const { isPublic = true, hasImageRenderer = true, imageRenderingAllowed = true, settingsData } = options; | ||
|
|
||
| const data = settingsData ?? { allowImageRendering: imageRenderingAllowed }; | ||
|
|
||
| mockCheckPublicAccess.mockReturnValue(isPublic); | ||
| mockCheckImageRenderer.mockReturnValue(hasImageRenderer); | ||
| mockCheckImageRenderingAllowed.mockReturnValue(imageRenderingAllowed); | ||
| mockUseGetFrontendSettingsQuery.mockReturnValue({ data } as never); | ||
|
|
||
| const registerMock = jest.fn().mockReturnValue({}); | ||
|
|
||
| const renderResult = render( | ||
| <MemoryRouter> | ||
| <ConfigFormGithubCollapse register={registerMock as unknown as UseFormRegister<RepositoryFormData>} /> | ||
| </MemoryRouter> | ||
| ); | ||
|
|
||
| return { renderResult, registerMock }; | ||
| } | ||
|
|
||
| describe('ConfigFormGithubCollapse', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('returns null when image rendering is not allowed on a public instance', () => { | ||
| const { renderResult } = setup({ imageRenderingAllowed: false, isPublic: true }); | ||
|
|
||
| expect(renderResult.container).toBeEmptyDOMElement(); | ||
| expect(screen.queryByText('GitHub features')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders preview checkbox when image rendering is allowed', () => { | ||
| const { registerMock } = setup({ imageRenderingAllowed: true, isPublic: true, hasImageRenderer: true }); | ||
|
|
||
| expect(screen.getByText('GitHub features')).toBeInTheDocument(); | ||
| const checkbox = screen.getByRole('checkbox', { | ||
| name: /Enable dashboard previews in pull requests/i, | ||
| }); | ||
| expect(checkbox).toBeEnabled(); | ||
| expect(registerMock).toHaveBeenCalledWith('generateDashboardPreviews'); | ||
| }); | ||
|
|
||
| it('disables preview checkbox when image renderer is unavailable', () => { | ||
| setup({ hasImageRenderer: false }); | ||
|
|
||
| const checkbox = screen.getByRole('checkbox', { | ||
| name: /Enable dashboard previews in pull requests/i, | ||
| }); | ||
| expect(checkbox).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('disables preview checkbox and shows realtime feedback info on private instances', () => { | ||
| setup({ isPublic: false, imageRenderingAllowed: true }); | ||
|
|
||
| const checkbox = screen.getByRole('checkbox', { | ||
| name: /Enable dashboard previews in pull requests/i, | ||
| }); | ||
| expect(checkbox).toBeDisabled(); | ||
| expect(screen.getByRole('link', { name: 'Configure webhooks' })).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('hides preview checkbox when image rendering is not allowed', () => { | ||
| setup({ imageRenderingAllowed: false, isPublic: false }); | ||
|
|
||
| expect( | ||
| screen.queryByRole('checkbox', { | ||
| name: /Enable dashboard previews in pull requests/i, | ||
| }) | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no logic changes from here to the end, things changes:
StackcomponentnoMarginprops toField