-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/pci ai notebooks unit test listing page (#14808)
* feat(pci.ai.notebook): add unit test in listing page and modal REF:DATATR-1818 * feat(pci.ai.notebook): fix pr comments * feat(pci.ai.notebook): add unit test in dashboard page (#14815) * feat(pci.ai.notebook): add unit test in dashboard page * feat(pci.ai.notebook): remove useless comments REF:DATATR-1819 * feat(pci.ai.notebook): add unit test on logs and backups page (#14832) REF: DATATR-1823,DATATR-1822 Signed-off-by: Arthur Bullet <[email protected]>
- Loading branch information
Showing
36 changed files
with
1,905 additions
and
23 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
37 changes: 37 additions & 0 deletions
37
packages/manager/apps/pci-ai-notebooks/src/__tests__/helpers/mocks/volume.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,37 @@ | ||
import * as ai from '@/types/cloud/project/ai'; | ||
|
||
export const mockedVolume: ai.volume.Volume = { | ||
cache: false, | ||
mountPath: '/demo', | ||
permission: ai.VolumePermissionEnum.RO, | ||
volumeSource: { | ||
dataStore: { | ||
alias: 'alias', | ||
container: 'container', | ||
}, | ||
}, | ||
}; | ||
|
||
export const mockedDatastoreVolume: ai.volume.Volume = { | ||
cache: false, | ||
mountPath: '/demo1', | ||
permission: ai.VolumePermissionEnum.RO, | ||
volumeSource: { | ||
dataStore: { | ||
alias: 'alias1', | ||
container: 'container1', | ||
internal: false, | ||
}, | ||
}, | ||
}; | ||
|
||
export const mockedPublicGitVolume: ai.volume.Volume = { | ||
cache: true, | ||
mountPath: '/publicGit', | ||
permission: ai.VolumePermissionEnum.RWD, | ||
volumeSource: { | ||
publicGit: { | ||
url: 'https://myUrl.com', | ||
}, | ||
}, | ||
}; |
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
45 changes: 45 additions & 0 deletions
45
packages/manager/apps/pci-ai-notebooks/src/pages/Auth.layout.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,45 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import Layout, { Loader } from '@/pages/Auth.layout'; | ||
import { RouterWithQueryClientWrapper } from '@/__tests__/helpers/wrappers/RouterWithQueryClientWrapper'; | ||
import * as authAPI from '@/data/api/ai/authorization.api'; | ||
|
||
const AuthLayoutProps = { | ||
params: { | ||
projectId: 'projectId', | ||
}, | ||
request: new Request('https://my-api.com/endpoint'), | ||
}; | ||
|
||
describe('Auth Layout', () => { | ||
beforeEach(() => { | ||
vi.restoreAllMocks(); | ||
|
||
vi.mock('@/data/api/ai/authorization.api', () => { | ||
return { | ||
getAuthorization: vi.fn(() => ({ | ||
authorized: true, | ||
})), | ||
}; | ||
}); | ||
}); | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('fetches project authorization', async () => { | ||
Loader(AuthLayoutProps); | ||
await waitFor(() => { | ||
expect(authAPI.getAuthorization).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('renders the Layout component', async () => { | ||
render(<Layout />, { | ||
wrapper: RouterWithQueryClientWrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(screen.getByText('/')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
packages/manager/apps/pci-ai-notebooks/src/pages/Root.layout.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,57 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
|
||
import Layout, { breadcrumb as Breadcrumb, Loader } from '@/pages/Root.layout'; | ||
import { RouterWithQueryClientWrapper } from '@/__tests__/helpers/wrappers/RouterWithQueryClientWrapper'; | ||
import * as projectAPI from '@/data/api/project/project.api'; | ||
|
||
const breadCrumbParam = { | ||
params: { | ||
projectId: 'projectId', | ||
}, | ||
request: new Request('https://my-api.com/endpoint'), | ||
}; | ||
|
||
describe('Notebooks Layout', () => { | ||
beforeEach(() => { | ||
vi.restoreAllMocks(); | ||
|
||
vi.mock('@/data/api/project/project.api', () => { | ||
return { | ||
getProject: vi.fn(() => ({ | ||
project_id: '123456', | ||
projectName: 'projectName', | ||
description: 'description', | ||
})), | ||
}; | ||
}); | ||
}); | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('renders the breadcrumb component', async () => { | ||
render(<Breadcrumb />, { | ||
wrapper: RouterWithQueryClientWrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(screen.getByText('Notebooks')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('fetches project data', async () => { | ||
Loader(breadCrumbParam); | ||
await waitFor(() => { | ||
expect(projectAPI.getProject).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('renders the Layout component', async () => { | ||
render(<Layout />, { | ||
wrapper: RouterWithQueryClientWrapper, | ||
}); | ||
await waitFor(() => { | ||
expect(screen.getByTestId('pageLayout')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
packages/manager/apps/pci-ai-notebooks/src/pages/Root.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,74 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import Root, { Loader } from '@/pages/Root.page'; | ||
import { Locale } from '@/hooks/useLocale'; | ||
import { RouterWithQueryClientWrapper } from '@/__tests__/helpers/wrappers/RouterWithQueryClientWrapper'; | ||
import * as notebookApi from '@/data/api/ai/notebook/notebook.api'; | ||
import { mockedNotebook } from '@/__tests__/helpers/mocks/notebook'; | ||
|
||
const NotebookProps = { | ||
params: { | ||
projectId: 'projectId', | ||
}, | ||
request: new Request('https://my-api.com/endpoint'), | ||
}; | ||
|
||
describe('Home page', () => { | ||
beforeEach(() => { | ||
vi.restoreAllMocks(); | ||
// Mock necessary hooks and dependencies | ||
vi.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => key, | ||
}), | ||
})); | ||
|
||
vi.mock('react-router-dom', async () => { | ||
const mod = await vi.importActual('react-router-dom'); | ||
return { | ||
...mod, | ||
redirect: vi.fn(), | ||
useParams: () => ({ | ||
projectId: 'projectId', | ||
}), | ||
}; | ||
}); | ||
|
||
vi.mock('@/data/api/ai/notebook/notebook.api', () => ({ | ||
getNotebooks: vi.fn(() => []), | ||
})); | ||
|
||
vi.mock('@ovh-ux/manager-react-shell-client', async (importOriginal) => { | ||
const mod = await importOriginal< | ||
typeof import('@ovh-ux/manager-react-shell-client') | ||
>(); | ||
return { | ||
...mod, | ||
useShell: vi.fn(() => ({ | ||
i18n: { | ||
getLocale: vi.fn(() => Locale.fr_FR), | ||
onLocaleChange: vi.fn(), | ||
setLocale: vi.fn(), | ||
}, | ||
})), | ||
}; | ||
}); | ||
}); | ||
|
||
it('fetches notebook data', async () => { | ||
Loader(NotebookProps); | ||
await waitFor(() => { | ||
expect(notebookApi.getNotebooks).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it('should display notebook page', async () => { | ||
vi.mocked(notebookApi.getNotebooks).mockResolvedValue([mockedNotebook]); | ||
render(<Root />, { wrapper: RouterWithQueryClientWrapper }); | ||
await waitFor(() => { | ||
expect( | ||
screen.getByTestId('notebooks-guides-container'), | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.