-
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.
chore: add a test file for projectSelection
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...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,71 @@ | ||
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 mockValidation = vi.fn().mockImplementationOnce(() => Promise.resolve()); | ||
vi.spyOn(fetchData, 'useFetchData').mockReturnValue({ | ||
validateProjectEnv: mockValidation, | ||
validateToken: vi.fn(), | ||
fetchProjects: vi.fn(), | ||
fetchApiPaths: vi.fn(), | ||
}); | ||
const user = userEvent.setup(); | ||
const mockHandleAppConfigurationChange = vi.fn(); | ||
const mockDispatchParameters = vi.fn(); | ||
const parameters = { | ||
dispatchParameters: mockDispatchParameters, | ||
handleAppConfigurationChange: mockHandleAppConfigurationChange, | ||
} as unknown as AppInstallationParameters; | ||
const projects = [ | ||
{ id: 'project-1', name: 'Project 1', targets: { production: { id: 'project-1' } }, env: [] }, | ||
]; | ||
const { unmount } = renderConfigPageComponent( | ||
<ProjectSelectionSection projects={projects} />, | ||
parameters | ||
); | ||
|
||
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(); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ const mockSdk: any = { | |
}, | ||
ids: { | ||
app: 'test-app', | ||
space: '1234', | ||
}, | ||
cma: { | ||
contentType: { | ||
|