Skip to content

Commit 1ad0cae

Browse files
MaxNumeriquegithub-actions[bot]
authored andcommitted
Apply prepare changes
1 parent 5334a81 commit 1ad0cae

File tree

1 file changed

+68
-22
lines changed

1 file changed

+68
-22
lines changed

tests/unit/composables/ProjectManager.nuxt.test.js

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ const snapshotMock = {
3030
abc123: {
3131
points: {
3232
visibility: true,
33-
coloring: { active: "color", color: { r: 255, g: 255, b: 255 }, vertex: null },
33+
coloring: {
34+
active: "color",
35+
color: { r: 255, g: 255, b: 255 },
36+
vertex: null,
37+
},
3438
size: 2,
3539
},
3640
},
@@ -48,10 +52,14 @@ const snapshotMock = {
4852
},
4953
}
5054

51-
const geodeStoreMock = { start_request: vi.fn(), stop_request: vi.fn(), base_url: "", $reset: vi.fn() }
52-
const infraStoreMock = { create_connection: vi.fn(() => Promise.resolve()) }
53-
const viewerStoreMock = { ws_connect: vi.fn(() => Promise.resolve())
55+
const geodeStoreMock = {
56+
start_request: vi.fn(),
57+
stop_request: vi.fn(),
58+
base_url: "",
59+
$reset: vi.fn(),
5460
}
61+
const infraStoreMock = { create_connection: vi.fn(() => Promise.resolve()) }
62+
const viewerStoreMock = { ws_connect: vi.fn(() => Promise.resolve()) }
5563
const treeviewStoreMock = {
5664
clear: vi.fn(),
5765
importStores: vi.fn(() => Promise.resolve()),
@@ -73,7 +81,8 @@ const hybridViewerStoreMock = {
7381
clear: vi.fn(),
7482
initHybridViewer: vi.fn(() => Promise.resolve()),
7583
importStores: vi.fn(async (snapshot) => {
76-
if (snapshot?.zScale != null) hybridViewerStoreMock.setZScaling(snapshot.zScale)
84+
if (snapshot?.zScale != null)
85+
hybridViewerStoreMock.setZScaling(snapshot.zScale)
7786
if (snapshot?.camera_options) {
7887
const { viewer_call } = await import("@/composables/viewer_call.js")
7988
viewer_call({
@@ -89,13 +98,20 @@ const hybridViewerStoreMock = {
8998
}
9099

91100
// Mocks
92-
vi.stubGlobal("$fetch", vi.fn(async () => ({ snapshot: snapshotMock })))
93-
vi.mock("@/composables/viewer_call.js", () => ({ viewer_call: vi.fn(() => Promise.resolve()) }))
101+
vi.stubGlobal(
102+
"$fetch",
103+
vi.fn(async () => ({ snapshot: snapshotMock })),
104+
)
105+
vi.mock("@/composables/viewer_call.js", () => ({
106+
viewer_call: vi.fn(() => Promise.resolve()),
107+
}))
94108
vi.mock("@/composables/api_fetch.js", () => ({
95109
api_fetch: vi.fn(async (_req, options = {}) => {
96110
const response = {
97111
_data: new Blob(["zipcontent"], { type: "application/zip" }),
98-
headers: { get: (k) => (k === "new-file-name" ? "project_123.zip" : null) },
112+
headers: {
113+
get: (k) => (k === "new-file-name" ? "project_123.zip" : null),
114+
},
99115
}
100116
if (options.response_function) await options.response_function(response)
101117
return response
@@ -104,16 +120,28 @@ vi.mock("@/composables/api_fetch.js", () => ({
104120
vi.mock("js-file-download", () => ({ default: vi.fn() }))
105121
vi.mock("@/stores/infra.js", () => ({ useInfraStore: () => infraStoreMock }))
106122
vi.mock("@/stores/viewer.js", () => ({ useViewerStore: () => viewerStoreMock }))
107-
vi.mock("@/stores/treeview.js", () => ({ useTreeviewStore: () => treeviewStoreMock }))
108-
vi.mock("@/stores/data_base.js", () => ({ useDataBaseStore: () => dataBaseStoreMock }))
109-
vi.mock("@/stores/data_style.js", () => ({ useDataStyleStore: () => dataStyleStoreMock }))
110-
vi.mock("@/stores/hybrid_viewer.js", () => ({ useHybridViewerStore: () => hybridViewerStoreMock }))
123+
vi.mock("@/stores/treeview.js", () => ({
124+
useTreeviewStore: () => treeviewStoreMock,
125+
}))
126+
vi.mock("@/stores/data_base.js", () => ({
127+
useDataBaseStore: () => dataBaseStoreMock,
128+
}))
129+
vi.mock("@/stores/data_style.js", () => ({
130+
useDataStyleStore: () => dataStyleStoreMock,
131+
}))
132+
vi.mock("@/stores/hybrid_viewer.js", () => ({
133+
useHybridViewerStore: () => hybridViewerStoreMock,
134+
}))
111135
vi.mock("@/stores/geode.js", () => ({ useGeodeStore: () => geodeStoreMock }))
112136
vi.mock("@/stores/app.js", () => ({
113-
useAppStore: () => ({ exportStores: vi.fn(() => ({ projectName: "mockedProject" })) }),
137+
useAppStore: () => ({
138+
exportStores: vi.fn(() => ({ projectName: "mockedProject" })),
139+
}),
114140
}))
115141

116-
vi.stubGlobal("useAppStore", () => ({ exportStores: vi.fn(() => ({ projectName: "mockedProject" })) }))
142+
vi.stubGlobal("useAppStore", () => ({
143+
exportStores: vi.fn(() => ({ projectName: "mockedProject" })),
144+
}))
117145

118146
describe("ProjectManager composable (compact)", () => {
119147
beforeEach(async () => {
@@ -129,7 +157,9 @@ describe("ProjectManager composable (compact)", () => {
129157
dataStyleStoreMock,
130158
hybridViewerStoreMock,
131159
]) {
132-
Object.values(store).forEach((v) => typeof v === "function" && v.mockClear && v.mockClear())
160+
Object.values(store).forEach(
161+
(v) => typeof v === "function" && v.mockClear && v.mockClear(),
162+
)
133163
}
134164
const { viewer_call } = await import("@/composables/viewer_call.js")
135165
viewer_call.mockClear()
@@ -147,7 +177,9 @@ describe("ProjectManager composable (compact)", () => {
147177

148178
test("importProjectFile with snapshot", async () => {
149179
const { importProjectFile } = useProjectManager()
150-
const file = new Blob(['{"dataBase":{"db":{}}}'], { type: "application/json" })
180+
const file = new Blob(['{"dataBase":{"db":{}}}'], {
181+
type: "application/json",
182+
})
151183

152184
await importProjectFile(file)
153185

@@ -157,12 +189,18 @@ describe("ProjectManager composable (compact)", () => {
157189
expect(viewerStoreMock.ws_connect).toHaveBeenCalled()
158190
expect(viewer_call).toHaveBeenCalledTimes(4)
159191

160-
expect(treeviewStoreMock.importStores).toHaveBeenCalledWith(snapshotMock.treeview)
192+
expect(treeviewStoreMock.importStores).toHaveBeenCalledWith(
193+
snapshotMock.treeview,
194+
)
161195
expect(hybridViewerStoreMock.initHybridViewer).toHaveBeenCalled()
162-
expect(hybridViewerStoreMock.importStores).toHaveBeenCalledWith(snapshotMock.hybridViewer)
196+
expect(hybridViewerStoreMock.importStores).toHaveBeenCalledWith(
197+
snapshotMock.hybridViewer,
198+
)
163199
expect(hybridViewerStoreMock.setZScaling).toHaveBeenCalledWith(1.5)
164200

165-
expect(dataStyleStoreMock.importStores).toHaveBeenCalledWith(snapshotMock.dataStyle)
201+
expect(dataStyleStoreMock.importStores).toHaveBeenCalledWith(
202+
snapshotMock.dataStyle,
203+
)
166204
expect(dataStyleStoreMock.applyAllStylesFromState).toHaveBeenCalled()
167205

168206
expect(dataBaseStoreMock.registerObject).toHaveBeenCalledWith("abc123")
@@ -174,11 +212,19 @@ describe("ProjectManager composable (compact)", () => {
174212
displayed_name: "My Data",
175213
}),
176214
)
177-
expect(treeviewStoreMock.addItem).toHaveBeenCalledWith("PointSet2D", "My Data", "abc123", "mesh")
215+
expect(treeviewStoreMock.addItem).toHaveBeenCalledWith(
216+
"PointSet2D",
217+
"My Data",
218+
"abc123",
219+
"mesh",
220+
)
178221
expect(hybridViewerStoreMock.addItem).toHaveBeenCalledWith("abc123")
179-
expect(dataStyleStoreMock.addDataStyle).toHaveBeenCalledWith("abc123", "PointSet2D")
222+
expect(dataStyleStoreMock.addDataStyle).toHaveBeenCalledWith(
223+
"abc123",
224+
"PointSet2D",
225+
)
180226
expect(dataStyleStoreMock.applyDefaultStyle).toHaveBeenCalledWith("abc123")
181227

182228
expect(hybridViewerStoreMock.remoteRender).toHaveBeenCalled()
183229
})
184-
})
230+
})

0 commit comments

Comments
 (0)