-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into update-js-packages
- Loading branch information
Showing
7 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { waitFor } from "@testing-library/dom"; | ||
import { http, HttpResponse } from "msw"; | ||
import { setupServer } from "msw/node"; | ||
|
||
import DataLoader from "../dataLoader"; | ||
|
||
const server = setupServer(); | ||
|
||
afterAll(() => { | ||
server.close(); | ||
}); | ||
|
||
afterEach(() => { | ||
server.resetHandlers(); | ||
}); | ||
|
||
beforeAll(() => { | ||
server.listen(); | ||
}); | ||
|
||
describe("loadFromUrl", () => { | ||
it("does nothing when urlInfo is empty", () => { | ||
const loadData = () => null; | ||
const treeElement = document.createElement("div"); | ||
const triggerEvent = jest.fn(); | ||
|
||
const dataLoader = new DataLoader({ | ||
loadData, | ||
treeElement, | ||
triggerEvent, | ||
}); | ||
|
||
dataLoader.loadFromUrl(null, null, null); | ||
expect(triggerEvent).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("parses json when the response is a string", async () => { | ||
server.use( | ||
http.get( | ||
"/test", | ||
() => | ||
new HttpResponse('{ "key1": "value1" }', { | ||
headers: { | ||
"Content-Type": "text/plain", | ||
}, | ||
}), | ||
{}, | ||
), | ||
); | ||
|
||
const loadData = jest.fn(); | ||
const treeElement = document.createElement("div"); | ||
const triggerEvent = jest.fn(); | ||
|
||
const dataLoader = new DataLoader({ | ||
loadData, | ||
treeElement, | ||
triggerEvent, | ||
}); | ||
dataLoader.loadFromUrl({ dataType: "text", url: "/test" }, null, null); | ||
|
||
await waitFor(() => { | ||
expect(loadData).toHaveBeenCalledWith({ key1: "value1" }, null); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import DragElement from "../../dragAndDropHandler/dragElement"; | ||
|
||
it("creates an element with autoEscape is true", () => { | ||
const treeElement = document.createElement("div"); | ||
|
||
new DragElement({ | ||
autoEscape: true, | ||
nodeName: "abc & def", | ||
offsetX: 0, | ||
offsetY: 0, | ||
treeElement, | ||
}); | ||
|
||
expect(treeElement.children.length).toBe(1); | ||
|
||
const childElement = treeElement.children[0]; | ||
expect(childElement).toHaveClass("jqtree-title"); | ||
expect(childElement).toHaveClass("jqtree-dragging"); | ||
expect(childElement).toHaveTextContent("abc & def"); | ||
}); | ||
|
||
it("creates an element with autoEscape is false", () => { | ||
const treeElement = document.createElement("div"); | ||
|
||
new DragElement({ | ||
autoEscape: false, | ||
nodeName: "abc & def", | ||
offsetX: 0, | ||
offsetY: 0, | ||
treeElement, | ||
}); | ||
|
||
expect(treeElement.children.length).toBe(1); | ||
|
||
const childElement = treeElement.children[0]; | ||
expect(childElement).toHaveTextContent("abc & def"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Node } from "../node"; | ||
import SelectNodeHandler from "../selectNodeHandler"; | ||
|
||
describe("getSelectedNodesUnder", () => { | ||
it("returns the nodes when the nodes have an id", () => { | ||
const node = new Node({ id: 1 }); | ||
|
||
const child = new Node({ id: 2 }); | ||
node.addChild(child); | ||
|
||
const nodeMap = new Map<NodeId, Node>(); | ||
nodeMap.set(1, node); | ||
nodeMap.set(2, child); | ||
|
||
const getNodeById = (id: NodeId) => nodeMap.get(id) ?? null; | ||
|
||
const selectNodeHandler = new SelectNodeHandler({ getNodeById }); | ||
selectNodeHandler.addToSelection(child); | ||
|
||
expect( | ||
selectNodeHandler.getSelectedNodesUnder(node), | ||
).toIncludeAllMembers([child]); | ||
}); | ||
}); |