@jsb188/mday 1.1.2
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/package.json +142 -0
- package/src/constants/agentMemory.ts +166 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +146 -0
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +21 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2199 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +60 -0
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +132 -0
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +85 -0
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +879 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +93 -0
- package/src/types/account.d.ts +81 -0
- package/src/types/agentMemory.d.ts +100 -0
- package/src/types/agentNote.d.ts +441 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +159 -0
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +231 -0
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +65 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +338 -0
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +350 -0
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +847 -0
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +481 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +435 -0
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1173 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +311 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +379 -0
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +357 -0
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +669 -0
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +262 -0
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +506 -0
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { FIELD_DOC_DEFAULT_ASIDE, FIELD_DOC_DOCUMENT_NAME_PATTERN, FIELD_DOC_SUMMARY_MAX } from '../src/constants/fieldDoc.ts';
|
|
3
|
+
import { getFieldDocAnswerId, getFieldDocDefinitionElementId } from '../src/utils/fieldDoc.ts';
|
|
4
|
+
import { getFieldDocAnswer, normalizeFieldDocAnswers } from '../src/utils/fieldDocAnswers.ts';
|
|
5
|
+
import { clampFieldDocSummary, composeFieldDocHint, isProgramFieldDoc } from '../src/utils/fieldDocProgram.ts';
|
|
6
|
+
import { composeWorkflowUserInstructions } from '../src/utils/workflow.ts';
|
|
7
|
+
|
|
8
|
+
describe('composeFieldDocHint', () => {
|
|
9
|
+
it('keeps the program hint when there are no custom instructions', () => {
|
|
10
|
+
expect(composeFieldDocHint('Read the probe.', null)).toBe('Read the probe.');
|
|
11
|
+
expect(composeFieldDocHint('Read the probe.', ' ')).toBe('Read the probe.');
|
|
12
|
+
expect(composeFieldDocHint(null, undefined)).toBeNull();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('appends trimmed custom instructions under their heading', () => {
|
|
16
|
+
expect(composeFieldDocHint(' Read the probe. ', ' Use the blue probe. ')).toBe(
|
|
17
|
+
'Read the probe.\nCustom instructions:\nUse the blue probe.',
|
|
18
|
+
);
|
|
19
|
+
expect(composeFieldDocHint('', 'Use the blue probe.')).toBe('Custom instructions:\nUse the blue probe.');
|
|
20
|
+
expect(composeFieldDocHint(null, 'Use the blue probe.')).toBe('Custom instructions:\nUse the blue probe.');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('composeWorkflowUserInstructions', () => {
|
|
25
|
+
it('appends trimmed user instructions to the catalog text', () => {
|
|
26
|
+
expect(composeWorkflowUserInstructions('Fill the document.', null)).toBe('Fill the document.');
|
|
27
|
+
expect(composeWorkflowUserInstructions('Fill the document.', ' ')).toBe('Fill the document.');
|
|
28
|
+
expect(composeWorkflowUserInstructions('Fill the document. ', ' Skip weekends. ')).toBe(
|
|
29
|
+
'Fill the document.\nUser instructions:\nSkip weekends.',
|
|
30
|
+
);
|
|
31
|
+
expect(composeWorkflowUserInstructions('', 'Skip weekends.')).toBe('User instructions:\nSkip weekends.');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe('isProgramFieldDoc', () => {
|
|
36
|
+
it('classifies docs by their owner organization and refuses unselected owners', () => {
|
|
37
|
+
expect(isProgramFieldDoc({ organizationId: null })).toBe(true);
|
|
38
|
+
expect(isProgramFieldDoc({ organizationId: 455 })).toBe(false);
|
|
39
|
+
expect(isProgramFieldDoc({ organizationId: 455n })).toBe(false);
|
|
40
|
+
expect(() => isProgramFieldDoc({} as { organizationId: null })).toThrow('FIELD_DOC_ORGANIZATION_ID_NOT_SELECTED');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('clampFieldDocSummary', () => {
|
|
45
|
+
it('keeps short summaries and drops blank ones', () => {
|
|
46
|
+
expect(clampFieldDocSummary(null)).toBeNull();
|
|
47
|
+
expect(clampFieldDocSummary(' ')).toBeNull();
|
|
48
|
+
expect(clampFieldDocSummary(' Saved answers. ')).toBe('Saved answers.');
|
|
49
|
+
expect(clampFieldDocSummary('a'.repeat(FIELD_DOC_SUMMARY_MAX))).toBe('a'.repeat(FIELD_DOC_SUMMARY_MAX));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('shortens long summaries to the stored character limit with an ellipsis', () => {
|
|
53
|
+
const clamped = clampFieldDocSummary('a'.repeat(FIELD_DOC_SUMMARY_MAX + 10));
|
|
54
|
+
expect(Array.from(clamped || '')).toHaveLength(FIELD_DOC_SUMMARY_MAX);
|
|
55
|
+
expect(clamped?.endsWith('a…')).toBe(true);
|
|
56
|
+
|
|
57
|
+
// Characters outside the BMP count once, as PostgreSQL counts them, and are never split
|
|
58
|
+
const astral = clampFieldDocSummary('🌡️'.repeat(FIELD_DOC_SUMMARY_MAX));
|
|
59
|
+
expect(Array.from(astral || '')).toHaveLength(FIELD_DOC_SUMMARY_MAX);
|
|
60
|
+
expect(astral).not.toMatch(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('field doc ids', () => {
|
|
65
|
+
it('builds answer and definition element ids from the generic id and the key', () => {
|
|
66
|
+
expect(getFieldDocAnswerId('9479647167134747', 'cooking_temp')).toBe('9479647167134747:cooking_temp');
|
|
67
|
+
expect(getFieldDocDefinitionElementId('9479647167134748', 'section_1')).toBe('9479647167134748:section_1');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('field doc answers', () => {
|
|
72
|
+
it('copies schemaVersion 2 answers and starts missing answers empty', () => {
|
|
73
|
+
const answers = {
|
|
74
|
+
schemaVersion: 2 as const,
|
|
75
|
+
questions: { temp: { value: 74, state: 'ANSWERED' as const, evidence: [], issues: [] } },
|
|
76
|
+
};
|
|
77
|
+
const copy = normalizeFieldDocAnswers(answers);
|
|
78
|
+
expect(copy).toEqual(answers);
|
|
79
|
+
expect(copy).not.toBe(answers);
|
|
80
|
+
expect(normalizeFieldDocAnswers(undefined)).toEqual({ schemaVersion: 2, questions: {} });
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('refuses answers that are not schemaVersion 2', () => {
|
|
84
|
+
expect(() => normalizeFieldDocAnswers({})).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
85
|
+
expect(() => normalizeFieldDocAnswers({ questions: {} })).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
86
|
+
expect(() => normalizeFieldDocAnswers({ schemaVersion: 2 })).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
87
|
+
expect(() => normalizeFieldDocAnswers({ schemaVersion: 2, questions: null })).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
88
|
+
expect(() => normalizeFieldDocAnswers({ schemaVersion: 2, questions: [] })).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
89
|
+
expect(() => normalizeFieldDocAnswers({ temp: 74, temp_note: 'Hot' })).toThrow('FIELD_DOC_ANSWERS_NOT_V2');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('reads answers by literal question key only', () => {
|
|
93
|
+
const answers = JSON.parse(
|
|
94
|
+
'{"schemaVersion":2,"questions":{"a":{"value":1,"state":"ANSWERED","evidence":[],"issues":[]},"__proto__":{"value":0,"state":"ANSWERED","evidence":[],"issues":[]}}}',
|
|
95
|
+
);
|
|
96
|
+
expect(getFieldDocAnswer(answers, 'a')?.value).toBe(1);
|
|
97
|
+
expect(getFieldDocAnswer(answers, '__proto__')?.value).toBe(0);
|
|
98
|
+
expect(getFieldDocAnswer(answers, 'a_note')).toBeUndefined();
|
|
99
|
+
expect(getFieldDocAnswer({ a: { value: 1 } }, 'a')).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('field doc program constants', () => {
|
|
104
|
+
it('accepts catalog codes and rejects invalid document names', () => {
|
|
105
|
+
for (const name of ['FS07', 'ccp1_cooking', 'SQF-2.4.3', 'a'.repeat(40)])
|
|
106
|
+
expect(FIELD_DOC_DOCUMENT_NAME_PATTERN.test(name)).toBe(true);
|
|
107
|
+
for (const name of ['', '_x', '-x', 'a b', 'a'.repeat(41)]) expect(FIELD_DOC_DOCUMENT_NAME_PATTERN.test(name)).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('uses only the canonical submission id variable in the default aside', () => {
|
|
111
|
+
const texts = FIELD_DOC_DEFAULT_ASIDE.flatMap((block) => block.items.map((item) => item.text));
|
|
112
|
+
expect(texts.filter((text) => /SubmissionId/.test(text))).toEqual(['{{fieldDocSubmissionId}}']);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { LogEntryDetailsFieldGQL, LogEntryGQL } from '../src/types/log.d.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Create typed saved values for resolver and renderer regression coverage.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function makeDisplayField(
|
|
8
|
+
key: string,
|
|
9
|
+
value: string | number | boolean | null,
|
|
10
|
+
fieldType = typeof value === 'number' ? 'NUMBER' : typeof value === 'boolean' ? 'BOOLEAN' : 'TEXT',
|
|
11
|
+
): LogEntryDetailsFieldGQL {
|
|
12
|
+
return {
|
|
13
|
+
key,
|
|
14
|
+
fieldType,
|
|
15
|
+
textValue: typeof value === 'string' ? value : null,
|
|
16
|
+
numberValue: typeof value === 'number' ? value : null,
|
|
17
|
+
booleanValue: typeof value === 'boolean' ? value : null,
|
|
18
|
+
dateValue: null,
|
|
19
|
+
datetimeValue: null,
|
|
20
|
+
unit: null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Build a complete minimal log so display tests exercise the actual GraphQL shape.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export function makeDisplayLog(activity = 'COOKING_TEMPERATURE', fields: LogEntryDetailsFieldGQL[] = []): LogEntryGQL {
|
|
29
|
+
return {
|
|
30
|
+
__typename: 'LogEntry',
|
|
31
|
+
id: 'log-1',
|
|
32
|
+
accountId: 'account-1',
|
|
33
|
+
organizationId: 'org-1',
|
|
34
|
+
childOrgId: null,
|
|
35
|
+
childOrgName: null,
|
|
36
|
+
inboundContactId: null,
|
|
37
|
+
inboundContactName: null,
|
|
38
|
+
fieldDocId: null,
|
|
39
|
+
fieldDocSubmissionId: null,
|
|
40
|
+
siteId: null,
|
|
41
|
+
location: 'Kitchen',
|
|
42
|
+
summary: 'Temperature reading',
|
|
43
|
+
translation: null,
|
|
44
|
+
account: null,
|
|
45
|
+
files: [],
|
|
46
|
+
date: '2026-10-09T12:00:00Z',
|
|
47
|
+
createdAt: '2026-10-09T12:00:00Z',
|
|
48
|
+
updatedAt: '2026-10-09T12:00:00Z',
|
|
49
|
+
details: {
|
|
50
|
+
__typename: 'LogEntryDetails',
|
|
51
|
+
id: 'details-1',
|
|
52
|
+
type: 'FOOD_PRODUCTION',
|
|
53
|
+
activity,
|
|
54
|
+
notes: '',
|
|
55
|
+
item: 'Bread',
|
|
56
|
+
quantity: null,
|
|
57
|
+
unit: null,
|
|
58
|
+
price: null,
|
|
59
|
+
values: null,
|
|
60
|
+
fields,
|
|
61
|
+
otherParty: null,
|
|
62
|
+
referenceNumber: null,
|
|
63
|
+
fieldLocation: null,
|
|
64
|
+
voided: null,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { beforeEach, expect, it } from 'vitest';
|
|
2
|
+
import i18n, { i18nTranslations } from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import type { LogDisplayRegistry } from '../src/types/logDisplay.types.ts';
|
|
4
|
+
import type { LogTaxonomyGQL } from '../src/types/log.d.ts';
|
|
5
|
+
import { buildLogEntryDisplay, resolveLogDisplayDefinition } from '../src/utils/logDisplay.ts';
|
|
6
|
+
import { makeDisplayField, makeDisplayLog } from './logDisplay.fixtures.ts';
|
|
7
|
+
import { LOG_DISPLAY_REGISTRY } from '../src/constants/logDisplay/index.ts';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Load the real English catalog so assertions check displayed labels rather than missing keys.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
i18n.replace(Object.fromEntries(Object.entries(i18nTranslations).map(([name, translations]) => [name, translations.en])));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('keeps every registered profile reference and translation valid', () => {
|
|
18
|
+
const registry: LogDisplayRegistry = LOG_DISPLAY_REGISTRY;
|
|
19
|
+
const definitions = [registry.defaults, ...Object.values(registry.shared)];
|
|
20
|
+
for (const operation of Object.values(registry.operations)) {
|
|
21
|
+
for (const scope of [operation.defaults, ...Object.values(operation.groups || {}), ...Object.values(operation.activities || {})]) {
|
|
22
|
+
if (!scope) continue;
|
|
23
|
+
definitions.push(scope);
|
|
24
|
+
for (const name of scope.profiles || []) expect(registry.shared[name], name).toBeDefined();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const definition of definitions) {
|
|
28
|
+
for (const field of Object.values(definition.fields || {})) {
|
|
29
|
+
if (field?.labelKey) expect(i18n.has(field.labelKey), field.labelKey).toBe(true);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it.each(['COOKING_TEMPERATURE', 'COOLING_TEMPERATURE'])(
|
|
35
|
+
'preserves the agreed %s layout with degree units and full rows',
|
|
36
|
+
(activity) => {
|
|
37
|
+
const logEntry = makeDisplayLog(activity, [
|
|
38
|
+
makeDisplayField('bottomTemperature', -2.5),
|
|
39
|
+
makeDisplayField('temperatureUnit', 'C'),
|
|
40
|
+
makeDisplayField('rackNumber', '003'),
|
|
41
|
+
makeDisplayField('middleTemperature', 0),
|
|
42
|
+
makeDisplayField('topTemperature', 74.5),
|
|
43
|
+
makeDisplayField('batchCode', 'B9'),
|
|
44
|
+
]);
|
|
45
|
+
const display = buildLogEntryDisplay({ logEntry, operation: 'FOOD_MANUFACTURING', timeZone: 'UTC' });
|
|
46
|
+
expect(display.rows.map((row) => row.key)).toEqual([
|
|
47
|
+
'date',
|
|
48
|
+
'logType',
|
|
49
|
+
'activity',
|
|
50
|
+
'item',
|
|
51
|
+
'field:rackNumber',
|
|
52
|
+
'field:topTemperature',
|
|
53
|
+
'field:middleTemperature',
|
|
54
|
+
'field:bottomTemperature',
|
|
55
|
+
'field:batchCode',
|
|
56
|
+
'location',
|
|
57
|
+
]);
|
|
58
|
+
expect(display.rows[0]?.value).toBe(new Date().getUTCFullYear() === 2026 ? '10/09, 12:00 PM' : '10/09/2026, 12:00 PM');
|
|
59
|
+
expect(display.rows.find((row) => row.key === 'item')?.label).toBe(i18n.t('c.product'));
|
|
60
|
+
expect(
|
|
61
|
+
display.rows.filter((row) => row.key.endsWith('Temperature')).map(({ label, value, span }) => ({ label, value, span })),
|
|
62
|
+
).toEqual([
|
|
63
|
+
{ label: i18n.t('log.rack_position.top'), value: '74.5 °C', span: 'full' },
|
|
64
|
+
{ label: i18n.t('log.rack_position.middle'), value: '0 °C', span: 'full' },
|
|
65
|
+
{ label: i18n.t('log.rack_position.bottom'), value: '-2.5 °C', span: 'full' },
|
|
66
|
+
]);
|
|
67
|
+
expect(display.rows.at(-1)?.span).toBe('full');
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
it('uses Product, Crop, and Item without leaking shared activity rules between operations', () => {
|
|
72
|
+
const logEntry = makeDisplayLog('COOKING_TEMPERATURE', [
|
|
73
|
+
makeDisplayField('topTemperature', 74),
|
|
74
|
+
makeDisplayField('temperatureUnit', 'F'),
|
|
75
|
+
]);
|
|
76
|
+
for (const [operation, labelKey] of [
|
|
77
|
+
['FOOD_MANUFACTURING', 'c.product'],
|
|
78
|
+
['ARABLE', 'c.crop'],
|
|
79
|
+
['FUTURE_OPERATION', 'c.item'],
|
|
80
|
+
]) {
|
|
81
|
+
const display = buildLogEntryDisplay({ logEntry, operation, timeZone: null });
|
|
82
|
+
expect(display.rows.find((row) => row.key === 'item')?.label).toBe(i18n.t(labelKey));
|
|
83
|
+
if (operation !== 'FOOD_MANUFACTURING') {
|
|
84
|
+
expect(display.rows.find((row) => row.key === 'field:temperatureUnit')?.value).toBe('F');
|
|
85
|
+
expect(display.rows.find((row) => row.key === 'field:topTemperature')?.span).toBe('half');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('resolves shared profiles before scoped overrides with explicit reset and no mutation', () => {
|
|
91
|
+
const registry: LogDisplayRegistry = {
|
|
92
|
+
defaults: { fields: { item: { labelKey: 'c.item', span: 'half' } } },
|
|
93
|
+
shared: { sharedReading: { fields: { item: { labelKey: 'c.quantity', hidden: true, span: 'full' } } } },
|
|
94
|
+
operations: {
|
|
95
|
+
ONE: {
|
|
96
|
+
defaults: { fields: { item: { labelKey: 'c.product' } } },
|
|
97
|
+
groups: { GROUP: { order: ['item', '*'], fields: { item: { labelKey: 'c.crop' } } } },
|
|
98
|
+
activities: {
|
|
99
|
+
SHARED_ACTIVITY: {
|
|
100
|
+
profiles: ['sharedReading'],
|
|
101
|
+
order: ['*', 'item'],
|
|
102
|
+
fields: { item: { labelKey: null, hidden: false, span: undefined } },
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
TWO: { activities: { SHARED_ACTIVITY: { profiles: ['sharedReading'], fields: { item: { labelKey: 'c.product' } } } } },
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
const before = structuredClone(registry);
|
|
110
|
+
const one = resolveLogDisplayDefinition({ operation: 'ONE', groupKey: 'GROUP', activityKey: 'SHARED_ACTIVITY' }, registry);
|
|
111
|
+
expect(one.fields.item).toEqual({ labelKey: null, hidden: false, span: 'full' });
|
|
112
|
+
expect(one.order).toEqual(['*', 'item']);
|
|
113
|
+
expect(resolveLogDisplayDefinition({ operation: 'ONE', groupKey: 'GROUP' }, registry).fields.item?.labelKey).toBe('c.crop');
|
|
114
|
+
expect(resolveLogDisplayDefinition({ operation: 'ONE' }, registry).fields.item?.labelKey).toBe('c.product');
|
|
115
|
+
expect(resolveLogDisplayDefinition({ operation: 'TWO', activityKey: 'SHARED_ACTIVITY' }, registry).fields.item).toMatchObject({
|
|
116
|
+
hidden: true,
|
|
117
|
+
labelKey: 'c.product',
|
|
118
|
+
});
|
|
119
|
+
expect(registry).toEqual(before);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('keeps historical custom fields, including colliding names, with one wildcard insertion', () => {
|
|
123
|
+
const logEntry = makeDisplayLog('FUTURE_ACTIVITY', [
|
|
124
|
+
makeDisplayField('item', 'Custom item'),
|
|
125
|
+
makeDisplayField('location', 'Custom location'),
|
|
126
|
+
makeDisplayField('retiredField', false),
|
|
127
|
+
makeDisplayField('flagColor', 'red'),
|
|
128
|
+
]);
|
|
129
|
+
const registry: LogDisplayRegistry = { defaults: { order: ['item', '*', '*', 'item', 'location'] }, shared: {}, operations: {} };
|
|
130
|
+
const display = buildLogEntryDisplay({ logEntry, operation: 'FUTURE_OPERATION', timeZone: null }, registry);
|
|
131
|
+
expect(display.rows.filter((row) => row.key === 'item')).toHaveLength(1);
|
|
132
|
+
expect(display.rows.find((row) => row.key === 'field:item')?.value).toBe('Custom item');
|
|
133
|
+
expect(display.rows.find((row) => row.key === 'field:location')?.value).toBe('Custom location');
|
|
134
|
+
expect(display.rows.find((row) => row.key === 'field:retiredField')?.value).toBe(i18n.t('c.no'));
|
|
135
|
+
expect(display.rows.at(-1)?.key).toBe('location');
|
|
136
|
+
const standard = buildLogEntryDisplay({ logEntry, timeZone: null });
|
|
137
|
+
expect(standard.rows.some((row) => row.key === 'field:flagColor')).toBe(false);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('retains unlisted fields without a wildcard and resets inherited labels to the generic label', () => {
|
|
141
|
+
const logEntry = makeDisplayLog('FUTURE_ACTIVITY', [makeDisplayField('newField', 'Saved')]);
|
|
142
|
+
const registry: LogDisplayRegistry = {
|
|
143
|
+
defaults: { order: ['item'], fields: { item: { labelKey: 'c.product' } } },
|
|
144
|
+
shared: {},
|
|
145
|
+
operations: { FUTURE: { defaults: { fields: { item: { labelKey: null } } } } },
|
|
146
|
+
};
|
|
147
|
+
const rows = buildLogEntryDisplay({ logEntry, operation: 'FUTURE', timeZone: null }, registry).rows;
|
|
148
|
+
expect(rows[0].label).toBe(i18n.t('c.item'));
|
|
149
|
+
expect(rows.find((row) => row.key === 'field:newField')?.value).toBe('Saved');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('keeps placeholders for missing readings and supports Fahrenheit without guessing a missing unit', () => {
|
|
153
|
+
const logEntry = makeDisplayLog('COOKING_TEMPERATURE', [
|
|
154
|
+
makeDisplayField('topTemperature', 165),
|
|
155
|
+
makeDisplayField('temperatureUnit', 'F'),
|
|
156
|
+
]);
|
|
157
|
+
const input = { logEntry, operation: 'FOOD_MANUFACTURING', timeZone: null };
|
|
158
|
+
expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:topTemperature')?.value).toBe('165 °F');
|
|
159
|
+
expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:middleTemperature')?.value).toBe('');
|
|
160
|
+
logEntry.details.fields = [makeDisplayField('topTemperature', 0)];
|
|
161
|
+
expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:topTemperature')?.value).toBe('0');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it.each([
|
|
165
|
+
['ARABLE', 'SEED_PURCHASE_INFO', 'purchaseInvoice'],
|
|
166
|
+
['ARABLE', 'OTHER_SUPPLY_PURCHASE_ACTIVITY', 'purchaseInvoice'],
|
|
167
|
+
['ARABLE', 'SALE_PRODUCE_ORDER', 'saleInvoice'],
|
|
168
|
+
['ARABLE', 'OTHER_SALE_ORDER', 'saleInvoice'],
|
|
169
|
+
['FARMERS_MARKET', 'MARKET_CREDIT_RECEIPT', 'receipt'],
|
|
170
|
+
['FOOD_MANUFACTURING', 'SALE_PRODUCE_ORDER', 'metadata'],
|
|
171
|
+
])('selects %s/%s as %s', (operation, activityKey, layout) => {
|
|
172
|
+
expect(resolveLogDisplayDefinition({ operation, activityKey }).layout).toBe(layout);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('uses matching taxonomy labels and ordering without hiding fields outside the current taxonomy', () => {
|
|
176
|
+
const taxonomy: LogTaxonomyGQL = {
|
|
177
|
+
operation: 'FUTURE',
|
|
178
|
+
groups: [{ key: 'CUSTOM_GROUP', label: 'Custom group label', ordinal: 0, requiredFields: null, orRequiredFields: null }],
|
|
179
|
+
activities: [
|
|
180
|
+
{
|
|
181
|
+
key: 'CUSTOM_ACTIVITY',
|
|
182
|
+
groupKey: 'CUSTOM_GROUP',
|
|
183
|
+
agentText: 'Custom activity label',
|
|
184
|
+
ordinal: 0,
|
|
185
|
+
requiredFields: null,
|
|
186
|
+
orRequiredFields: null,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
fieldDefs: [
|
|
190
|
+
{
|
|
191
|
+
key: 'orderedFirst',
|
|
192
|
+
fieldType: 'TEXT',
|
|
193
|
+
ordinal: 0,
|
|
194
|
+
required: false,
|
|
195
|
+
agentHint: null,
|
|
196
|
+
options: null,
|
|
197
|
+
allowedUnits: null,
|
|
198
|
+
groupKey: null,
|
|
199
|
+
activityKey: null,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
};
|
|
203
|
+
const logEntry = makeDisplayLog('CUSTOM_ACTIVITY', [
|
|
204
|
+
makeDisplayField('historicalField', 'Old'),
|
|
205
|
+
makeDisplayField('orderedFirst', 'First'),
|
|
206
|
+
]);
|
|
207
|
+
logEntry.details.type = null;
|
|
208
|
+
const rows = buildLogEntryDisplay({ logEntry, operation: 'FUTURE', taxonomy, timeZone: null }).rows;
|
|
209
|
+
expect(rows.find((row) => row.key === 'logType')?.value).toBe('Custom group label');
|
|
210
|
+
expect(rows.find((row) => row.key === 'activity')?.value).toBe('Custom activity label');
|
|
211
|
+
expect(rows.filter((row) => row.key.startsWith('field:')).map((row) => row.key)).toEqual([
|
|
212
|
+
'field:orderedFirst',
|
|
213
|
+
'field:historicalField',
|
|
214
|
+
]);
|
|
215
|
+
const other = buildLogEntryDisplay({ logEntry, operation: 'OTHER', taxonomy, timeZone: null });
|
|
216
|
+
expect(other.rows.find((row) => row.key === 'activity')?.value).toBe('Custom activity');
|
|
217
|
+
logEntry.details.type = 'HISTORICAL_GROUP';
|
|
218
|
+
expect(
|
|
219
|
+
buildLogEntryDisplay({ logEntry, operation: 'FUTURE', taxonomy, timeZone: null }).rows.find((row) => row.key === 'logType')
|
|
220
|
+
?.badgeGroupKey,
|
|
221
|
+
).toBe('HISTORICAL_GROUP');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('reports misspelled shared profile references instead of silently using the wrong layout', () => {
|
|
225
|
+
const registry: LogDisplayRegistry = { defaults: {}, shared: {}, operations: { ONE: { defaults: { profiles: ['missing'] } } } };
|
|
226
|
+
expect(() => resolveLogDisplayDefinition({ operation: 'ONE' }, registry)).toThrow('Unknown log display profile: missing');
|
|
227
|
+
});
|