Skip to content

Commit

Permalink
add some unit tests on pages
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jan 19, 2024
1 parent cdc2110 commit 2026b9b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/frontend/src/pages/Model.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { vi, test, expect } from 'vitest';
import { screen, render } from '@testing-library/svelte';
import Model from './Model.svelte';
import catalog from '../../../backend/src/ai-user-test.json';

const mocks = vi.hoisted(() => {
return {
getCatalogMock: vi.fn(),
};
});

vi.mock('../utils/client', async () => {
return {
studioClient: {
getCatalog: mocks.getCatalogMock,
},
rpcBrowser: {
subscribe: () => {
return {
unsubscribe: () => {},
};
},
},
};
});

test('should display model information', async () => {
const model = catalog.models.find(m => m.id === 'model1');
expect(model).not.toBeUndefined();

mocks.getCatalogMock.mockResolvedValue(catalog);
render(Model, {
modelId: 'model1',
});
await new Promise(resolve => setTimeout(resolve, 200));

screen.getByText(model!.name);
screen.getByText(model!.description);
});
39 changes: 39 additions & 0 deletions packages/frontend/src/pages/Recipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { vi, test, expect } from 'vitest';
import { screen, render } from '@testing-library/svelte';
import catalog from '../../../backend/src/ai-user-test.json';
import Recipe from './Recipe.svelte';

const mocks = vi.hoisted(() => {
return {
getCatalogMock: vi.fn(),
};
});

vi.mock('../utils/client', async () => {
return {
studioClient: {
getCatalog: mocks.getCatalogMock,
},
rpcBrowser: {
subscribe: () => {
return {
unsubscribe: () => {},
};
},
},
};
});

test('should display recipe information', async () => {
const recipe = catalog.recipes.find(r => r.id === 'recipe 1');
expect(recipe).not.toBeUndefined();

mocks.getCatalogMock.mockResolvedValue(catalog);
render(Recipe, {
recipeId: 'recipe 1',
});
await new Promise(resolve => setTimeout(resolve, 200));

screen.getByText(recipe!.name);
screen.getByText(recipe!.readme);
});

0 comments on commit 2026b9b

Please sign in to comment.