-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add error message when project not aligned to spaceId (#7587)
* feat: add error message when project not aligned to spaceId * chore: add teamId scope * fix: fix api path selection on error * fix: add another test * chore: add more tests to api path selection * chore: add a test file for projectSelection * fix: adjust logic of when the project env is validated * chore: small copy changes * fix: adjust api path filtering * chore: change name of listProject
- Loading branch information
Showing
18 changed files
with
286 additions
and
40 deletions.
There are no files selected for viewing
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
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
69 changes: 69 additions & 0 deletions
69
...end/src/components/config-screen/ProjectSelectionSection/ProjectSelectionSection.spec.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,69 @@ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { AppInstallationParameters } from '@customTypes/configPage'; | ||
import { ProjectSelectionSection } from './ProjectSelectionSection'; | ||
import { copies } from '@constants/copies'; | ||
import { renderConfigPageComponent } from '@test/helpers/renderConfigPageComponent'; | ||
import userEvent from '@testing-library/user-event'; | ||
import * as fetchData from '@hooks/useFetchData/useFetchData'; | ||
|
||
const projects = [ | ||
{ id: 'project-1', name: 'Project 1', targets: { production: { id: 'project-1' } }, env: [] }, | ||
]; | ||
|
||
describe('ProjectSelectionSection', () => { | ||
it('renders dropdown when paths are present and no errors are present', () => { | ||
const { unmount } = renderConfigPageComponent(<ProjectSelectionSection projects={projects} />); | ||
|
||
const select = screen.getByTestId('optionsSelect'); | ||
expect(select).toBeTruthy(); | ||
unmount(); | ||
}); | ||
|
||
it('renders no selected value in dropdown when projectNotFound error', () => { | ||
const mockDispatchParameters = vi.fn(); | ||
const parameters = { | ||
dispatchParameters: mockDispatchParameters, | ||
} as unknown as AppInstallationParameters; | ||
const { unmount } = renderConfigPageComponent( | ||
<ProjectSelectionSection projects={projects} />, | ||
parameters | ||
); | ||
|
||
const emptyInput = screen.getByText(copies.configPage.projectSelectionSection.placeholder); | ||
expect(emptyInput).toBeTruthy(); | ||
unmount(); | ||
}); | ||
|
||
it('handles project selection', async () => { | ||
const user = userEvent.setup(); | ||
const mockValidation = vi.fn().mockImplementationOnce(() => Promise.resolve()); | ||
vi.spyOn(fetchData, 'useFetchData').mockReturnValue({ | ||
validateProjectEnv: mockValidation, | ||
validateToken: vi.fn(), | ||
fetchProjects: vi.fn(), | ||
fetchApiPaths: vi.fn(), | ||
}); | ||
const mockHandleAppConfigurationChange = vi.fn(); | ||
const mockDispatchParameters = vi.fn(); | ||
const overrides = { | ||
dispatchParameters: mockDispatchParameters, | ||
handleAppConfigurationChange: mockHandleAppConfigurationChange, | ||
parameters: { teamId: '1234', selectedProject: projects[0].id }, | ||
} as unknown as AppInstallationParameters; | ||
|
||
const { unmount } = renderConfigPageComponent(<ProjectSelectionSection projects={projects} />, { | ||
...overrides, | ||
}); | ||
|
||
const selectDropdown = screen.getByTestId('optionsSelect'); | ||
|
||
user.selectOptions(selectDropdown, projects[0].name); | ||
|
||
await waitFor(() => expect(mockHandleAppConfigurationChange).toBeCalled()); | ||
await waitFor(() => expect(mockDispatchParameters).toBeCalled()); | ||
await waitFor(() => expect(mockValidation).toBeCalled()); | ||
unmount(); | ||
}); | ||
}); |
Oops, something went wrong.