Skip to content

Commit daf7dbb

Browse files
committed
test(dnd): add tests
1 parent 15e6aea commit daf7dbb

24 files changed

Lines changed: 2736 additions & 1124 deletions

package-lock.json

Lines changed: 1329 additions & 684 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,35 @@
1717
"@codemirror/language": "6.9.1",
1818
"@commitlint/cli": "17.4.0",
1919
"@commitlint/config-conventional": "17.4.0",
20-
"@popperjs/core": "2.11.8",
2120
"@tsconfig/svelte": "5.0.2",
2221
"@types/electron": "1.6.10",
23-
"@types/node": "16.11.6",
22+
"@types/node": "20.11.24",
2423
"@types/uniqid": "5.3.4",
25-
"@typescript-eslint/eslint-plugin": "7.0.2",
26-
"@typescript-eslint/parser": "7.0.2",
24+
"@typescript-eslint/eslint-plugin": "7.1.0",
25+
"@typescript-eslint/parser": "7.1.0",
2726
"builtin-modules": "3.3.0",
28-
"classnames": "^2.5.1",
29-
"esbuild": "0.17.3",
27+
"classnames": "2.5.1",
28+
"esbuild": "0.20.1",
3029
"esbuild-plugin-inline-worker": "0.1.1",
3130
"esbuild-svelte": "0.8.0",
32-
"eslint": "8.56.0",
31+
"eslint": "8.57.0",
3332
"eslint-plugin-svelte": "2.35.1",
3433
"husky": "8.0.3",
35-
"lint-staged": "13.1.0",
36-
"lucide-svelte": "0.292.0",
34+
"lint-staged": "13.3.0",
35+
"lucide-svelte": "0.344.0",
3736
"monkey-around": "3.0.0",
37+
"nanoid": "5.0.6",
3838
"obsidian": "latest",
39-
"prettier": "3.0.3",
40-
"prettier-plugin-svelte": "3.1.2",
41-
"svelte": "4.2.1",
39+
"prettier": "3.2.5",
40+
"prettier-plugin-svelte": "3.2.2",
41+
"svelte": "4.2.12",
4242
"svelte-eslint-parser": "0.33.1",
43-
"svelte-preprocess": "5.0.4",
44-
"tslib": "2.4.0",
43+
"svelte-preprocess": "5.1.3",
44+
"tslib": "2.6.2",
4545
"typescript": "5.3.3",
46-
"vitest": "0.34.5",
47-
"nanoid": "5.0.6"
46+
"vitest": "1.3.1"
47+
},
48+
"dependencies": {
49+
"jsdom": "^24.0.0"
4850
}
49-
5051
}

src/stores/document/default-document-state.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ export const defaultDocumentState = (): ViewState => ({
88
activeBranch: {
99
node: '',
1010
group: '',
11-
childNodes: new Set<string>(),
1211
childGroups: new Set<string>(),
13-
parentNodes: new Set<string>(),
14-
siblingNodes: new Set<string>(),
1512
sortedParentNodes: [],
1613
},
1714
dnd: {

src/stores/document/document-type.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ export type DNDState = {
2121
node: string;
2222
};
2323
export type ActiveBranch = {
24-
parentNodes: Set<string>;
25-
childNodes: Set<string>;
2624
childGroups: Set<string>;
27-
siblingNodes: Set<string>;
2825
node: string;
2926
sortedParentNodes: NodeId[];
3027
group: string;

src/stores/document/effects/align-branch-effect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const alignBranch = (
1717
};
1818
if (nodeId) {
1919
alignElement(container, nodeId, behavior, localState, 'both');
20-
for (const id of state.document.state.activeBranch.parentNodes) {
20+
for (const id of state.document.state.activeBranch.sortedParentNodes) {
2121
alignElement(container, id, behavior, localState);
2222
}
2323
for (const id of state.document.state.activeBranch.childGroups) {

src/stores/document/effects/save-document-effect.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const saveDocumentEffect = (
1313
action.type === 'DROP_NODE' ||
1414
action.type === 'APPLY_SNAPSHOT' ||
1515
action.type === 'TREE/DELETE_NODE' ||
16-
action.type === 'MERGE_NODE'
16+
action.type === 'MERGE_NODE' ||
17+
action.type === 'MOVE_NODE'
1718
) {
1819
await save(action.type);
1920
}

src/stores/document/helpers/search/find-siblings.ts

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

src/stores/document/helpers/search/traverse-down.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Columns, NodeId } from 'src/stores/document/document-type';
33
export type StringSet = Set<string>;
44
export const traverseDown = (
55
childGroups: NodeId[],
6-
childNodes: StringSet,
76
columns: Columns,
87
nodeId: NodeId,
98
columnIndex = 0,
@@ -14,10 +13,8 @@ export const traverseDown = (
1413
if (group.parentId === nodeId) {
1514
if (!nodeId.startsWith('-r')) childGroups.push(nodeId);
1615
for (const childNodeId of group.nodes) {
17-
childNodes.add(childNodeId);
1816
traverseDown(
1917
childGroups,
20-
childNodes,
2118
columns,
2219
childNodeId,
2320
columnIndex + 1,

src/stores/document/reducers/state/on-drag-start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const onDragStart = (
1515
const node = action.payload.nodeId;
1616
if (node) {
1717
const childGroups: NodeId[] = [];
18-
traverseDown(childGroups, new Set<string>(), columns, node);
18+
traverseDown(childGroups, columns, node);
1919
state.node = action.payload.nodeId;
2020
state.childGroups = new Set(childGroups);
2121
}

src/stores/document/reducers/state/shared/update-active-node.spec.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ describe('update-active-node', () => {
7575
],
7676
state: {
7777
activeBranch: {
78-
parentNodes: new Set([]),
7978
childGroups: new Set([]),
80-
childNodes: new Set([]),
81-
siblingNodes: new Set([]),
8279
sortedParentNodes: [],
8380
node: activeNodeId,
8481
group: 'r-lt8upk0k',
@@ -149,24 +146,7 @@ describe('update-active-node', () => {
149146
],
150147
state: {
151148
activeBranch: {
152-
parentNodes: new Set([]),
153149
childGroups: new Set([activeNodeId, child4]),
154-
childNodes: new Set([
155-
child1,
156-
child2,
157-
child3,
158-
child4,
159-
child4_1,
160-
]),
161-
siblingNodes: new Set([
162-
'n-lt8upk0u',
163-
'n-lt8upk0v',
164-
'n-lt8upk0z',
165-
'n-lt8upk10',
166-
'n-lt8upk11',
167-
'n-lt8upk12',
168-
'n-lt8upk13',
169-
]),
170150
sortedParentNodes: [],
171151
node: activeNodeId,
172152
group: 'r-lt8upk0k',

0 commit comments

Comments
 (0)