Skip to content
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

Feat/pci ai notebooks unit test listing page #14808

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
"addLabelNameSubmit": "Ajouter",
"notebookToastErrorTitle": "Erreur",
"notebookToastSuccessTitle": "Succés",
"deleteNotebookSuccess": "Le label a été correctement ajouté à votre notebook"
"notebookLabelSuccess": "Labels correctement mis à jour."
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const mockedJobStatus: ai.job.JobStatus = {
dataSync: [mockedDataSync],
history: [
{
date: 'date',
date: '2024-12-12T16:27:46.65022Z',
state: ai.job.JobStateEnum.DONE,
},
],
Expand All @@ -29,10 +29,10 @@ export const mockedJobStatus: ai.job.JobStatus = {
},
};
export const mockedJob: ai.job.Job = {
createdAt: 'createdAt',
createdAt: '2024-12-12T16:27:46.65022Z',
id: 'jobId',
spec: mockedJobSpec,
status: mockedJobStatus,
updatedAt: 'updatedAt',
updatedAt: '2024-12-12T16:27:46.65022Z',
user: 'user',
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as ai from '@/types/cloud/project/ai';
import { NotebookEnv } from '@/types/cloud/project/ai/notebook/NotebookEnv';
import { mockedJobStatus } from './job';
import { mockedDataSync } from './datasync';
import { mockedVolume } from './volume';

const notebookEnv: NotebookEnv = {
editorId: 'editor',
Expand Down Expand Up @@ -30,11 +31,11 @@ export const mockedNotebookSpec: ai.notebook.NotebookSpec = {
name: 'name',
region: 'region',
resources: mockedResources,
volumes: [mockedVolume],
};

export const mockedNotebookStatus: ai.notebook.NotebookStatus = {
dataSync: [mockedDataSync],

info: {
code: ai.InfoCodeEnum.JOB_DONE,
message: 'message',
Expand Down
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',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
stopNotebook,
} from '@/data/api/ai/notebook/notebook.api';
import { mockedNotebookSpec } from '@/__tests__/helpers/mocks/notebook';
import * as ai from '@/types/cloud/project/ai';

vi.mock('@ovh-ux/manager-core-api', () => {
const get = vi.fn(() => {
Expand Down Expand Up @@ -100,6 +101,19 @@ describe('notebook functions', () => {
privateNetwork: 1,
publicNetwork: 1,
},
volumes: [
{
cache: false,
mountPath: '/demo',
permission: ai.VolumePermissionEnum.RO,
volumeSource: {
dataStore: {
alias: 'alias',
container: 'container',
},
},
},
],
},
);
});
Expand Down Expand Up @@ -168,6 +182,19 @@ describe('notebook functions', () => {
privateNetwork: 1,
publicNetwork: 1,
},
volumes: [
{
cache: false,
mountPath: '/demo',
permission: ai.VolumePermissionEnum.RO,
volumeSource: {
dataStore: {
alias: 'alias',
container: 'container',
},
},
},
],
},
);
});
Expand Down
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();
});
});
});
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 packages/manager/apps/pci-ai-notebooks/src/pages/Root.spec.tsx
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();
});
});
});
Loading
Loading