-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix models downloaded being displayed in banner
Signed-off-by: axel7083 <[email protected]>
- Loading branch information
Showing
3 changed files
with
113 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { vi, test, expect } from 'vitest'; | ||
import { screen, render, waitFor } from '@testing-library/svelte'; | ||
import Models from './Models.svelte'; | ||
import type { RecipeStatus } from '@shared/src/models/IRecipeStatus'; | ||
|
||
const mocks = vi.hoisted(() => { | ||
return { | ||
getCatalogMock: vi.fn(), | ||
getPullingStatusesMock: vi.fn().mockResolvedValue(new Map()), | ||
getLocalModelsMock: vi.fn().mockResolvedValue([]), | ||
localModelsSubscribeMock: vi.fn(), | ||
localModelsQueriesMock: { | ||
subscribe: (f: (msg: any) => void) => { | ||
f(mocks.localModelsSubscribeMock()); | ||
return () => {}; | ||
}, | ||
}, | ||
getLocalModels: vi.fn().mockResolvedValue([]), | ||
}; | ||
}); | ||
|
||
vi.mock('/@/utils/client', async () => { | ||
return { | ||
studioClient: { | ||
getLocalModels: mocks.getLocalModels, | ||
getPullingStatuses: mocks.getPullingStatusesMock, | ||
}, | ||
rpcBrowser: { | ||
subscribe: () => { | ||
return { | ||
unsubscribe: () => {}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
vi.mock('../stores/local-models', async () => { | ||
return { | ||
localModels: mocks.localModelsQueriesMock, | ||
}; | ||
}); | ||
|
||
test('should display There is no model yet', async () => { | ||
mocks.localModelsSubscribeMock.mockReturnValue([]); | ||
|
||
render(Models); | ||
|
||
const status = screen.getByRole('status'); | ||
expect(status).toBeDefined(); | ||
}); | ||
|
||
test('should display There is no model yet and have a task running', async () => { | ||
mocks.localModelsSubscribeMock.mockReturnValue([]); | ||
const map = new Map<string, RecipeStatus>(); | ||
map.set('random', { | ||
recipeId: 'random-recipe-id', | ||
state: 'loading', | ||
tasks: [ | ||
{ | ||
id: 'random', | ||
name: 'random', | ||
state: 'loading', | ||
labels: { | ||
'model-pulling': 'random-models-id', | ||
}, | ||
}, | ||
], | ||
}); | ||
mocks.getPullingStatusesMock.mockResolvedValue(map); | ||
|
||
render(Models); | ||
|
||
const status = screen.getByRole('status'); | ||
expect(status).toBeDefined(); | ||
|
||
await waitFor(() => { | ||
const title = screen.getByText('Downloading models'); | ||
expect(title).toBeDefined(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import '@testing-library/jest-dom/vitest'; | ||
import { vi, test, expect } from 'vitest'; | ||
import { screen, render } from '@testing-library/svelte'; | ||
import Models from './Models.svelte'; | ||
|
||
const mocks = vi.hoisted(() => ({ | ||
getLocalModelsMock: vi.fn().mockImplementation(() => Promise.resolve([])), | ||
localModelsSubscribeMock: vi.fn(), | ||
localModelsQueriesMock: { | ||
subscribe: (f: (msg: any) => void) => { | ||
f(mocks.localModelsSubscribeMock()); | ||
return () => {}; | ||
}, | ||
}, | ||
})); | ||
|
||
vi.mock('../stores/local-models', async () => { | ||
return { | ||
localModels: mocks.localModelsQueriesMock, | ||
}; | ||
}); | ||
|
||
test('no models provided should display no model yet', async () => { | ||
mocks.localModelsSubscribeMock.mockReturnValue([]); | ||
render(Models); | ||
|
||
const status = screen.getByRole('status', { value: { text: 'There is no model yet' } }); | ||
expect(status).toBeDefined(); | ||
}); |