|
1 | | -import { describe, test, expect, expectTypeOf, beforeEach } from "vitest" |
| 1 | +import { describe, test, expect, expectTypeOf, beforeEach, vi } from "vitest" |
2 | 2 | import { registerEndpoint } from "@nuxt/test-utils/runtime" |
3 | 3 | import { setActivePinia } from "pinia" |
4 | 4 | import { createTestingPinia } from "@pinia/testing" |
5 | | -import Status from "../utils/status" |
| 5 | +import Status from "@/utils/status.js" |
| 6 | + |
| 7 | +// Mock navigator.locks API |
| 8 | +const mockLockRequest = vi.fn().mockImplementation(async (name, callback) => { |
| 9 | + return callback({ name }) |
| 10 | +}) |
| 11 | + |
| 12 | +vi.stubGlobal('navigator', { |
| 13 | + ...navigator, |
| 14 | + locks: { |
| 15 | + request: mockLockRequest |
| 16 | + } |
| 17 | +}) |
6 | 18 |
|
7 | 19 | describe("Infra Store", () => { |
| 20 | + // const locksMock = { |
| 21 | + // locks: { request: vi.fn() }, |
| 22 | + // } |
| 23 | + // global.navigator = locksMock // here |
| 24 | + |
8 | 25 | const pinia = createTestingPinia({ |
9 | 26 | stubActions: false, |
10 | 27 | }) |
@@ -62,6 +79,7 @@ describe("Infra Store", () => { |
62 | 79 | test("test geode false & viewer false", () => { |
63 | 80 | geode_store.$patch({ status: Status.NOT_CONNECTED }) |
64 | 81 | viewer_store.$patch({ status: Status.NOT_CONNECTED }) |
| 82 | + console.log("Status", Status) |
65 | 83 | expect(infra_store.microservices_connected).toBe(false) |
66 | 84 | }) |
67 | 85 | test("test geode true & viewer false", () => { |
@@ -106,27 +124,24 @@ describe("Infra Store", () => { |
106 | 124 | }) |
107 | 125 |
|
108 | 126 | describe("actions", () => { |
109 | | - describe("create_backend", () => { |
110 | | - test("test without end-point", async () => { |
111 | | - await infra_store.create_backend() |
112 | | - expect(infra_store.status).toBe(Status.NOT_CONNECTED) |
113 | | - expect(feedback_store.server_error).toBe(true) |
114 | | - }) |
115 | | - }) |
116 | 127 | describe("create_backend", () => { |
117 | 128 | test("test without end-point", async () => { |
118 | 129 | await infra_store.create_backend() |
119 | 130 | console.log("geode_store.status", geode_store.status) |
| 131 | + expect(infra_store.status).toBe(Status.CREATING) |
120 | 132 | expect(geode_store.status).toBe(Status.NOT_CONNECTED) |
121 | | - expect(feedback_store.server_error).toBe(true) |
| 133 | + expect(viewer_store.status).toBe(Status.NOT_CONNECTED) |
122 | 134 | }) |
123 | 135 | test("test with end-point", async () => { |
124 | 136 | registerEndpoint(infra_store.lambda_url, { |
125 | 137 | method: "POST", |
126 | 138 | handler: () => ({ ID: "123456" }), |
127 | 139 | }) |
128 | 140 | await infra_store.create_backend() |
129 | | - expect(geode_store.status).toBe(Status.CONNECTED) |
| 141 | + expect(infra_store.status).toBe(Status.CREATING) |
| 142 | + expect(geode_store.status).toBe(Status.NOT_CONNECTED) |
| 143 | + expect(viewer_store.status).toBe(Status.NOT_CONNECTED) |
| 144 | + expect(feedback_store.server_error).toBe(false) |
130 | 145 | }) |
131 | 146 | }) |
132 | 147 | }) |
|
0 commit comments