|
| 1 | +// Copyright (c) 2026 ObjectStack contributors. Apache-2.0 license. |
| 2 | +// |
| 3 | +// objectstack#24916 — an approval flow's label and each approval step's label |
| 4 | +// join the flow bucket. |
| 5 | +// |
| 6 | +// The approvals door names a request's flow and its current step in the |
| 7 | +// READER's locale (`plugin-approvals` `reader-locale-labels.ts`), from |
| 8 | +// `flows.<flow>.label` and `flows.<flow>.approvals.<node_id>.label`. The walker |
| 9 | +// asked for the flow label only on a flow with a `screen` node, and for no |
| 10 | +// approval step at all, so `os lint` and `os i18n check` never listed an |
| 11 | +// approval flow as untranslated: HotCRM's six approval flows rendered English |
| 12 | +// in zh-CN / ja-JP / es-ES under a green coverage run. These pins are the CLI |
| 13 | +// half: the walker scaffolds both keys, the coverage gate demands them, and a |
| 14 | +// flow no reader names (no screen, no approval) still owes no label. |
| 15 | +// |
| 16 | +// The ledger mock is `i18n-flow-screen-coverage.test.ts`'s, for its reason: |
| 17 | +// these pins measure the bucket itself, whatever the shipped ledger says next. |
| 18 | + |
| 19 | +import { describe, it, expect, vi } from 'vitest'; |
| 20 | + |
| 21 | +vi.mock('@objectstack/lint', async (importOriginal) => ({ |
| 22 | + ...(await importOriginal<typeof import('@objectstack/lint')>()), |
| 23 | + authorWarnedProperties: () => new Set<string>(), |
| 24 | +})); |
| 25 | + |
| 26 | +import { collectExpectedEntries, extractTranslations } from '../src/utils/i18n-extract.js'; |
| 27 | +import { computeI18nCoverage } from '../src/utils/i18n-coverage.js'; |
| 28 | +import { TranslationDataSchema } from '@objectstack/spec/system'; |
| 29 | + |
| 30 | +/** An approval-only flow: record-triggered, two approval steps, no screen. */ |
| 31 | +const expenseApproval = { |
| 32 | + name: 'expense_approval', |
| 33 | + label: 'Expense Approval', |
| 34 | + type: 'autolaunched', |
| 35 | + nodes: [ |
| 36 | + { id: 'start', type: 'start', label: 'On Expense Created', config: { objectName: 'expense', triggerType: 'record-after-insert' } }, |
| 37 | + { id: 'manager_review', type: 'approval', label: 'Manager Review', config: { approvers: [{ type: 'org_membership_level', value: 'owner' }] } }, |
| 38 | + { id: 'finance_review', type: 'approval', label: 'Finance Review', config: { approvers: [{ type: 'org_membership_level', value: 'owner' }] } }, |
| 39 | + { id: 'approved', type: 'end', label: 'Approved' }, |
| 40 | + ], |
| 41 | + edges: [], |
| 42 | +}; |
| 43 | + |
| 44 | +/** A screen flow, the shape the bucket already covered. */ |
| 45 | +const quickNote = { |
| 46 | + name: 'quick_note', |
| 47 | + label: 'Quick Note', |
| 48 | + type: 'screen', |
| 49 | + nodes: [ |
| 50 | + { id: 'start', type: 'start', label: 'Start' }, |
| 51 | + { id: 'ask', type: 'screen', label: 'Ask', config: { title: 'Write a note', fields: [{ name: 'note', label: 'Note' }] } }, |
| 52 | + { id: 'done', type: 'end', label: 'Done' }, |
| 53 | + ], |
| 54 | + edges: [], |
| 55 | +}; |
| 56 | + |
| 57 | +/** A scheduled flow with no screen and no approval: no reader names it. */ |
| 58 | +const nightlyDigest = { |
| 59 | + name: 'nightly_digest', |
| 60 | + label: 'Nightly Digest', |
| 61 | + type: 'schedule', |
| 62 | + nodes: [ |
| 63 | + { id: 'start', type: 'start', label: 'Start' }, |
| 64 | + { id: 'mail', type: 'send_email', label: 'Mail' }, |
| 65 | + ], |
| 66 | + edges: [], |
| 67 | +}; |
| 68 | + |
| 69 | +const flowKeys = (config: any) => |
| 70 | + collectExpectedEntries(config).filter((e) => e.path[0] === 'flows').map((e) => e.path.join('.')); |
| 71 | + |
| 72 | +describe('what the walker harvests from an approval flow (#24916)', () => { |
| 73 | + it('emits the flow label and each approval step label, seeded with the authored text', () => { |
| 74 | + const entries = collectExpectedEntries({ flows: [expenseApproval] }).filter((e) => e.path[0] === 'flows'); |
| 75 | + |
| 76 | + expect(entries.map((e) => e.path.join('.'))).toEqual([ |
| 77 | + 'flows.expense_approval.label', |
| 78 | + 'flows.expense_approval.approvals.manager_review.label', |
| 79 | + 'flows.expense_approval.approvals.finance_review.label', |
| 80 | + ]); |
| 81 | + expect(entries[0]).toMatchObject({ sourceValue: 'Expense Approval', inline: 'Expense Approval', source: 'flow', flowName: 'expense_approval' }); |
| 82 | + expect(entries[1]).toMatchObject({ sourceValue: 'Manager Review', inline: 'Manager Review', source: 'flow', flowName: 'expense_approval' }); |
| 83 | + }); |
| 84 | + |
| 85 | + it('skips an approval node with no id: the request could not name it', () => { |
| 86 | + const flow = { ...expenseApproval, nodes: [{ type: 'approval', label: 'Anonymous Review' }] }; |
| 87 | + expect(flowKeys({ flows: [flow] })).toEqual(['flows.expense_approval.label']); |
| 88 | + }); |
| 89 | + |
| 90 | + it('still emits no label for a flow with neither a screen nor an approval node', () => { |
| 91 | + expect(flowKeys({ flows: [nightlyDigest] })).toEqual([]); |
| 92 | + }); |
| 93 | +}); |
| 94 | + |
| 95 | +describe('the coverage gate demands the approval flow and its steps (#24916)', () => { |
| 96 | + const tree = (flows?: Record<string, unknown>) => ({ |
| 97 | + i18n: { defaultLocale: 'en', supportedLocales: ['en', 'zh-CN'] }, |
| 98 | + flows: [expenseApproval, quickNote, nightlyDigest], |
| 99 | + translations: [{ 'zh-CN': { ...(flows ? { flows } : {}) } }], |
| 100 | + }); |
| 101 | + const zhFlowIssues = (config: any) => |
| 102 | + computeI18nCoverage(config).issues.filter((i) => i.locale === 'zh-CN' && i.source === 'flow'); |
| 103 | + |
| 104 | + it('lists the untranslated approval flow label and step labels in the flow bucket', () => { |
| 105 | + const keys = zhFlowIssues(tree()).map((i) => i.key).filter((k) => k.startsWith('flows.expense_approval.')); |
| 106 | + expect(keys).toEqual([ |
| 107 | + 'flows.expense_approval.label', |
| 108 | + 'flows.expense_approval.approvals.manager_review.label', |
| 109 | + 'flows.expense_approval.approvals.finance_review.label', |
| 110 | + ]); |
| 111 | + }); |
| 112 | + |
| 113 | + it('keeps the step labels listed while only the flow label is translated', () => { |
| 114 | + const keys = zhFlowIssues(tree({ expense_approval: { label: '报销审批' } })) |
| 115 | + .map((i) => i.key) |
| 116 | + .filter((k) => k.startsWith('flows.expense_approval.')); |
| 117 | + expect(keys).toEqual([ |
| 118 | + 'flows.expense_approval.approvals.manager_review.label', |
| 119 | + 'flows.expense_approval.approvals.finance_review.label', |
| 120 | + ]); |
| 121 | + }); |
| 122 | + |
| 123 | + it('goes quiet for the approval flow once its label and every step are translated', () => { |
| 124 | + const keys = zhFlowIssues(tree({ |
| 125 | + expense_approval: { |
| 126 | + label: '报销审批', |
| 127 | + approvals: { manager_review: { label: '经理审核' }, finance_review: { label: '财务审核' } }, |
| 128 | + }, |
| 129 | + })).map((i) => i.key); |
| 130 | + expect(keys.filter((k) => k.startsWith('flows.expense_approval.'))).toEqual([]); |
| 131 | + }); |
| 132 | + |
| 133 | + it('keeps the screen flow\'s demand exactly as it was, and asks nothing of the scheduled flow', () => { |
| 134 | + const keys = zhFlowIssues(tree()).map((i) => i.key); |
| 135 | + expect(keys.filter((k) => k.startsWith('flows.quick_note.'))).toEqual([ |
| 136 | + 'flows.quick_note.label', |
| 137 | + 'flows.quick_note.screens.ask.title', |
| 138 | + 'flows.quick_note.screens.ask.fields.note.label', |
| 139 | + ]); |
| 140 | + expect(keys.filter((k) => k.startsWith('flows.nightly_digest.'))).toEqual([]); |
| 141 | + }); |
| 142 | + |
| 143 | + it('accepts the translated pack the way the translation contract declares it', () => { |
| 144 | + // The key the gate asks for is one the face declares: the translation that |
| 145 | + // silences it parses with no unrecognized key. |
| 146 | + const parsed = TranslationDataSchema.safeParse({ |
| 147 | + flows: { expense_approval: { label: '报销审批', approvals: { manager_review: { label: '经理审核' } } } }, |
| 148 | + }); |
| 149 | + expect(parsed.success ? [] : parsed.error.issues).toEqual([]); |
| 150 | + }); |
| 151 | +}); |
| 152 | + |
| 153 | +describe('the skeleton `os i18n extract` writes for an approval flow (#24916)', () => { |
| 154 | + const result = extractTranslations({ flows: [expenseApproval] }, { locales: ['en', 'zh-CN'] }); |
| 155 | + |
| 156 | + it('writes the authored labels into the default locale and empty slots into the others', () => { |
| 157 | + expect((result.bundles.en as any).flows.expense_approval).toEqual({ |
| 158 | + label: 'Expense Approval', |
| 159 | + approvals: { manager_review: { label: 'Manager Review' }, finance_review: { label: 'Finance Review' } }, |
| 160 | + }); |
| 161 | + expect((result.bundles['zh-CN'] as any).flows.expense_approval).toEqual({ |
| 162 | + label: '', |
| 163 | + approvals: { manager_review: { label: '' }, finance_review: { label: '' } }, |
| 164 | + }); |
| 165 | + }); |
| 166 | + |
| 167 | + it('parses through the schema it is written for, in every locale', () => { |
| 168 | + for (const [locale, bundle] of Object.entries(result.bundles)) { |
| 169 | + const parsed = TranslationDataSchema.safeParse(bundle); |
| 170 | + expect(parsed.success ? [] : parsed.error.issues, `skeleton for ${locale}`).toEqual([]); |
| 171 | + } |
| 172 | + }); |
| 173 | +}); |
0 commit comments