@powerhousedao/vetra 5.1.0-dev.4 → 5.1.0-dev.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document-models/app-module/gen/document-schema.d.ts +24 -170
- package/dist/document-models/app-module/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/app-module/gen/schema/types.d.ts +15 -3
- package/dist/document-models/app-module/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/app-module/gen/schema/zod.d.ts +7 -4
- package/dist/document-models/app-module/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/app-module/gen/schema/zod.js +2 -2
- package/dist/document-models/app-module/hooks.d.ts +5 -2
- package/dist/document-models/app-module/hooks.d.ts.map +1 -1
- package/dist/document-models/app-module/hooks.js +3 -4
- package/dist/document-models/app-module/src/tests/base-operations.test.js +52 -1
- package/dist/document-models/document-editor/gen/document-schema.d.ts +21 -151
- package/dist/document-models/document-editor/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/document-editor/gen/schema/types.d.ts +15 -3
- package/dist/document-models/document-editor/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/document-editor/gen/schema/zod.d.ts +7 -4
- package/dist/document-models/document-editor/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/document-editor/gen/schema/zod.js +2 -2
- package/dist/document-models/document-editor/hooks.d.ts +5 -2
- package/dist/document-models/document-editor/hooks.d.ts.map +1 -1
- package/dist/document-models/document-editor/hooks.js +3 -4
- package/dist/document-models/document-editor/src/tests/base-operations.test.js +42 -1
- package/dist/document-models/processor-module/gen/document-schema.d.ts +24 -170
- package/dist/document-models/processor-module/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/schema/types.d.ts +15 -3
- package/dist/document-models/processor-module/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/schema/zod.d.ts +7 -4
- package/dist/document-models/processor-module/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/processor-module/gen/schema/zod.js +2 -2
- package/dist/document-models/processor-module/hooks.d.ts +5 -2
- package/dist/document-models/processor-module/hooks.d.ts.map +1 -1
- package/dist/document-models/processor-module/hooks.js +3 -4
- package/dist/document-models/processor-module/src/tests/base-operations.test.js +52 -1
- package/dist/document-models/subgraph-module/gen/document-schema.d.ts +18 -132
- package/dist/document-models/subgraph-module/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/gen/schema/types.d.ts +15 -3
- package/dist/document-models/subgraph-module/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/gen/schema/zod.d.ts +7 -4
- package/dist/document-models/subgraph-module/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/gen/schema/zod.js +1 -1
- package/dist/document-models/subgraph-module/hooks.d.ts +5 -2
- package/dist/document-models/subgraph-module/hooks.d.ts.map +1 -1
- package/dist/document-models/subgraph-module/hooks.js +3 -4
- package/dist/document-models/subgraph-module/src/tests/base-operations.test.js +22 -1
- package/dist/document-models/vetra-package/gen/document-schema.d.ts +33 -227
- package/dist/document-models/vetra-package/gen/document-schema.d.ts.map +1 -1
- package/dist/document-models/vetra-package/gen/schema/types.d.ts +17 -1
- package/dist/document-models/vetra-package/gen/schema/types.d.ts.map +1 -1
- package/dist/document-models/vetra-package/gen/schema/zod.d.ts +3 -3
- package/dist/document-models/vetra-package/gen/schema/zod.d.ts.map +1 -1
- package/dist/document-models/vetra-package/gen/schema/zod.js +10 -10
- package/dist/document-models/vetra-package/hooks.d.ts +5 -2
- package/dist/document-models/vetra-package/hooks.d.ts.map +1 -1
- package/dist/document-models/vetra-package/hooks.js +3 -4
- package/dist/document-models/vetra-package/src/tests/base-operations.test.js +127 -28
- package/dist/editors/app-editor/components/AppEditorForm.js +1 -1
- package/dist/editors/app-editor/editor.test.js +3 -2
- package/dist/editors/document-editor/components/DocumentEditorForm.d.ts.map +1 -1
- package/dist/editors/document-editor/components/DocumentEditorForm.js +32 -26
- package/dist/editors/document-editor/editor.js +1 -1
- package/dist/editors/document-editor/editor.test.js +2 -2
- package/dist/processors/codegen/__tests__/codegen-processor-e2e.test.js +98 -47
- package/dist/processors/codegen/document-handlers/generators/app-generator.js +2 -2
- package/dist/processors/codegen/document-handlers/generators/constants.d.ts +2 -1
- package/dist/processors/codegen/document-handlers/generators/constants.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/constants.js +2 -1
- package/dist/processors/codegen/document-handlers/generators/document-editor-generator.js +2 -2
- package/dist/processors/codegen/document-handlers/generators/document-model-generator.d.ts.map +1 -1
- package/dist/processors/codegen/document-handlers/generators/document-model-generator.js +8 -5
- package/dist/processors/codegen/factory.d.ts.map +1 -1
- package/dist/processors/codegen/factory.js +3 -0
- package/dist/processors/codegen/index.js +1 -1
- package/dist/setupTests.js +1 -0
- package/dist/subgraphs/app-module/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/app-module/resolvers.js +4 -4
- package/dist/subgraphs/app-module/schema.d.ts.map +1 -1
- package/dist/subgraphs/app-module/schema.js +2 -17
- package/dist/subgraphs/document-editor/index.d.ts +3 -2
- package/dist/subgraphs/document-editor/index.d.ts.map +1 -1
- package/dist/subgraphs/document-editor/index.js +1 -1
- package/dist/subgraphs/document-editor/resolvers.d.ts +1 -1
- package/dist/subgraphs/document-editor/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/document-editor/resolvers.js +12 -16
- package/dist/subgraphs/document-editor/schema.d.ts.map +1 -1
- package/dist/subgraphs/document-editor/schema.js +2 -21
- package/dist/subgraphs/index.d.ts +4 -4
- package/dist/subgraphs/index.d.ts.map +1 -1
- package/dist/subgraphs/index.js +4 -4
- package/dist/subgraphs/processor-module/index.d.ts +1 -1
- package/dist/subgraphs/processor-module/index.d.ts.map +1 -1
- package/dist/subgraphs/processor-module/resolvers.d.ts +1 -1
- package/dist/subgraphs/processor-module/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/processor-module/resolvers.js +12 -16
- package/dist/subgraphs/processor-module/schema.d.ts.map +1 -1
- package/dist/subgraphs/processor-module/schema.js +2 -22
- package/dist/subgraphs/subgraph-module/index.d.ts +1 -1
- package/dist/subgraphs/subgraph-module/index.d.ts.map +1 -1
- package/dist/subgraphs/subgraph-module/resolvers.d.ts +1 -1
- package/dist/subgraphs/subgraph-module/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/subgraph-module/resolvers.js +12 -16
- package/dist/subgraphs/subgraph-module/schema.d.ts.map +1 -1
- package/dist/subgraphs/subgraph-module/schema.js +2 -15
- package/dist/subgraphs/vetra-package/index.d.ts +1 -1
- package/dist/subgraphs/vetra-package/index.d.ts.map +1 -1
- package/dist/subgraphs/vetra-package/resolvers.d.ts +1 -1
- package/dist/subgraphs/vetra-package/resolvers.d.ts.map +1 -1
- package/dist/subgraphs/vetra-package/resolvers.js +137 -94
- package/dist/subgraphs/vetra-package/schema.d.ts.map +1 -1
- package/dist/subgraphs/vetra-package/schema.js +3 -26
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* This is a scaffold file meant for customization:
|
|
3
3
|
* - change it by adding new tests or modifying the existing ones
|
|
4
4
|
*/
|
|
5
|
+
import { generateMock } from "@powerhousedao/codegen";
|
|
6
|
+
import { addPackageKeyword, AddPackageKeywordInputSchema, isVetraPackageDocument, reducer, removePackageKeyword, RemovePackageKeywordInputSchema, setPackageAuthor, SetPackageAuthorInputSchema, setPackageAuthorName, SetPackageAuthorNameInputSchema, setPackageAuthorWebsite, SetPackageAuthorWebsiteInputSchema, setPackageCategory, SetPackageCategoryInputSchema, setPackageDescription, SetPackageDescriptionInputSchema, setPackageGithubUrl, SetPackageGithubUrlInputSchema, setPackageName, SetPackageNameInputSchema, setPackageNpmUrl, SetPackageNpmUrlInputSchema, utils, } from "@powerhousedao/vetra/document-models/vetra-package";
|
|
5
7
|
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
import * as creators from "../../gen/base-operations/creators.js";
|
|
7
|
-
import { reducer } from "../../gen/reducer.js";
|
|
8
|
-
import { utils } from "@powerhousedao/vetra/document-models/vetra-package";
|
|
9
8
|
describe("BaseOperations Operations", () => {
|
|
10
9
|
let document;
|
|
11
10
|
beforeEach(() => {
|
|
@@ -14,7 +13,7 @@ describe("BaseOperations Operations", () => {
|
|
|
14
13
|
describe("setPackageName", () => {
|
|
15
14
|
it("should mutate state with new name", () => {
|
|
16
15
|
const input = { name: "my-package" };
|
|
17
|
-
const updatedDocument = reducer(document,
|
|
16
|
+
const updatedDocument = reducer(document, setPackageName(input));
|
|
18
17
|
expect(updatedDocument.state.global.name).toBe("my-package");
|
|
19
18
|
});
|
|
20
19
|
});
|
|
@@ -23,14 +22,14 @@ describe("BaseOperations Operations", () => {
|
|
|
23
22
|
const input = {
|
|
24
23
|
description: "A test package",
|
|
25
24
|
};
|
|
26
|
-
const updatedDocument = reducer(document,
|
|
25
|
+
const updatedDocument = reducer(document, setPackageDescription(input));
|
|
27
26
|
expect(updatedDocument.state.global.description).toBe("A test package");
|
|
28
27
|
});
|
|
29
28
|
});
|
|
30
29
|
describe("setPackageCategory", () => {
|
|
31
30
|
it("should mutate state with new category", () => {
|
|
32
31
|
const input = { category: "utility" };
|
|
33
|
-
const updatedDocument = reducer(document,
|
|
32
|
+
const updatedDocument = reducer(document, setPackageCategory(input));
|
|
34
33
|
expect(updatedDocument.state.global.category).toBe("utility");
|
|
35
34
|
});
|
|
36
35
|
});
|
|
@@ -40,17 +39,17 @@ describe("BaseOperations Operations", () => {
|
|
|
40
39
|
name: "John Doe",
|
|
41
40
|
website: "https://johndoe.com",
|
|
42
41
|
};
|
|
43
|
-
const updatedDocument = reducer(document,
|
|
42
|
+
const updatedDocument = reducer(document, setPackageAuthor(input));
|
|
44
43
|
expect(updatedDocument.state.global.author.name).toBe("John Doe");
|
|
45
44
|
expect(updatedDocument.state.global.author.website).toBe("https://johndoe.com");
|
|
46
45
|
});
|
|
47
46
|
it("should handle partial author data (name only or website only)", () => {
|
|
48
47
|
// Name only
|
|
49
|
-
let updatedDoc = reducer(document,
|
|
48
|
+
let updatedDoc = reducer(document, setPackageAuthor({ name: "Jane Doe" }));
|
|
50
49
|
expect(updatedDoc.state.global.author.name).toBe("Jane Doe");
|
|
51
50
|
expect(updatedDoc.state.global.author.website).toBeNull();
|
|
52
51
|
// Website only
|
|
53
|
-
updatedDoc = reducer(updatedDoc,
|
|
52
|
+
updatedDoc = reducer(updatedDoc, setPackageAuthor({ website: "https://janedoe.com" }));
|
|
54
53
|
expect(updatedDoc.state.global.author.name).toBeNull();
|
|
55
54
|
expect(updatedDoc.state.global.author.website).toBe("https://janedoe.com");
|
|
56
55
|
});
|
|
@@ -58,7 +57,7 @@ describe("BaseOperations Operations", () => {
|
|
|
58
57
|
describe("setPackageAuthorName", () => {
|
|
59
58
|
it("should mutate state with new author name", () => {
|
|
60
59
|
const input = { name: "Alice" };
|
|
61
|
-
const updatedDocument = reducer(document,
|
|
60
|
+
const updatedDocument = reducer(document, setPackageAuthorName(input));
|
|
62
61
|
expect(updatedDocument.state.global.author.name).toBe("Alice");
|
|
63
62
|
});
|
|
64
63
|
});
|
|
@@ -67,7 +66,7 @@ describe("BaseOperations Operations", () => {
|
|
|
67
66
|
const input = {
|
|
68
67
|
website: "https://example.com",
|
|
69
68
|
};
|
|
70
|
-
const updatedDocument = reducer(document,
|
|
69
|
+
const updatedDocument = reducer(document, setPackageAuthorWebsite(input));
|
|
71
70
|
expect(updatedDocument.state.global.author.website).toBe("https://example.com");
|
|
72
71
|
});
|
|
73
72
|
});
|
|
@@ -77,7 +76,7 @@ describe("BaseOperations Operations", () => {
|
|
|
77
76
|
id: "kw-1",
|
|
78
77
|
label: "react",
|
|
79
78
|
};
|
|
80
|
-
const updatedDocument = reducer(document,
|
|
79
|
+
const updatedDocument = reducer(document, addPackageKeyword(input));
|
|
81
80
|
expect(updatedDocument.state.global.keywords).toContainEqual({
|
|
82
81
|
id: "kw-1",
|
|
83
82
|
label: "react",
|
|
@@ -89,15 +88,15 @@ describe("BaseOperations Operations", () => {
|
|
|
89
88
|
id: "first-kw",
|
|
90
89
|
label: "typescript",
|
|
91
90
|
};
|
|
92
|
-
const updatedDocument = reducer(document,
|
|
91
|
+
const updatedDocument = reducer(document, addPackageKeyword(input));
|
|
93
92
|
expect(updatedDocument.state.global.keywords).toEqual([
|
|
94
93
|
{ id: "first-kw", label: "typescript" },
|
|
95
94
|
]);
|
|
96
95
|
});
|
|
97
96
|
it("should add multiple keywords sequentially", () => {
|
|
98
|
-
let updatedDoc = reducer(document,
|
|
99
|
-
updatedDoc = reducer(updatedDoc,
|
|
100
|
-
updatedDoc = reducer(updatedDoc,
|
|
97
|
+
let updatedDoc = reducer(document, addPackageKeyword({ id: "kw-1", label: "react" }));
|
|
98
|
+
updatedDoc = reducer(updatedDoc, addPackageKeyword({ id: "kw-2", label: "vue" }));
|
|
99
|
+
updatedDoc = reducer(updatedDoc, addPackageKeyword({ id: "kw-3", label: "angular" }));
|
|
101
100
|
expect(updatedDoc.state.global.keywords).toHaveLength(3);
|
|
102
101
|
expect(updatedDoc.state.global.keywords[0]).toEqual({
|
|
103
102
|
id: "kw-1",
|
|
@@ -117,10 +116,10 @@ describe("BaseOperations Operations", () => {
|
|
|
117
116
|
id: "duplicate",
|
|
118
117
|
label: "first",
|
|
119
118
|
};
|
|
120
|
-
let updatedDoc = reducer(document,
|
|
119
|
+
let updatedDoc = reducer(document, addPackageKeyword(input));
|
|
121
120
|
expect(updatedDoc.state.global.keywords).toHaveLength(1);
|
|
122
121
|
expect(updatedDoc.operations.global[0].error).toBeUndefined();
|
|
123
|
-
updatedDoc = reducer(updatedDoc,
|
|
122
|
+
updatedDoc = reducer(updatedDoc, addPackageKeyword({
|
|
124
123
|
id: "duplicate",
|
|
125
124
|
label: "second",
|
|
126
125
|
}));
|
|
@@ -131,42 +130,42 @@ describe("BaseOperations Operations", () => {
|
|
|
131
130
|
});
|
|
132
131
|
describe("removePackageKeyword", () => {
|
|
133
132
|
it("should mutate state by removing keyword from array", () => {
|
|
134
|
-
let updatedDoc = reducer(document,
|
|
133
|
+
let updatedDoc = reducer(document, addPackageKeyword({
|
|
135
134
|
id: "to-remove",
|
|
136
135
|
label: "test",
|
|
137
136
|
}));
|
|
138
|
-
updatedDoc = reducer(updatedDoc,
|
|
137
|
+
updatedDoc = reducer(updatedDoc, removePackageKeyword({ id: "to-remove" }));
|
|
139
138
|
expect(updatedDoc.state.global.keywords).not.toContainEqual({
|
|
140
139
|
id: "to-remove",
|
|
141
140
|
label: "test",
|
|
142
141
|
});
|
|
143
142
|
});
|
|
144
143
|
it("should remove existing ID", () => {
|
|
145
|
-
let updatedDoc = reducer(document,
|
|
144
|
+
let updatedDoc = reducer(document, addPackageKeyword({
|
|
146
145
|
id: "existing",
|
|
147
146
|
label: "test",
|
|
148
147
|
}));
|
|
149
148
|
const lengthBefore = updatedDoc.state.global.keywords.length;
|
|
150
|
-
updatedDoc = reducer(updatedDoc,
|
|
149
|
+
updatedDoc = reducer(updatedDoc, removePackageKeyword({ id: "existing" }));
|
|
151
150
|
expect(updatedDoc.state.global.keywords.length).toBe(lengthBefore - 1);
|
|
152
151
|
expect(updatedDoc.state.global.keywords.find((kw) => kw.id === "existing")).toBeUndefined();
|
|
153
152
|
});
|
|
154
153
|
it("should gracefully handle non-existent ID", () => {
|
|
155
154
|
const initialState = document.state.global.keywords;
|
|
156
|
-
const updatedDocument = reducer(document,
|
|
155
|
+
const updatedDocument = reducer(document, removePackageKeyword({ id: "non-existent-id" }));
|
|
157
156
|
expect(updatedDocument.state.global.keywords).toEqual(initialState);
|
|
158
157
|
});
|
|
159
158
|
it("should handle empty array gracefully", () => {
|
|
160
159
|
expect(document.state.global.keywords).toEqual([]);
|
|
161
|
-
const updatedDocument = reducer(document,
|
|
160
|
+
const updatedDocument = reducer(document, removePackageKeyword({ id: "any-id" }));
|
|
162
161
|
expect(updatedDocument.state.global.keywords).toEqual([]);
|
|
163
162
|
});
|
|
164
163
|
it("should add then immediately remove item", () => {
|
|
165
|
-
let updatedDoc = reducer(document,
|
|
164
|
+
let updatedDoc = reducer(document, addPackageKeyword({
|
|
166
165
|
id: "temp-kw",
|
|
167
166
|
label: "temp",
|
|
168
167
|
}));
|
|
169
|
-
updatedDoc = reducer(updatedDoc,
|
|
168
|
+
updatedDoc = reducer(updatedDoc, removePackageKeyword({ id: "temp-kw" }));
|
|
170
169
|
expect(updatedDoc.state.global.keywords.find((kw) => kw.id === "temp-kw")).toBeUndefined();
|
|
171
170
|
expect(updatedDoc.operations.global).toHaveLength(2);
|
|
172
171
|
});
|
|
@@ -176,7 +175,7 @@ describe("BaseOperations Operations", () => {
|
|
|
176
175
|
const input = {
|
|
177
176
|
url: "https://github.com/user/repo",
|
|
178
177
|
};
|
|
179
|
-
const updatedDocument = reducer(document,
|
|
178
|
+
const updatedDocument = reducer(document, setPackageGithubUrl(input));
|
|
180
179
|
expect(updatedDocument.state.global.githubUrl).toBe("https://github.com/user/repo");
|
|
181
180
|
});
|
|
182
181
|
});
|
|
@@ -185,8 +184,108 @@ describe("BaseOperations Operations", () => {
|
|
|
185
184
|
const input = {
|
|
186
185
|
url: "https://npmjs.com/package/my-package",
|
|
187
186
|
};
|
|
188
|
-
const updatedDocument = reducer(document,
|
|
187
|
+
const updatedDocument = reducer(document, setPackageNpmUrl(input));
|
|
189
188
|
expect(updatedDocument.state.global.npmUrl).toBe("https://npmjs.com/package/my-package");
|
|
190
189
|
});
|
|
191
190
|
});
|
|
191
|
+
it("should handle setPackageName operation", () => {
|
|
192
|
+
const document = utils.createDocument();
|
|
193
|
+
const input = generateMock(SetPackageNameInputSchema());
|
|
194
|
+
const updatedDocument = reducer(document, setPackageName(input));
|
|
195
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
196
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
197
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_NAME");
|
|
198
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
199
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
200
|
+
});
|
|
201
|
+
it("should handle setPackageDescription operation", () => {
|
|
202
|
+
const document = utils.createDocument();
|
|
203
|
+
const input = generateMock(SetPackageDescriptionInputSchema());
|
|
204
|
+
const updatedDocument = reducer(document, setPackageDescription(input));
|
|
205
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
206
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
207
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_DESCRIPTION");
|
|
208
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
209
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
210
|
+
});
|
|
211
|
+
it("should handle setPackageCategory operation", () => {
|
|
212
|
+
const document = utils.createDocument();
|
|
213
|
+
const input = generateMock(SetPackageCategoryInputSchema());
|
|
214
|
+
const updatedDocument = reducer(document, setPackageCategory(input));
|
|
215
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
216
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
217
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_CATEGORY");
|
|
218
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
219
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
220
|
+
});
|
|
221
|
+
it("should handle setPackageAuthor operation", () => {
|
|
222
|
+
const document = utils.createDocument();
|
|
223
|
+
const input = generateMock(SetPackageAuthorInputSchema());
|
|
224
|
+
const updatedDocument = reducer(document, setPackageAuthor(input));
|
|
225
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
226
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
227
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_AUTHOR");
|
|
228
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
229
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
230
|
+
});
|
|
231
|
+
it("should handle setPackageAuthorName operation", () => {
|
|
232
|
+
const document = utils.createDocument();
|
|
233
|
+
const input = generateMock(SetPackageAuthorNameInputSchema());
|
|
234
|
+
const updatedDocument = reducer(document, setPackageAuthorName(input));
|
|
235
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
236
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
237
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_AUTHOR_NAME");
|
|
238
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
239
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
240
|
+
});
|
|
241
|
+
it("should handle setPackageAuthorWebsite operation", () => {
|
|
242
|
+
const document = utils.createDocument();
|
|
243
|
+
const input = generateMock(SetPackageAuthorWebsiteInputSchema());
|
|
244
|
+
const updatedDocument = reducer(document, setPackageAuthorWebsite(input));
|
|
245
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
246
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
247
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_AUTHOR_WEBSITE");
|
|
248
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
249
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
250
|
+
});
|
|
251
|
+
it("should handle addPackageKeyword operation", () => {
|
|
252
|
+
const document = utils.createDocument();
|
|
253
|
+
const input = generateMock(AddPackageKeywordInputSchema());
|
|
254
|
+
const updatedDocument = reducer(document, addPackageKeyword(input));
|
|
255
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
256
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
257
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_PACKAGE_KEYWORD");
|
|
258
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
259
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
260
|
+
});
|
|
261
|
+
it("should handle removePackageKeyword operation", () => {
|
|
262
|
+
const document = utils.createDocument();
|
|
263
|
+
const input = generateMock(RemovePackageKeywordInputSchema());
|
|
264
|
+
const updatedDocument = reducer(document, removePackageKeyword(input));
|
|
265
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
266
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
267
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("REMOVE_PACKAGE_KEYWORD");
|
|
268
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
269
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
270
|
+
});
|
|
271
|
+
it("should handle setPackageGithubUrl operation", () => {
|
|
272
|
+
const document = utils.createDocument();
|
|
273
|
+
const input = generateMock(SetPackageGithubUrlInputSchema());
|
|
274
|
+
const updatedDocument = reducer(document, setPackageGithubUrl(input));
|
|
275
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
276
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
277
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_GITHUB_URL");
|
|
278
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
279
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
280
|
+
});
|
|
281
|
+
it("should handle setPackageNpmUrl operation", () => {
|
|
282
|
+
const document = utils.createDocument();
|
|
283
|
+
const input = generateMock(SetPackageNpmUrlInputSchema());
|
|
284
|
+
const updatedDocument = reducer(document, setPackageNpmUrl(input));
|
|
285
|
+
expect(isVetraPackageDocument(updatedDocument)).toBe(true);
|
|
286
|
+
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
287
|
+
expect(updatedDocument.operations.global[0].action.type).toBe("SET_PACKAGE_NPM_URL");
|
|
288
|
+
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
289
|
+
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
290
|
+
});
|
|
192
291
|
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useDocumentTypesInSelectedDrive, useSupportedDocumentTypesInReactor, } from "@powerhousedao/reactor-browser";
|
|
3
3
|
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { useSelectedAppModuleDocument } from "../../../document-models/app-module/hooks.js";
|
|
4
5
|
import { actions } from "../../../document-models/app-module/index.js";
|
|
5
6
|
import { StatusPill } from "../../components/index.js";
|
|
6
7
|
import { useDebounce } from "../../hooks/index.js";
|
|
7
|
-
import { useSelectedAppModuleDocument } from "../../hooks/useVetraDocument.js";
|
|
8
8
|
const ALL_IN_DRIVE = "all-in-drive";
|
|
9
9
|
const ALL_IN_REACTOR = "all-in-reactor";
|
|
10
10
|
const ALLOW_ANY = "allow-any";
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
3
3
|
import { userEvent } from "@testing-library/user-event";
|
|
4
4
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { useSelectedAppModuleDocument } from "
|
|
5
|
+
import { useSelectedAppModuleDocument } from "../../document-models/app-module/hooks.js";
|
|
6
6
|
import Editor from "./editor.js";
|
|
7
|
-
vi.mock("
|
|
7
|
+
vi.mock("../../document-models/app-module/hooks.js", () => ({
|
|
8
8
|
useSelectedAppModuleDocument: vi.fn(),
|
|
9
9
|
}));
|
|
10
10
|
vi.mock("@powerhousedao/reactor-browser", async (importOriginal) => {
|
|
@@ -20,6 +20,7 @@ vi.mock("@powerhousedao/reactor-browser", async (importOriginal) => {
|
|
|
20
20
|
useSetPHDocumentEditorConfig: vi.fn(),
|
|
21
21
|
// These are needed by DocumentToolbar but mocked in setupTests
|
|
22
22
|
useSelectedDocument: vi.fn(() => [null, vi.fn()]),
|
|
23
|
+
useSelectedDocumentSafe: vi.fn(() => [null, vi.fn()]),
|
|
23
24
|
useDocumentById: vi.fn(() => [null, vi.fn()]),
|
|
24
25
|
useDocumentTimeline: vi.fn(() => []),
|
|
25
26
|
useNodeParentFolderById: vi.fn(() => null),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentEditorForm.d.ts","sourceRoot":"","sources":["../../../../editors/document-editor/components/DocumentEditorForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,mDAAmD,CAAC;AAI3D,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC1D,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAChE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"DocumentEditorForm.d.ts","sourceRoot":"","sources":["../../../../editors/document-editor/components/DocumentEditorForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,mDAAmD,CAAC;AAI3D,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC1D,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAChE,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAqED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAmIhE,CAAC"}
|
|
@@ -1,14 +1,41 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
2
|
+
import { Suspense, useEffect, useState } from "react";
|
|
3
3
|
import { StatusPill } from "../../components/index.js";
|
|
4
4
|
import { useAvailableDocumentTypes, useDebounce } from "../../hooks/index.js";
|
|
5
|
+
function DocumentTypeSelectUI(props) {
|
|
6
|
+
return (_jsxs("select", { id: "supported-document-types", className: "w-full rounded-md border border-gray-300 px-3 py-2 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500", ...props, children: [_jsx("option", { value: "", children: "Select a document type" }), props.children] }));
|
|
7
|
+
}
|
|
8
|
+
function DocumentTypeSelect({ documentTypes, setDocumentTypes, onAddDocumentType, onRemoveDocumentType, }) {
|
|
9
|
+
// Get available document types from the hook (vetra drive only for document editor)
|
|
10
|
+
const availableDocumentTypes = useAvailableDocumentTypes(true);
|
|
11
|
+
const [selectedDocumentType, setSelectedDocumentType] = useState("");
|
|
12
|
+
return (_jsx(DocumentTypeSelectUI, { value: selectedDocumentType, onChange: (e) => {
|
|
13
|
+
const selectedValue = e.target.value;
|
|
14
|
+
if (selectedValue) {
|
|
15
|
+
// Remove existing document type if any
|
|
16
|
+
const existingType = documentTypes?.at(0);
|
|
17
|
+
if (existingType) {
|
|
18
|
+
onRemoveDocumentType?.({ id: existingType.id });
|
|
19
|
+
}
|
|
20
|
+
// Add the new document type
|
|
21
|
+
const newTypeInput = {
|
|
22
|
+
id: Date.now().toString(), // Generate a unique ID
|
|
23
|
+
documentType: selectedValue,
|
|
24
|
+
};
|
|
25
|
+
const newType = {
|
|
26
|
+
id: newTypeInput.id,
|
|
27
|
+
documentType: newTypeInput.documentType,
|
|
28
|
+
};
|
|
29
|
+
setDocumentTypes([newType]); // Replace with single item array
|
|
30
|
+
onAddDocumentType?.(newTypeInput);
|
|
31
|
+
}
|
|
32
|
+
setSelectedDocumentType("");
|
|
33
|
+
}, children: availableDocumentTypes.map((docType) => (_jsx("option", { value: docType, children: docType }, docType))) }));
|
|
34
|
+
}
|
|
5
35
|
export const DocumentEditorForm = ({ editorName: initialEditorName = "", documentTypes: initialDocumentTypes = [], status = "DRAFT", onEditorNameChange, onAddDocumentType, onRemoveDocumentType, onConfirm, }) => {
|
|
6
36
|
const [editorName, setEditorName] = useState(initialEditorName);
|
|
7
37
|
const [documentTypes, setDocumentTypes] = useState(initialDocumentTypes);
|
|
8
|
-
const [selectedDocumentType, setSelectedDocumentType] = useState("");
|
|
9
38
|
const [isConfirmed, setIsConfirmed] = useState(false);
|
|
10
|
-
// Get available document types from the hook (vetra drive only for document editor)
|
|
11
|
-
const availableDocumentTypes = useAvailableDocumentTypes(true);
|
|
12
39
|
// Use the debounce hook for name changes
|
|
13
40
|
useDebounce(editorName, onEditorNameChange, 300);
|
|
14
41
|
// Update local state when initial values change
|
|
@@ -32,28 +59,7 @@ export const DocumentEditorForm = ({ editorName: initialEditorName = "", documen
|
|
|
32
59
|
onConfirm?.();
|
|
33
60
|
}
|
|
34
61
|
};
|
|
35
|
-
return (_jsxs("div", { className: "space-y-6 bg-white p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("h2", { className: "text-lg font-medium text-gray-900", children: "Editor Configuration" }), _jsx(StatusPill, { status: status === "CONFIRMED" ? "confirmed" : "draft", label: status === "CONFIRMED" ? "Confirmed" : "Draft" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "editor-name", className: "mb-2 block text-sm font-medium text-gray-700", children: "Editor Name" }), _jsx("input", { id: "editor-name", type: "text", value: editorName, onChange: (e) => setEditorName(e.target.value), disabled: isReadOnly, className: `w-full rounded-md border border-gray-300 px-3 py-2 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 ${isReadOnly ? "cursor-not-allowed bg-gray-100" : ""}` })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "supported-document-types", className: "mb-2 block text-sm font-medium text-gray-700", children: "Supported Document Types" }), _jsxs("div", { className: "space-y-2", children: [!isReadOnly &&
|
|
36
|
-
const selectedValue = e.target.value;
|
|
37
|
-
if (selectedValue) {
|
|
38
|
-
// Remove existing document type if any
|
|
39
|
-
const existingType = documentTypes.at(0);
|
|
40
|
-
if (existingType) {
|
|
41
|
-
onRemoveDocumentType?.({ id: existingType.id });
|
|
42
|
-
}
|
|
43
|
-
// Add the new document type
|
|
44
|
-
const newTypeInput = {
|
|
45
|
-
id: Date.now().toString(), // Generate a unique ID
|
|
46
|
-
documentType: selectedValue,
|
|
47
|
-
};
|
|
48
|
-
const newType = {
|
|
49
|
-
id: newTypeInput.id,
|
|
50
|
-
documentType: newTypeInput.documentType,
|
|
51
|
-
};
|
|
52
|
-
setDocumentTypes([newType]); // Replace with single item array
|
|
53
|
-
onAddDocumentType?.(newTypeInput);
|
|
54
|
-
}
|
|
55
|
-
setSelectedDocumentType("");
|
|
56
|
-
}, className: "w-full rounded-md border border-gray-300 px-3 py-2 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500", children: [_jsx("option", { value: "", children: "Select a document type" }), availableDocumentTypes.map((docType) => (_jsx("option", { value: docType, children: docType }, docType)))] })), _jsx("div", { className: "space-y-1", children: documentTypes.map((type) => (_jsxs("div", { className: "flex items-center py-1", children: [_jsx("span", { className: "text-sm text-gray-700", children: type.documentType }), !isReadOnly && (_jsx("button", { onClick: () => {
|
|
62
|
+
return (_jsxs("div", { className: "space-y-6 bg-white p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("h2", { className: "text-lg font-medium text-gray-900", children: "Editor Configuration" }), _jsx(StatusPill, { status: status === "CONFIRMED" ? "confirmed" : "draft", label: status === "CONFIRMED" ? "Confirmed" : "Draft" })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "editor-name", className: "mb-2 block text-sm font-medium text-gray-700", children: "Editor Name" }), _jsx("input", { id: "editor-name", type: "text", value: editorName, onChange: (e) => setEditorName(e.target.value), disabled: isReadOnly, className: `w-full rounded-md border border-gray-300 px-3 py-2 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 ${isReadOnly ? "cursor-not-allowed bg-gray-100" : ""}` })] }), _jsxs("div", { children: [_jsx("label", { htmlFor: "supported-document-types", className: "mb-2 block text-sm font-medium text-gray-700", children: "Supported Document Types" }), _jsxs("div", { className: "space-y-2", children: [!isReadOnly && (_jsx(Suspense, { fallback: _jsx(DocumentTypeSelectUI, {}), children: _jsx(DocumentTypeSelect, { documentTypes: documentTypes, setDocumentTypes: setDocumentTypes, onAddDocumentType: onAddDocumentType, onRemoveDocumentType: onRemoveDocumentType }) })), _jsx("div", { className: "space-y-1", children: documentTypes.map((type) => (_jsxs("div", { className: "flex items-center py-1", children: [_jsx("span", { className: "text-sm text-gray-700", children: type.documentType }), !isReadOnly && (_jsx("button", { onClick: () => {
|
|
57
63
|
setDocumentTypes([]);
|
|
58
64
|
onRemoveDocumentType?.({ id: type.id });
|
|
59
65
|
}, className: "ml-2 text-gray-400 hover:text-gray-600 focus:outline-none", children: "\u00D7" }))] }, type.id))) })] })] }), !isReadOnly && (_jsx("div", { children: _jsx("button", { onClick: handleConfirm, disabled: !editorName.trim() || documentTypes.length === 0, className: "rounded-md bg-blue-600 px-4 py-2 text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:bg-gray-300", children: "Confirm" }) }))] }));
|
|
@@ -2,8 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { DocumentToolbar } from "@powerhousedao/design-system/connect";
|
|
3
3
|
import { useSetPHDocumentEditorConfig } from "@powerhousedao/reactor-browser";
|
|
4
4
|
import { useCallback } from "react";
|
|
5
|
+
import { useSelectedDocumentEditorDocument } from "../../document-models/document-editor/hooks.js";
|
|
5
6
|
import { actions } from "../../document-models/document-editor/index.js";
|
|
6
|
-
import { useSelectedDocumentEditorDocument } from "../hooks/useVetraDocument.js";
|
|
7
7
|
import { DocumentEditorForm } from "./components/DocumentEditorForm.js";
|
|
8
8
|
import { editorConfig } from "./config.js";
|
|
9
9
|
export default function Editor() {
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { render, screen, waitFor } from "@testing-library/react";
|
|
3
3
|
import { userEvent } from "@testing-library/user-event";
|
|
4
4
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
-
import { useSelectedDocumentEditorDocument } from "
|
|
5
|
+
import { useSelectedDocumentEditorDocument } from "../../document-models/document-editor/hooks.js";
|
|
6
6
|
import Editor from "./editor.js";
|
|
7
|
-
vi.mock("
|
|
7
|
+
vi.mock("../../document-models/document-editor/hooks.js", () => ({
|
|
8
8
|
useSelectedDocumentEditorDocument: vi.fn(),
|
|
9
9
|
}));
|
|
10
10
|
vi.mock("../hooks/useAvailableDocumentTypes.js", () => ({
|