1- // Global imports
21import path from "path"
32
4- // Third party imports
53import { setActivePinia } from "pinia"
64import { createTestingPinia } from "@pinia/testing"
7-
85import {
6+ afterAll ,
97 afterEach ,
8+ beforeAll ,
109 beforeEach ,
1110 describe ,
1211 expect ,
13- expectTypeOf ,
1412 test ,
1513 vi ,
1614} from "vitest"
1715
18- // Local imports
1916import {
2017 executable_name ,
2118 executable_path ,
2219 kill_processes ,
2320 run_viewer ,
2421} from "@ogw_f/utils/local"
22+
23+ // import viewer_call from "@ogw_f/composables/viewer_call"
2524import { useDataStyleStore } from "@ogw_f/stores/data_style"
25+ import { useDataBaseStore } from "@ogw_f/stores/data_base"
26+ import { useViewerStore } from "@ogw_f/stores/viewer"
27+ import { useInfraStore } from "@ogw_f/stores/infra"
28+
29+ import viewer_call from "@ogw_f/composables/viewer_call"
2630
27- describe ( "DataStyle Store" , ( ) => {
31+ import { WebSocket } from "ws"
32+
33+ const mockLockRequest = vi . fn ( ) . mockImplementation ( async ( name , callback ) => {
34+ return callback ( { name } )
35+ } )
36+
37+ vi . stubGlobal ( "navigator" , {
38+ ...navigator ,
39+ locks : {
40+ request : mockLockRequest ,
41+ } ,
42+ } )
43+
44+ beforeAll ( ( ) => {
45+ global . WebSocket = WebSocket
46+ } )
47+
48+ afterAll ( ( ) => {
49+ delete global . WebSocket
50+ } )
51+
52+ const id = "fake_id"
53+ const file_name = "edged_curve.vtp"
54+ const geode_object = "EdgedCurve2D"
55+ const object_type = "mesh"
56+
57+ describe ( "Mesh edges" , ( ) => {
2858 const pinia = createTestingPinia ( {
2959 stubActions : false ,
3060 createSpy : vi . fn ,
3161 } )
3262
3363 const dataStyleStore = useDataStyleStore ( )
64+ const dataBaseStore = useDataBaseStore ( )
65+ const viewerStore = useViewerStore ( )
66+ const infraStore = useInfraStore ( )
67+ infraStore . app_mode = appMode . appMode . BROWSER
3468 beforeEach ( async ( ) => {
3569 setActivePinia ( pinia )
3670 console . log ( "__dirname" , __dirname )
@@ -40,16 +74,55 @@ describe("DataStyle Store", () => {
4074 ) ,
4175 executable_name ( "opengeodeweb_viewer" ) ,
4276 )
43- await run_viewer ( viewer_path , { port : 1234 , data_folder_path : "./data" } )
77+ const viewer_port = await run_viewer ( viewer_path , {
78+ port : 1234 ,
79+ data_folder_path : path . join ( __dirname , ".." , ".." , ".." , "data" ) ,
80+ } )
81+
82+ viewerStore . default_local_port = viewer_port
83+ await viewerStore . ws_connect ( )
84+ await dataBaseStore . registerObject ( id , file_name , object_type )
85+ await dataStyleStore . addDataStyle ( id , geode_object , object_type )
86+ expect ( viewerStore . status ) . toBe ( "CONNECTED" )
4487 } )
4588
4689 afterEach ( ( ) => {
4790 kill_processes ( )
4891 } )
4992
50- describe ( "state" , ( ) => {
51- test ( "initial state" , ( ) => {
52- expectTypeOf ( true ) . toBeBoolean ( )
93+ // describe("Edges visibility", () => {
94+ // test("test visibility true", async () => {
95+ // // dataStyleStore.addDataStyle(id, geode_object, object_type)
96+ // await dataStyleStore.setEdgesVisibility(id, true)
97+ // expect(dataStyleStore.edgesVisibility(id)).toBe(true)
98+ // })
99+ // })
100+
101+ // describe("Edges active coloring", () => {
102+ // test("test color", async () => {
103+ // const id = "fake_id"
104+ // const geodeObject = "EdgedCurve2D"
105+ // const object_type = "mesh"
106+
107+ // const coloringTypes = ["color"]
108+ // for (let i = 0; i < coloringTypes.length; i++) {
109+ // dataStyleStore.addDataStyle(id, geodeObject, object_type)
110+ // dataStyleStore.setEdgesActiveColoring(id, coloringTypes[i])
111+ // expect(dataStyleStore.edgesActiveColoring(id)).toBe(coloringTypes[i])
112+ // }
113+ // })
114+ // })
115+ describe ( "Edges color" , ( ) => {
116+ test ( "test red" , async ( ) => {
117+ const color = { r : 255 , g : 0 , b : 0 }
118+ // const spy = vi.spyOn(viewer_call, "viewer_call")
119+ await dataStyleStore . setEdgesColor ( id , color )
120+ // expect(spy).toHaveBeenCalledWith({
121+ // schema: mesh_edges_schemas.color,
122+ // params: { id, color },
123+ // })
124+ expect ( dataStyleStore . edgesColor ( id ) ) . toStrictEqual ( color )
125+ expect ( viewerStore . status ) . toBe ( status . CONNECTED )
53126 } )
54127 } )
55128} )
0 commit comments