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

fix: disabling service form creation when loading #952

Merged
merged 1 commit into from
Apr 23, 2024
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
51 changes: 51 additions & 0 deletions packages/frontend/src/pages/CreateService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,57 @@ test('tasks should be displayed after requestCreateInferenceServer', async () =>
});
});

test('form should be disabled when loading', async () => {
mocks.modelsInfoSubscribeMock.mockReturnValue([{ id: 'random', file: true }]);

let listener: ((tasks: Task[]) => void) | undefined;
vi.spyOn(mocks.tasksQueriesMock, 'subscribe').mockImplementation((f: (tasks: Task[]) => void) => {
listener = f;
listener([]);
return () => {};
});

render(CreateService);

// wait for listener to be defined
await vi.waitFor(() => {
expect(listener).toBeDefined();
});

let createBtn: HTMLElement | undefined = undefined;
await vi.waitFor(() => {
createBtn = screen.getByTitle('Create service');
expect(createBtn).toBeDefined();
});

if (createBtn === undefined || listener === undefined) throw new Error('properties undefined');

await fireEvent.click(createBtn);

await vi.waitFor(() => {
expect(studioClient.requestCreateInferenceServer).toHaveBeenCalled();
});

listener([
{
id: 'dummyTaskId',
labels: {
trackingId: 'dummyTrackingId',
},
name: 'Dummy Task name',
state: 'loading',
},
]);

await vi.waitFor(() => {
const select = screen.getByRole('combobox', { name: 'Model select' });
expect(select).toBeDisabled();

const input = screen.getByRole('spinbutton', { name: 'Port input' });
expect(input).toBeDisabled();
});
});

test('should display error message if createService fails', async () => {
mocks.modelsInfoSubscribeMock.mockReturnValue([{ id: 'random', file: true }]);

Expand Down
12 changes: 9 additions & 3 deletions packages/frontend/src/pages/CreateService.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ let error: boolean = false;
let containerId: string | undefined = undefined;
$: available = containerId && $inferenceServers.some(server => server.container.containerId);

$: loading = trackingId !== undefined && !error;

let connectionInfo: ContainerConnectionInfo | undefined;
$: if (localModels && modelId) {
checkContainerConnectionStatus(localModels, modelId, 'inference')
Expand Down Expand Up @@ -155,9 +157,11 @@ onMount(async () => {
<select
required
bind:value="{modelId}"
id="providerChoice"
disabled="{loading}"
aria-label="Model select"
id="model-select"
class="border text-sm rounded-lg w-full focus:ring-purple-500 focus:border-purple-500 block p-2.5 bg-charcoal-900 border-charcoal-900 placeholder-gray-700 text-white"
name="providerChoice">
name="Model select">
{#each localModels as model}
<option class="my-1" value="{model.id}">{model.name}</option>
{/each}
Expand All @@ -184,6 +188,8 @@ onMount(async () => {
class="w-full p-2 outline-none text-sm bg-charcoal-600 rounded-sm text-gray-700 placeholder-gray-700"
placeholder="8888"
name="containerPort"
aria-label="Port input"
disabled="{loading}"
required />
</div>
{#if errorMsg !== undefined}
Expand All @@ -194,7 +200,7 @@ onMount(async () => {
{#if containerId === undefined}
<Button
title="Create service"
inProgress="{trackingId !== undefined && !error}"
inProgress="{loading}"
on:click="{submit}"
disabled="{!modelId}"
icon="{faPlusCircle}">
Expand Down