Skip to content

Commit

Permalink
test: for finetune
Browse files Browse the repository at this point in the history
  • Loading branch information
jialudev committed Dec 27, 2024
1 parent 60b2774 commit 917f54f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
60 changes: 33 additions & 27 deletions frontend/src/components/__tests__/finetune/FinetuneDetail.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, it, expect, vi } from "vitest";
import { mount } from "@vue/test-utils";
import FinetuneDetail from "@/components/finetune/FinetuneDetail.vue";

// Mock useFetchApi
vi.mock('@/packs/useFetchApi', () => ({
default: (url) => ({
Expand All @@ -10,20 +9,18 @@ vi.mock('@/packs/useFetchApi', () => ({
return Promise.resolve({
data: {
value: {
body: {
data: {
deploy_name: 'Test Finetune',
proxy_endpoint: 'test.endpoint',
hardware: 'Test Hardware',
repository_id: 123,
svc_name: 'Test Service',
model_id: 456,
deploy_id: 789,
runtime_framework: 'Test Framework',
cluster_id: 'Test Cluster',
status: 'Running',
endpoint: 'test.endpoint'
}
data: {
deploy_name: 'Test Finetune',
proxy_endpoint: 'test.endpoint',
hardware: 'Test Hardware',
repository_id: 123,
svc_name: 'Test Service',
model_id: '456',
deploy_id: 789,
runtime_framework: 'Test Framework',
cluster_id: 'Test Cluster',
status: 'Running',
endpoint: 'test.endpoint'
}
}
},
Expand All @@ -36,15 +33,13 @@ vi.mock('@/packs/useFetchApi', () => ({
return Promise.resolve({
data: {
value: {
body: {
data: [
{
name: 'Test Resource',
resources: 'Test Hardware',
is_available: true
}
]
}
data: [
{
name: 'Test Resource',
resources: 'Test Hardware',
is_available: true
}
]
}
},
error: { value: null },
Expand All @@ -71,6 +66,18 @@ vi.mock('@/packs/useFetchApi', () => ({
})
}));


vi.mock('@microsoft/fetch-event-source', () => {
return {
fetchEventSource: vi.fn((url, options) => {
// Simulate the onopen and onmessage events
options.onopen({ ok: true, status: 200 });
options.onmessage({ data: JSON.stringify({ status: 'Running', details: [{ name: 'Test Resource' }] }) });
return { close: vi.fn() }; // Return a mock close function
})
}
})

const createWrapper = (props = {}) => {
window.ENABLE_HTTPS = 'false';
return mount(FinetuneDetail, {
Expand Down Expand Up @@ -98,18 +105,17 @@ describe("FinetuneDetail", () => {
expect(wrapper.exists()).toBe(true);
});

it.skip("fetches finetune details on mount", async () => {
it("fetches finetune details on mount", async () => {
const wrapper = createWrapper();
await wrapper.vm.$nextTick();
expect(wrapper.vm.finetune.deploy_name).toBe('Test Finetune');
expect(wrapper.vm.appStatus).toBe('Running');
});


it.skip("handles SSE connection successfully", async () => {
it("handles SSE connection successfully", async () => {
const wrapper = createWrapper();
await wrapper.vm.$nextTick();
expect(fetchEventSource).toHaveBeenCalled();
expect(wrapper.vm.isStatusSSEConnected).toBe(true);
expect(wrapper.vm.appStatus).toBe('Running');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ vi.mock('@/packs/useFetchApi', () => ({
return Promise.resolve({
data: {
value: {
body: {
data: [
{ cluster_id: 'cluster-1', region: 'region-1' },
{ cluster_id: 'cluster-2', region: 'region-2' }
]
}
data: [
{ cluster_id: 'cluster-1', region: 'region-1' },
{ cluster_id: 'cluster-2', region: 'region-2' }
]
}
},
error: { value: null }
Expand Down

0 comments on commit 917f54f

Please sign in to comment.