Skip to content

Commit 5a97467

Browse files
wip unit tests
1 parent ee92d5a commit 5a97467

16 files changed

+199
-196
lines changed

components/Launcher.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@
1111
<h4 class="pb-3">Please complete the recaptcha to launch the app</h4>
1212
<Recaptcha :site_key="site_key" />
1313
</v-col>
14-
<v-col v-else-if="!is_running && is_connexion_launched">
14+
<v-col v-else-if="infra_store.status == Status.CREATING">
1515
<Loading />
1616
</v-col>
1717
</v-row>
1818
</v-container>
1919
</template>
2020

2121
<script setup>
22+
import Status from "../utils/status"
23+
2224
const viewer_store = use_viewer_store()
2325
const infra_store = use_infra_store()
24-
const { is_captcha_validated, is_connexion_launched, is_running } =
25-
storeToRefs(infra_store)
26+
const { is_captcha_validated } = storeToRefs(infra_store)
2627
2728
const site_key = useRuntimeConfig().public.RECAPTCHA_SITE_KEY
2829
2930
watch(is_captcha_validated, async (value) => {
3031
if (value === true && process.client) {
31-
await infra_store.create_connexion()
32+
await infra_store.create_backend()
3233
await viewer_store.connect()
3334
}
3435
})

components/PackagesVersions.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
<script setup>
2222
const infra_store = use_infra_store()
23-
const { is_running } = storeToRefs(infra_store)
2423
2524
const props = defineProps({
2625
schema: { type: Object, required: true },
@@ -53,7 +52,7 @@
5352
await Promise.all(array_promise)
5453
}
5554
56-
watch(is_running, () => {
55+
watch(infra_store.status, () => {
5756
get_packages_versions()
5857
})
5958

components/Wrapper.vue

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<template>
22
<v-container>
33
<v-row class="flex-column">
4-
<v-col v-if="!is_running">
5-
<Launcher />
6-
</v-col>
7-
<v-col v-if="is_running">
8-
<Stepper />
9-
</v-col>
10-
<v-col v-if="is_running">
11-
<PackagesVersions :schema="versions_schema" />
12-
</v-col>
4+
<template v-if="!infra_store.microservices_connected">
5+
<v-col>
6+
<Launcher />
7+
</v-col>
8+
</template>
9+
<template v-else>
10+
<v-col>
11+
<Stepper />
12+
</v-col>
13+
<v-col> <PackagesVersions :schema="versions_schema" /> </v-col>
14+
</template>
1315
</v-row>
1416
</v-container>
1517
</template>
1618

1719
<script setup>
1820
const infra_store = use_infra_store()
19-
const { is_running } = storeToRefs(infra_store)
2021
2122
const props = defineProps({
2223
versions_schema: { type: Object, required: true },
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function run_function_when_microservices_connected(function_to_run) {
2+
const infra_store = use_infra_store()
3+
const { status } = storeToRefs(infra_store)
4+
if (status === Status.CREATED) {
5+
function_to_run()
6+
} else {
7+
watch(status, (value) => {
8+
if (value === Status.CREATED) {
9+
function_to_run()
10+
}
11+
})
12+
}
13+
}
14+
15+
export default run_function_when_microservices_connected

composables/run_function_when_infra_running.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

nuxt.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineNuxtConfig({
3939
"ajv",
4040
"fast-deep-equal",
4141
"globalthis",
42+
"h3",
4243
"is-electron",
4344
"js-file-download",
4445
"lodash",

stores/geode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import back_schemas from "@geode/opengeodeweb-back/schemas.json"
2-
import Status from "../utils/status"
2+
import Status from "@/utils/status"
33

44
export const use_geode_store = defineStore("geode", {
55
state: () => ({

stores/infra.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -47,49 +47,44 @@ export const use_infra_store = defineStore("infra", {
4747
},
4848
actions: {
4949
async create_backend() {
50-
if (this.status in [Status.CREATING, Status.CREATED]) {
51-
return
52-
}
53-
navigator.locks.request(
54-
"infra.create_backend",
55-
{ mode: "shared" },
56-
async (lock) => {
57-
this.status = Status.CREATING
58-
console.log("LOCK", lock)
59-
if (lock) {
60-
console.log("LOCKED")
61-
this.status = Status.CREATING
62-
const geode_store = use_geode_store()
63-
const viewer_store = use_viewer_store()
64-
const feedback_store = use_feedback_store()
65-
if (isElectron()) {
66-
const back_port = await window.electronAPI.run_back(
67-
geode_store.port,
68-
)
69-
geode_store.$patch({ default_local_port: back_port })
70-
const viewer_port = await window.electronAPI.run_viewer(
71-
viewer_store.port,
72-
)
73-
viewer_store.$patch({ default_local_port: viewer_port })
74-
} else {
75-
const { data, error } = await useFetch(this.lambda_url, {
76-
method: "POST",
77-
})
78-
if (data.value !== null) {
79-
this.ID = data.value.ID
80-
localStorage.setItem("ID", data.value.ID)
81-
} else {
82-
feedback_store.server_error = true
83-
return
84-
}
85-
}
86-
this.status = Status.CREATED
87-
geode_store.ping_task()
88-
viewer_store.connect()
50+
console.log("create_backend", this.status)
51+
if (this.status === Status.CREATED) return
52+
navigator.locks.request("infra.create_backend", async (lock) => {
53+
console.log("create_backend lock", this.status)
54+
if (this.status === Status.CREATED) return
55+
console.log("INFRA LOCK GRANTED !", lock)
56+
console.log("INFRA STATUS", this.status)
57+
this.status = Status.CREATING
58+
const geode_store = use_geode_store()
59+
const viewer_store = use_viewer_store()
60+
const feedback_store = use_feedback_store()
61+
if (isElectron()) {
62+
const back_port = await window.electronAPI.run_back(geode_store.port)
63+
geode_store.$patch({ default_local_port: back_port })
64+
const viewer_port = await window.electronAPI.run_viewer(
65+
viewer_store.port,
66+
)
67+
viewer_store.$patch({ default_local_port: viewer_port })
68+
} else {
69+
const { data, error } = await useFetch(this.lambda_url, {
70+
method: "POST",
71+
})
72+
if (data.value !== null) {
73+
this.ID = data.value.ID
74+
localStorage.setItem("ID", data.value.ID)
75+
} else {
76+
feedback_store.server_error = true
8977
return
9078
}
91-
},
92-
)
79+
}
80+
this.status = Status.CREATED
81+
return this.create_connection()
82+
})
83+
},
84+
async create_connection() {
85+
await use_viewer_store().ws_connect()
86+
await use_geode_store().do_ping()
87+
return
9388
},
9489
},
9590
})

stores/viewer.js

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -56,79 +56,81 @@ export const use_viewer_store = defineStore("viewer", {
5656
this.picked_point.y = world_y
5757
this.picking_mode = false
5858
},
59-
async connect() {
60-
if (process.env.NODE_ENV == "test") {
61-
return
62-
}
63-
navigator.locks.request("viewer.connect", async (lock) => {
59+
async ws_connect() {
60+
if (process.env.NODE_ENV == "test") return
61+
console.log("ws_connect 1", this.status)
62+
if (this.status === Status.CONNECTED) return
63+
console.log("ws_connect 2", this.status)
64+
65+
navigator.locks.request("viewer.ws_connect", async (lock) => {
66+
console.log("VIEWER STATUS", this.status)
67+
if (this.status === Status.CONNECTED) return
68+
console.log("VIEWER LOCK GRANTED !", lock)
6469
this.status = Status.CONNECTING
65-
if (lock) {
66-
this.status = Status.CONNECTING
67-
const SmartConnect = await import("wslink/src/SmartConnect")
68-
vtkWSLinkClient.setSmartConnectClass(SmartConnect)
70+
const SmartConnect = await import("wslink/src/SmartConnect")
71+
vtkWSLinkClient.setSmartConnectClass(SmartConnect)
6972

70-
const config = { application: "Viewer" }
71-
config.sessionURL = this.base_url
73+
const config = { application: "Viewer" }
74+
config.sessionURL = this.base_url
7275

73-
const { client } = this
74-
if (this.is_running && client.isConnected()) {
75-
client.disconnect(-1)
76-
this.is_running = false
77-
}
78-
let clientToConnect = client
79-
if (_.isEmpty(clientToConnect)) {
80-
clientToConnect = vtkWSLinkClient.newInstance()
81-
}
76+
const { client } = this
77+
console.log("client", client)
78+
if (this.status === Status.CONNECTED && client.isConnected()) {
79+
client.disconnect(-1)
80+
this.status = Status.NOT_CONNECTED
81+
}
82+
let clientToConnect = client
83+
if (_.isEmpty(clientToConnect)) {
84+
clientToConnect = vtkWSLinkClient.newInstance()
85+
}
8286

83-
// Connect to busy store
84-
clientToConnect.onBusyChange((count) => {
85-
this.buzy = count
86-
})
87-
clientToConnect.beginBusy()
87+
// Connect to busy store
88+
clientToConnect.onBusyChange((count) => {
89+
this.buzy = count
90+
})
91+
clientToConnect.beginBusy()
8892

89-
// Error
90-
clientToConnect.onConnectionError((httpReq) => {
91-
const message =
92-
(httpReq && httpReq.response && httpReq.response.error) ||
93-
`Connection error`
94-
console.error(message)
95-
})
93+
// Error
94+
clientToConnect.onConnectionError((httpReq) => {
95+
const message =
96+
(httpReq && httpReq.response && httpReq.response.error) ||
97+
`Connection error`
98+
console.error(message)
99+
})
96100

97-
// Close
98-
clientToConnect.onConnectionClose((httpReq) => {
99-
const message =
100-
(httpReq && httpReq.response && httpReq.response.error) ||
101-
`Connection close`
102-
console.error(message)
103-
})
101+
// Close
102+
clientToConnect.onConnectionClose((httpReq) => {
103+
const message =
104+
(httpReq && httpReq.response && httpReq.response.error) ||
105+
`Connection close`
106+
console.error(message)
107+
})
104108

105-
// Connect
106-
const { connectImageStream } = await import(
107-
"@kitware/vtk.js/Rendering/Misc/RemoteView"
108-
)
109-
return new Promise((resolve, reject) => {
110-
clientToConnect
111-
.connect(config)
112-
.then((validClient) => {
113-
connectImageStream(validClient.getConnection().getSession())
114-
this.client = validClient
115-
clientToConnect.endBusy()
109+
// Connect
110+
const { connectImageStream } = await import(
111+
"@kitware/vtk.js/Rendering/Misc/RemoteView"
112+
)
113+
return new Promise((resolve, reject) => {
114+
clientToConnect
115+
.connect(config)
116+
.then((validClient) => {
117+
connectImageStream(validClient.getConnection().getSession())
118+
this.client = validClient
119+
clientToConnect.endBusy()
116120

117-
// Now that the client is ready let's setup the server for us
118-
viewer_call({
119-
schema:
120-
schemas.opengeodeweb_viewer.viewer.reset_visualization,
121-
})
122-
this.status = Status.CONNECTED
123-
resolve()
124-
})
125-
.catch((error) => {
126-
console.error(error)
127-
this.status = Status.NOT_CONNECTED
128-
reject(error)
121+
// Now that the client is ready let's setup the server for us
122+
viewer_call({
123+
schema: schemas.opengeodeweb_viewer.viewer.reset_visualization,
129124
})
130-
})
131-
}
125+
this.status = Status.CONNECTED
126+
resolve()
127+
})
128+
.catch((error) => {
129+
console.error(error)
130+
this.status = Status.NOT_CONNECTED
131+
reject(error)
132+
})
133+
})
132134
})
133135
},
134136
start_request() {

test/components/Launcher.nuxt.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
// describe("Launcher.vue", async () => {
2323
// test(`Mount`, async () => {
24-
// const spy_infra_store = vi.spyOn(infra_store, "create_connexion")
24+
// const spy_infra_store = vi.spyOn(infra_store, "create_backend")
2525
// const wrapper = await mountSuspended(Launcher, {
2626
// global: {
2727
// plugins: [vuetify],

0 commit comments

Comments
 (0)