asma-core-helpers 0.26.0 → 0.27.1
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/lib/collaboration/applyOperation.d.ts.map +1 -1
- package/lib/collaboration/applyOperation.js +354 -69
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/index.d.ts +1 -0
- package/lib/collaboration/index.d.ts.map +1 -1
- package/lib/collaboration/index.js +1 -0
- package/lib/collaboration/index.js.map +1 -1
- package/lib/collaboration/operations.d.ts +35 -1
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +7 -0
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/schemas.d.ts +125 -2
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +135 -10
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +28 -1
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.d.ts +4 -0
- package/lib/collaboration/testHelpers/documentGenerator.d.ts.map +1 -1
- package/lib/collaboration/testHelpers/documentGenerator.js +100 -4
- package/lib/collaboration/testHelpers/documentGenerator.js.map +1 -1
- package/package.json +1 -1
- package/src/collaboration/applyOperation.test.ts +379 -12
- package/src/collaboration/applyOperation.ts +411 -76
- package/src/collaboration/index.ts +1 -0
- package/src/collaboration/operations.ts +35 -0
- package/src/collaboration/property.test.ts +24 -1
- package/src/collaboration/schemas.test.ts +136 -1
- package/src/collaboration/schemas.ts +167 -5
- package/src/collaboration/templateDocument.ts +27 -1
- package/src/collaboration/testHelpers/documentGenerator.ts +101 -5
|
@@ -27,10 +27,15 @@ const NEW_NODE_ID = (n: number): string => `n-${n}`
|
|
|
27
27
|
const NEW_BINDING_ID = (n: number): string => `b-${n}`
|
|
28
28
|
const NEW_FILTER_ID = (n: number): string => `f-${n}`
|
|
29
29
|
const NEW_VISIBILITY_RULE_ID = (n: number): string => `vr-${n}`
|
|
30
|
+
const NEW_COLUMN_ID = (n: number): string => `c-${n}`
|
|
31
|
+
const NEW_NARRATIVE_RULE_ID = (n: number): string => `nr-${n}`
|
|
32
|
+
const NEW_QNR_RULE_ID = (n: number): string => `qr-${n}`
|
|
30
33
|
|
|
31
34
|
type IdPools = {
|
|
32
35
|
questions: string[]
|
|
33
36
|
grids: string[]
|
|
37
|
+
columns: string[]
|
|
38
|
+
columnOwnerById: Record<string, string>
|
|
34
39
|
gridRows: string[]
|
|
35
40
|
alternatives: string[]
|
|
36
41
|
tabs: string[]
|
|
@@ -40,11 +45,15 @@ type IdPools = {
|
|
|
40
45
|
filters: string[]
|
|
41
46
|
visibilityRules: string[]
|
|
42
47
|
highlightRules: string[]
|
|
48
|
+
narrativeRules: string[]
|
|
49
|
+
qnrRules: string[]
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
const emptyPools = (): IdPools => ({
|
|
46
53
|
questions: [],
|
|
47
54
|
grids: [],
|
|
55
|
+
columns: [],
|
|
56
|
+
columnOwnerById: {},
|
|
48
57
|
gridRows: [],
|
|
49
58
|
alternatives: [],
|
|
50
59
|
tabs: [],
|
|
@@ -54,6 +63,8 @@ const emptyPools = (): IdPools => ({
|
|
|
54
63
|
filters: [],
|
|
55
64
|
visibilityRules: [],
|
|
56
65
|
highlightRules: [],
|
|
66
|
+
narrativeRules: [],
|
|
67
|
+
qnrRules: [],
|
|
57
68
|
})
|
|
58
69
|
|
|
59
70
|
/** Picks an id from a pool, or mints a new one when the pool is empty. */
|
|
@@ -65,7 +76,7 @@ const pickOrFallback = (random: () => number, pool: string[], fallback: string):
|
|
|
65
76
|
pool.length === 0 ? fallback : pick(random, pool)
|
|
66
77
|
|
|
67
78
|
/** A schema-valid value for the given question field (op payloads are validated before the reducer). */
|
|
68
|
-
const fieldValue = (field: 'label' | 'required' | 'scale.from' | 'grid.singleRow'
|
|
79
|
+
const fieldValue = (field: 'label' | 'required' | 'scale.from' | 'grid.singleRow', random: () => number) => {
|
|
69
80
|
switch (field) {
|
|
70
81
|
case 'label':
|
|
71
82
|
return pick(random, ['Hei', 'Ha det', 'Tittel'])
|
|
@@ -74,8 +85,6 @@ const fieldValue = (field: 'label' | 'required' | 'scale.from' | 'grid.singleRow
|
|
|
74
85
|
return pick(random, [true, false] as const)
|
|
75
86
|
case 'scale.from':
|
|
76
87
|
return 1
|
|
77
|
-
case 'grid.columnIds':
|
|
78
|
-
return pick(random, [['c-0'], ['c-1', 'c-2'], []] as Array<string[]>)
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
90
|
|
|
@@ -114,6 +123,7 @@ export const generateOpSequence = (
|
|
|
114
123
|
}
|
|
115
124
|
|
|
116
125
|
const nextOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
126
|
+
if (maybe(random, 0.22)) return nextAddedContractOp(random, pools)
|
|
117
127
|
const roll = random()
|
|
118
128
|
|
|
119
129
|
if (roll < 0.1) {
|
|
@@ -125,7 +135,7 @@ const nextOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
|
125
135
|
}
|
|
126
136
|
if (roll < 0.3) {
|
|
127
137
|
const questionId = idOrNew(random, pools.questions, NEW_QUESTION_ID)
|
|
128
|
-
const field = pick(random, ['label', 'required', 'scale.from', 'grid.singleRow'
|
|
138
|
+
const field = pick(random, ['label', 'required', 'scale.from', 'grid.singleRow'] as const)
|
|
129
139
|
// The op schema validates op payloads before the reducer runs, so generated ops must
|
|
130
140
|
// be schema-valid: each field gets a value of the field's own type.
|
|
131
141
|
const value = fieldValue(field, random)
|
|
@@ -199,14 +209,88 @@ const nextOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
|
199
209
|
}
|
|
200
210
|
}
|
|
201
211
|
|
|
212
|
+
/** Operations added by ASMA-7676, kept in a dedicated mix so every seeded run exercises them. */
|
|
213
|
+
const nextAddedContractOp = (random: () => number, pools: IdPools): TemplateOp => {
|
|
214
|
+
const choice = Math.floor(random() * 9)
|
|
215
|
+
const columnQuestionId = pickOrFallback(random, pools.columns, 'c-ghost')
|
|
216
|
+
const ownerQuestionId = pools.columnOwnerById[columnQuestionId] ?? pickOrFallback(random, pools.grids, 'g-ghost')
|
|
217
|
+
const questionId = idOrNew(random, pools.questions, NEW_QUESTION_ID)
|
|
218
|
+
switch (choice) {
|
|
219
|
+
case 0:
|
|
220
|
+
return {
|
|
221
|
+
type: 'gridColumn.create',
|
|
222
|
+
questionId: pickOrFallback(random, pools.grids, 'g-ghost'),
|
|
223
|
+
columnQuestionId: NEW_COLUMN_ID(pools.columns.length),
|
|
224
|
+
questionType: pick(random, ['TextShort', 'DateField', 'RadioButtons'] as const),
|
|
225
|
+
atIndex: Math.floor(random() * 4),
|
|
226
|
+
}
|
|
227
|
+
case 1:
|
|
228
|
+
return {
|
|
229
|
+
type: 'gridColumn.move',
|
|
230
|
+
questionId: ownerQuestionId,
|
|
231
|
+
columnQuestionId,
|
|
232
|
+
toIndex: Math.floor(random() * 5),
|
|
233
|
+
}
|
|
234
|
+
case 2:
|
|
235
|
+
return {
|
|
236
|
+
type: 'gridColumn.setLayout',
|
|
237
|
+
questionId: ownerQuestionId,
|
|
238
|
+
columnQuestionId,
|
|
239
|
+
placement: maybe(random, 0.25)
|
|
240
|
+
? null
|
|
241
|
+
: { row: Math.floor(random() * 3), cell: Math.floor(random() * 4), keepCellSize: true },
|
|
242
|
+
}
|
|
243
|
+
case 3:
|
|
244
|
+
return {
|
|
245
|
+
type: 'narrativeRule.set',
|
|
246
|
+
ruleId: NEW_NARRATIVE_RULE_ID(pools.narrativeRules.length),
|
|
247
|
+
questionId,
|
|
248
|
+
condition: { sourceQuestionId: pickOrFallback(random, pools.questions, 'q-ghost') },
|
|
249
|
+
}
|
|
250
|
+
case 4:
|
|
251
|
+
return {
|
|
252
|
+
type: 'narrativeRule.delete',
|
|
253
|
+
ruleId: pickOrFallback(random, pools.narrativeRules, 'nr-ghost'),
|
|
254
|
+
}
|
|
255
|
+
case 5:
|
|
256
|
+
return {
|
|
257
|
+
type: 'qnrRule.set',
|
|
258
|
+
ruleId: NEW_QNR_RULE_ID(pools.qnrRules.length),
|
|
259
|
+
questionId,
|
|
260
|
+
condition: { sourceQuestionId: pickOrFallback(random, pools.questions, 'q-ghost') },
|
|
261
|
+
templateFamilyId: `family-${Math.floor(random() * 5)}`,
|
|
262
|
+
}
|
|
263
|
+
case 6:
|
|
264
|
+
return { type: 'qnrRule.delete', ruleId: pickOrFallback(random, pools.qnrRules, 'qr-ghost') }
|
|
265
|
+
case 7:
|
|
266
|
+
return { type: 'question.move', questionId: columnQuestionId, toIndex: Math.floor(random() * 5) }
|
|
267
|
+
default:
|
|
268
|
+
return {
|
|
269
|
+
type: 'gridColumn.setLayout',
|
|
270
|
+
questionId: ownerQuestionId,
|
|
271
|
+
columnQuestionId,
|
|
272
|
+
placement: null,
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
202
277
|
const updatePools = (op: TemplateOp, ok: boolean, pools: IdPools): void => {
|
|
203
278
|
if (!ok) return
|
|
204
279
|
switch (op.type) {
|
|
205
280
|
case 'question.create':
|
|
206
281
|
pools.questions.push(op.questionId)
|
|
282
|
+
if (op.questionType === 'QuestionGrid') pools.grids.push(op.questionId)
|
|
207
283
|
break
|
|
208
284
|
case 'question.delete':
|
|
209
285
|
pools.questions = pools.questions.filter((id) => id !== op.questionId)
|
|
286
|
+
pools.grids = pools.grids.filter((id) => id !== op.questionId)
|
|
287
|
+
pools.columns = pools.columns.filter((id) => id !== op.questionId)
|
|
288
|
+
delete pools.columnOwnerById[op.questionId]
|
|
289
|
+
break
|
|
290
|
+
case 'gridColumn.create':
|
|
291
|
+
pools.questions.push(op.columnQuestionId)
|
|
292
|
+
pools.columns.push(op.columnQuestionId)
|
|
293
|
+
pools.columnOwnerById[op.columnQuestionId] = op.questionId
|
|
210
294
|
break
|
|
211
295
|
case 'gridRow.create':
|
|
212
296
|
pools.gridRows.push(op.rowId)
|
|
@@ -229,7 +313,19 @@ const updatePools = (op: TemplateOp, ok: boolean, pools: IdPools): void => {
|
|
|
229
313
|
pools.filters.push(op.filterId)
|
|
230
314
|
break
|
|
231
315
|
case 'visibilityRule.set':
|
|
232
|
-
pools.visibilityRules.push(op.ruleId)
|
|
316
|
+
if (!pools.visibilityRules.includes(op.ruleId)) pools.visibilityRules.push(op.ruleId)
|
|
317
|
+
break
|
|
318
|
+
case 'narrativeRule.set':
|
|
319
|
+
if (!pools.narrativeRules.includes(op.ruleId)) pools.narrativeRules.push(op.ruleId)
|
|
320
|
+
break
|
|
321
|
+
case 'narrativeRule.delete':
|
|
322
|
+
pools.narrativeRules = pools.narrativeRules.filter((id) => id !== op.ruleId)
|
|
323
|
+
break
|
|
324
|
+
case 'qnrRule.set':
|
|
325
|
+
if (!pools.qnrRules.includes(op.ruleId)) pools.qnrRules.push(op.ruleId)
|
|
326
|
+
break
|
|
327
|
+
case 'qnrRule.delete':
|
|
328
|
+
pools.qnrRules = pools.qnrRules.filter((id) => id !== op.ruleId)
|
|
233
329
|
break
|
|
234
330
|
case 'mappingBinding.create':
|
|
235
331
|
pools.bindings.push(op.bindingId)
|