Skip to content

Commit d65b3ac

Browse files
committed
[fix] Qa
1 parent eca31fd commit d65b3ac

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/js/netjsongraph.util.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,15 +1244,15 @@ class NetJSONGraphUtil {
12441244
// We store the selected node's data to the browser's history state.
12451245
// This allows the node's information to be retrieved instantly on a back/forward
12461246
// button click without needing to re-parse the entire nodes list.
1247-
history.pushState(state, "", `#${newHash}`);
1247+
window.history.pushState(state, "", `#${newHash}`);
12481248
}
12491249

12501250
addActionToUrl(self, params) {
12511251
if (!self.config.bookmarkableActions.enabled || params.data.cluster) {
12521252
return;
12531253
}
12541254
const fragments = this.parseUrlFragments();
1255-
const id = self.config.bookmarkableActions.id;
1255+
const {id} = self.config.bookmarkableActions;
12561256
let nodeId;
12571257
self.indexedNode = self.indexedNode || {};
12581258
if (self.config.render === self.utils.graphRender) {
@@ -1285,8 +1285,10 @@ class NetJSONGraphUtil {
12851285
if (!self.config.bookmarkableActions.enabled || !Object.keys(fragments).length) {
12861286
return;
12871287
}
1288-
const id = self.config.bookmarkableActions.id;
1289-
const nodeId = fragments[id]?.get("nodeId");
1288+
const {id} = self.config.bookmarkableActions;
1289+
const fragmentParams = fragments[id] && fragments[id].get ? fragments[id] : null;
1290+
const nodeId =
1291+
fragmentParams && fragmentParams.get ? fragmentParams.get("nodeId") : undefined;
12901292
if (nodeId === node.id) {
12911293
self.indexedNode = self.indexedNode || {};
12921294
self.indexedNode[nodeId] = node;
@@ -1297,9 +1299,11 @@ class NetJSONGraphUtil {
12971299
if (!self.config.bookmarkableActions.enabled) {
12981300
return;
12991301
}
1300-
const id = self.config.bookmarkableActions.id;
1302+
const {id} = self.config.bookmarkableActions;
13011303
const fragments = self.utils.parseUrlFragments();
1302-
const nodeId = fragments[id]?.get("nodeId");
1304+
const fragmentParams = fragments[id] && fragments[id].get ? fragments[id] : null;
1305+
const nodeId =
1306+
fragmentParams && fragmentParams.get ? fragmentParams.get("nodeId") : undefined;
13031307
if (!self.indexedNode || !self.indexedNode[nodeId]) {
13041308
return;
13051309
}

test/netjsongraph.util.test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe("Test URL fragment utilities", () => {
216216
config: {
217217
bookmarkableActions: {enabled: true, id: "geoMap"},
218218
},
219-
utils: utils,
219+
utils,
220220
};
221221
const params = {
222222
componentSubType: "effectScatter",
@@ -239,10 +239,10 @@ describe("Test URL fragment utilities", () => {
239239
bookmarkableActions: {enabled: true, id: "geo"},
240240
},
241241
indexedNode: undefined,
242-
utils: utils,
242+
utils,
243243
};
244244
const params = {
245-
data:{node: {id: "node-2"}},
245+
data: {node: {id: "node-2"}},
246246
};
247247

248248
utils.addActionToUrl(self, params);
@@ -314,13 +314,19 @@ describe("Test URL fragment utilities", () => {
314314
},
315315
emit(event) {
316316
const h = this.handlers[event];
317-
if (h) h();
317+
if (h) {
318+
h();
319+
}
318320
},
319321
};
322+
const delay = (ms) =>
323+
new Promise((resolve) => {
324+
setTimeout(resolve, ms);
325+
});
320326

321327
const asyncOnReady = async () => {
322328
recorder.push("onReady-start");
323-
await new Promise((r) => setTimeout(r, 20));
329+
await delay(20);
324330
recorder.push("onReady-done");
325331
};
326332

@@ -337,7 +343,7 @@ describe("Test URL fragment utilities", () => {
337343
});
338344
emitter.emit("onReady");
339345
emitter.emit("applyUrlFragmentState");
340-
await new Promise((r) => setTimeout(r, 40));
346+
await delay(40);
341347
expect(recorder).toEqual([
342348
"onReady-start",
343349
"onReady-done",

0 commit comments

Comments
 (0)