react-native-live-widgets 1.2.1 → 1.2.3
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/CHANGELOG.md +37 -0
- package/README.md +89 -49
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +86 -13
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +647 -104
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +3 -1
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
- package/app.plugin.js +36 -0
- package/assets/MaterialIcons.json +2236 -0
- package/cli/codegen.js +889 -0
- package/cli/setup.js +323 -63
- package/docs/EXPO-GUIDE-EN.md +21 -3
- package/docs/EXPO-GUIDE-VI.md +21 -3
- package/docs/GUIDE-EN.md +203 -21
- package/docs/GUIDE-VI.md +207 -22
- package/docs/index.html +1461 -226
- package/docs/llms-full.txt +15 -0
- package/docs/llms.txt +16 -7
- package/ios/Bridge/LiveActivityModule.swift +333 -44
- package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
- package/ios/Models/DynamicLayoutModels.swift +114 -4
- package/ios/Renderer/DynamicNodeView.swift +15 -6
- package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
- package/ios/Widgets/DynamicControlWidget.swift +63 -0
- package/ios/Widgets/DynamicHomeScreenWidget.swift +99 -26
- package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
- package/lib/builder.d.ts +50 -7
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +326 -18
- package/lib/builder.js.map +1 -1
- package/lib/hooks.d.ts +13 -9
- package/lib/hooks.d.ts.map +1 -1
- package/lib/hooks.js +70 -12
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +80 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +303 -59
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts.map +1 -1
- package/lib/ir.js +9 -2
- package/lib/ir.js.map +1 -1
- package/lib/jsx.d.ts +11 -7
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +50 -13
- package/lib/jsx.js.map +1 -1
- package/lib/material-icons.generated.d.ts +8 -0
- package/lib/material-icons.generated.d.ts.map +1 -0
- package/lib/material-icons.generated.js +9 -0
- package/lib/material-icons.generated.js.map +1 -0
- package/lib/preview.d.ts +11 -4
- package/lib/preview.d.ts.map +1 -1
- package/lib/preview.js +150 -82
- package/lib/preview.js.map +1 -1
- package/lib/sf-symbols.generated.d.ts +8 -0
- package/lib/sf-symbols.generated.d.ts.map +1 -0
- package/lib/sf-symbols.generated.js +9 -0
- package/lib/sf-symbols.generated.js.map +1 -0
- package/lib/types.d.ts +302 -18
- package/lib/types.d.ts.map +1 -1
- package/package.json +6 -2
- package/scripts/build.js +98 -0
- package/scripts/generate-material-icons.js +93 -0
- package/scripts/generate-sf-symbols.js +95 -0
- package/scripts/release.js +115 -0
- package/scripts/test-ir-semantic.js +314 -0
- package/src/builder.ts +382 -24
- package/src/hooks.ts +88 -12
- package/src/index.ts +319 -56
- package/src/ir.ts +8 -2
- package/src/jsx.tsx +69 -21
- package/src/material-icons.generated.ts +3844 -0
- package/src/preview.tsx +235 -81
- package/src/sf-symbols.generated.ts +9533 -0
- package/src/types.ts +348 -18
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 🧪 Test Suite for UI Intermediate Representation (IR) & Semantic Tree (Phase 2 & Phase 6)
|
|
5
|
+
* Verifies:
|
|
6
|
+
* 1. AST compilation & unique ID indexing.
|
|
7
|
+
* 2. Semantic Tree generation & TalkBack synthesis.
|
|
8
|
+
* 3. Decorative node suppression.
|
|
9
|
+
* 4. Renderer Planner target classification (Native-first, Canvas-when-needed).
|
|
10
|
+
* 5. State Bindings identification (Two-Way Sync).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const assert = require('assert');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
// Run tests against the compiled lib/
|
|
18
|
+
const { compileToIR, inspectIR } = require('../lib/ir');
|
|
19
|
+
const {
|
|
20
|
+
UI,
|
|
21
|
+
createDataBinding,
|
|
22
|
+
flattenDataObject,
|
|
23
|
+
resolveTemplateString,
|
|
24
|
+
} = require('../lib/builder');
|
|
25
|
+
const { actionHandlers } = require('../lib/dispatcher');
|
|
26
|
+
|
|
27
|
+
console.log('🧪 [Test Suite] Running UI IR & Semantic Tree Test Suite...');
|
|
28
|
+
|
|
29
|
+
// ── Test 1: Full Architecture Compilation ────────────────────────────────────
|
|
30
|
+
console.log(' ✓ Test 1: Compiling complex layout into IR v2.0...');
|
|
31
|
+
const complexLayout = UI.VStack(
|
|
32
|
+
{ padding: 16, backgroundColor: '#0F172A' },
|
|
33
|
+
UI.Text('BẢNG ĐIỀU KHIỂN CHẤM CÔNG', { typography: 'title2' }),
|
|
34
|
+
UI.Progress({ value: 0.86, accessibilityLabel: 'Tiến độ hoàn thành ca' }),
|
|
35
|
+
UI.Button({ title: 'Xác nhận vào ca', actionId: 'toggle:attendance_shift' }),
|
|
36
|
+
UI.Gauge({ value: 0.95, label: 'KPI' }),
|
|
37
|
+
UI.Image('sparkles', { accessible: false }) // Decorative image
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const ir = compileToIR(complexLayout);
|
|
41
|
+
|
|
42
|
+
assert.strictEqual(ir.version, '2.0', 'IR version must be 2.0');
|
|
43
|
+
assert(ir.timestamp > 0, 'IR must include a timestamp');
|
|
44
|
+
assert(Array.isArray(ir.semanticTree), 'Semantic tree must be an array');
|
|
45
|
+
assert(typeof ir.semanticSummary === 'string', 'Semantic summary must be a string');
|
|
46
|
+
console.log(' -> Generated IR with', ir.semanticTree.length, 'semantic nodes.');
|
|
47
|
+
|
|
48
|
+
// ── Test 2: Decorative Elements Suppression ──────────────────────────────────
|
|
49
|
+
console.log(' ✓ Test 2: Verifying decorative elements are excluded from TalkBack summary...');
|
|
50
|
+
const hasDecorativeInTree = ir.semanticTree.some((n) => n.isDecorative === true);
|
|
51
|
+
assert.strictEqual(hasDecorativeInTree, false, 'Decorative elements must not be in active semantic tree');
|
|
52
|
+
assert(!ir.semanticSummary.includes('sparkles'), 'Decorative image sparkles must not appear in spoken summary');
|
|
53
|
+
|
|
54
|
+
// ── Test 3: Renderer Planner Target Classification ───────────────────────────
|
|
55
|
+
console.log(' ✓ Test 3: Verifying Renderer Planner (Native-first vs Canvas-when-needed)...');
|
|
56
|
+
const plan = ir.renderPlan;
|
|
57
|
+
assert.strictEqual(plan.overallStrategy, 'native_first_hybrid', 'Strategy should be native_first_hybrid');
|
|
58
|
+
assert(plan.nativeNodeCount >= 3, 'Should identify at least 3 native RemoteViews nodes (Text, Progress, Button)');
|
|
59
|
+
assert(plan.canvasNodeCount >= 1, 'Should identify at least 1 canvas node (Gauge)');
|
|
60
|
+
|
|
61
|
+
// Check specific nodes in the plan
|
|
62
|
+
const nodes = Object.values(plan.nodes);
|
|
63
|
+
const textPlan = nodes.find((n) => n.type === 'Text');
|
|
64
|
+
assert.strictEqual(textPlan.target, 'native_remote_view', 'Text must be native_remote_view');
|
|
65
|
+
|
|
66
|
+
const buttonPlan = nodes.find((n) => n.type === 'Button');
|
|
67
|
+
assert.strictEqual(buttonPlan.target, 'native_remote_view', 'Button must be native_remote_view');
|
|
68
|
+
|
|
69
|
+
const gaugePlan = nodes.find((n) => n.type === 'Gauge');
|
|
70
|
+
assert.strictEqual(gaugePlan.target, 'canvas_bitmap', 'Gauge must be canvas_bitmap');
|
|
71
|
+
|
|
72
|
+
// ── Test 4: State Bindings Identification ────────────────────────────────────
|
|
73
|
+
console.log(' ✓ Test 4: Verifying Two-Way State Bindings extraction...');
|
|
74
|
+
assert(ir.stateBindings.length >= 1, 'Should extract state bindings for interactive buttons');
|
|
75
|
+
const toggleBinding = ir.stateBindings.find((b) => b.actionId === 'toggle:attendance_shift');
|
|
76
|
+
assert(toggleBinding, 'Should find toggle:attendance_shift binding');
|
|
77
|
+
assert.strictEqual(toggleBinding.bindingType, 'toggle', 'Binding type must be toggle');
|
|
78
|
+
assert.strictEqual(toggleBinding.targetKey, 'attendance_shift', 'Target key must match');
|
|
79
|
+
|
|
80
|
+
// ── Test 5: Speech Synthesizer Output ────────────────────────────────────────
|
|
81
|
+
console.log(' ✓ Test 5: Verifying synthesized speech summary...');
|
|
82
|
+
assert(ir.semanticSummary.includes('BẢNG ĐIỀU KHIỂN CHẤM CÔNG'), 'Summary must contain heading');
|
|
83
|
+
assert(ir.semanticSummary.includes('86%'), 'Summary must contain progress percentage');
|
|
84
|
+
assert(ir.semanticSummary.includes('Xác nhận vào ca'), 'Summary must contain button title');
|
|
85
|
+
assert(ir.semanticSummary.includes('KPI'), 'Summary must contain gauge label');
|
|
86
|
+
|
|
87
|
+
// ── Test 6: inspectIR utility output ─────────────────────────────────────────
|
|
88
|
+
console.log(' ✓ Test 6: Verifying inspectIR() ASCII formatting...');
|
|
89
|
+
const inspectOutput = inspectIR(complexLayout);
|
|
90
|
+
assert(inspectOutput.includes('[NATIVE]'), 'inspectIR must output [NATIVE] tags');
|
|
91
|
+
assert(inspectOutput.includes('[CANVAS]'), 'inspectIR must output [CANVAS] tags');
|
|
92
|
+
assert(inspectOutput.includes('🌲 Widget IR v2.0'), 'inspectIR must output header');
|
|
93
|
+
|
|
94
|
+
// ── Test 7: Extended Families (extraLarge, standBy) & widgetAccentable ────────
|
|
95
|
+
console.log(' ✓ Test 7: Verifying widgetAccentable & extended family layout nodes...');
|
|
96
|
+
const standByLayout = UI.VStack(
|
|
97
|
+
{ padding: 12, backgroundColor: '#000000' },
|
|
98
|
+
UI.Text('08:30', { fontSize: 32, widgetAccentable: true }),
|
|
99
|
+
UI.Progress({ value: 0.72, widgetAccentable: true }),
|
|
100
|
+
UI.Gauge({ value: 0.9, label: 'Focus', widgetAccentable: true })
|
|
101
|
+
);
|
|
102
|
+
const extraLargeLayout = UI.VStack(
|
|
103
|
+
{ padding: 20, backgroundColor: '#0F172A' },
|
|
104
|
+
UI.Text('Bảng tổng hợp iPadOS Extra Large', { typography: 'title1' }),
|
|
105
|
+
standByLayout
|
|
106
|
+
);
|
|
107
|
+
const extendedConfig = {
|
|
108
|
+
small: UI.VStack(UI.Text('Small')),
|
|
109
|
+
extraLarge: extraLargeLayout,
|
|
110
|
+
standBy: standByLayout,
|
|
111
|
+
};
|
|
112
|
+
assert(extendedConfig.extraLarge.type === 'VStack', 'extraLarge layout must be valid');
|
|
113
|
+
assert(extendedConfig.standBy.type === 'VStack', 'standBy layout must be valid');
|
|
114
|
+
assert.strictEqual(standByLayout.children[0].props.widgetAccentable, true, 'Text must preserve widgetAccentable');
|
|
115
|
+
assert.strictEqual(standByLayout.children[1].props.widgetAccentable, true, 'Progress must preserve widgetAccentable');
|
|
116
|
+
assert.strictEqual(standByLayout.children[2].props.widgetAccentable, true, 'Gauge must preserve widgetAccentable');
|
|
117
|
+
|
|
118
|
+
const standByIR = compileToIR(standByLayout);
|
|
119
|
+
assert(standByIR.semanticSummary.includes('08:30'), 'standBy IR summary must include text');
|
|
120
|
+
|
|
121
|
+
// ── Test 8: ControlWidget DSL Helpers & Export Declarations ──────────────────
|
|
122
|
+
console.log(' ✓ Test 8: Verifying UI.ControlButton, UI.ControlToggle & exported types...');
|
|
123
|
+
let controlCallbackTriggered = false;
|
|
124
|
+
const ctrlBtn = UI.ControlButton({
|
|
125
|
+
title: 'Check-in nhanh',
|
|
126
|
+
systemName: 'bolt.fill',
|
|
127
|
+
actionId: 'quick_checkin',
|
|
128
|
+
onPress: () => {
|
|
129
|
+
controlCallbackTriggered = true;
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
assert.strictEqual(ctrlBtn.type, 'button', 'ControlButton type must be button');
|
|
133
|
+
assert.strictEqual(ctrlBtn.actionId, 'quick_checkin', 'ControlButton must keep explicit actionId');
|
|
134
|
+
assert.strictEqual('onPress' in ctrlBtn, false, 'Serialized ControlWidgetConfig must strip onPress function');
|
|
135
|
+
assert(actionHandlers.has('quick_checkin'), 'ControlButton onPress must register in actionHandlers');
|
|
136
|
+
actionHandlers.get('quick_checkin')({ actionId: 'quick_checkin' });
|
|
137
|
+
assert.strictEqual(controlCallbackTriggered, true, 'Registered ControlButton handler must execute');
|
|
138
|
+
|
|
139
|
+
const ctrlToggle = UI.ControlToggle({
|
|
140
|
+
title: 'Tạm nghỉ',
|
|
141
|
+
checkedTitle: 'Đang làm việc',
|
|
142
|
+
systemName: 'clock.badge.checkmark.fill',
|
|
143
|
+
checked: true,
|
|
144
|
+
actionId: 'shift_active',
|
|
145
|
+
});
|
|
146
|
+
assert.strictEqual(ctrlToggle.type, 'toggle', 'ControlToggle type must be toggle');
|
|
147
|
+
assert.strictEqual(ctrlToggle.actionId, 'toggle:shift_active', 'ControlToggle must ensure toggle: prefix');
|
|
148
|
+
assert.strictEqual(ctrlToggle.checked, true, 'ControlToggle must preserve checked flag');
|
|
149
|
+
|
|
150
|
+
const indexDts = fs.readFileSync(path.join(__dirname, '../lib/index.d.ts'), 'utf8');
|
|
151
|
+
const previewDts = fs.readFileSync(path.join(__dirname, '../lib/preview.d.ts'), 'utf8');
|
|
152
|
+
const typesDts = fs.readFileSync(path.join(__dirname, '../lib/types.d.ts'), 'utf8');
|
|
153
|
+
assert(indexDts.includes('export declare const ControlWidget'), 'lib/index.d.ts must export ControlWidget');
|
|
154
|
+
assert(previewDts.includes("'control'") && previewDts.includes('controlConfig?: ControlWidgetConfig'), 'lib/preview.d.ts must include control preview size and prop');
|
|
155
|
+
assert(typesDts.includes('extraLarge?: LayoutNode') && typesDts.includes('standBy?: LayoutNode'), 'lib/types.d.ts must include extraLarge and standBy');
|
|
156
|
+
|
|
157
|
+
// ── Test 9: Background Data Engine 2.0 & Structured Data Binding ──────────────
|
|
158
|
+
console.log(' ✓ Test 9: Verifying createDataBinding, flattenDataObject & pipe transforms...');
|
|
159
|
+
const data = createDataBinding({
|
|
160
|
+
defaults: { user: { name: 'Khách' }, attendance: { progress: 0 } },
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
const boundLayout = UI.VStack(
|
|
164
|
+
{ padding: 14 },
|
|
165
|
+
UI.Text(data.user.name),
|
|
166
|
+
UI.Text(`${data.attendance.progress}%`),
|
|
167
|
+
UI.Progress(data.attendance.progress.divide(100)),
|
|
168
|
+
UI.Gauge(data.attendance.progress.divide(100), { label: 'KPI' }),
|
|
169
|
+
UI.Text(UI.bind('salary', { currency: '₫' }))
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
assert.strictEqual(boundLayout.children[0].props.text, '{{user.name|default:Khách}}');
|
|
173
|
+
assert.strictEqual(boundLayout.children[1].props.text, '{{attendance.progress|default:0}}%');
|
|
174
|
+
assert.strictEqual(boundLayout.children[2].props.value, '{{attendance.progress|default:0|divide:100}}');
|
|
175
|
+
assert.strictEqual(boundLayout.children[3].props.value, '{{attendance.progress|default:0|divide:100}}');
|
|
176
|
+
assert.strictEqual(boundLayout.children[4].props.text, '{{salary|currency:₫}}');
|
|
177
|
+
|
|
178
|
+
const plainData = createDataBinding();
|
|
179
|
+
assert.strictEqual(
|
|
180
|
+
plainData.attendance.progress.divide(100).toToken(),
|
|
181
|
+
'{{attendance.progress|divide:100}}'
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const flatVars = flattenDataObject({
|
|
185
|
+
user: { name: 'Vũ Trần' },
|
|
186
|
+
attendance: { progress: 85, onTime: true },
|
|
187
|
+
salary: 15000000,
|
|
188
|
+
items: [{ title: 'OKR Q4' }],
|
|
189
|
+
});
|
|
190
|
+
assert.strictEqual(flatVars['user.name'], 'Vũ Trần');
|
|
191
|
+
assert.strictEqual(flatVars['attendance.progress'], '85');
|
|
192
|
+
assert.strictEqual(flatVars['attendance.onTime'], 'true');
|
|
193
|
+
assert.strictEqual(flatVars['items.0.title'], 'OKR Q4');
|
|
194
|
+
|
|
195
|
+
assert.strictEqual(resolveTemplateString('{{user.name|upper}}', flatVars), 'VŨ TRẦN');
|
|
196
|
+
assert.strictEqual(resolveTemplateString('{{user.role|default:Nhân viên}}', flatVars), 'Nhân viên');
|
|
197
|
+
assert.strictEqual(resolveTemplateString('{{attendance.progress|divide:100}}', flatVars), '0.85');
|
|
198
|
+
assert.strictEqual(resolveTemplateString('{{attendance.progress|divide:100|multiply:100|round:0}}', flatVars), '85');
|
|
199
|
+
assert.strictEqual(resolveTemplateString('{{attendance.progress|percent:0}}', flatVars), '85%');
|
|
200
|
+
assert.strictEqual(resolveTemplateString('{{attendance.onTime|if:Đúng giờ:Đi trễ}}', flatVars), 'Đúng giờ');
|
|
201
|
+
assert.strictEqual(resolveTemplateString('{{salary|currency:₫}}', flatVars), '15,000,000₫');
|
|
202
|
+
assert.strictEqual(
|
|
203
|
+
resolveTemplateString('{{wrapped|divide:100}}', { wrapped: '{{92}}' }),
|
|
204
|
+
'0.92',
|
|
205
|
+
'Stale {{...}} wrapped values must unwrap cleanly before pipe math'
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
assert(
|
|
209
|
+
typesDts.includes('cacheTtlSeconds?: number') &&
|
|
210
|
+
typesDts.includes('enableETag?: boolean') &&
|
|
211
|
+
typesDts.includes('authRefresh?: WidgetAuthRefreshConfig'),
|
|
212
|
+
'lib/types.d.ts must include Background Data Engine 2.0 fields'
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// ── Test 10: Widget Codegen Swift Generator ──────────────────────────────────
|
|
216
|
+
console.log(' ✓ Test 10: Verifying TypeScript-driven Swift Codegen (generateSwiftSource)...');
|
|
217
|
+
const { generateSwiftSource } = require('../cli/codegen');
|
|
218
|
+
const testConfig = {
|
|
219
|
+
bundleName: 'TestLiveWidgetsBundle',
|
|
220
|
+
liveActivity: true,
|
|
221
|
+
controlWidgets: true,
|
|
222
|
+
widgets: [
|
|
223
|
+
{
|
|
224
|
+
key: 'main',
|
|
225
|
+
kind: 'DynamicHomeScreenWidget',
|
|
226
|
+
displayName: 'Tiện ích chính',
|
|
227
|
+
description: 'Mô tả tiện ích chính',
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
key: 'counter',
|
|
231
|
+
displayName: 'Bộ đếm',
|
|
232
|
+
supportedFamilies: ['systemSmall', 'systemMedium'],
|
|
233
|
+
standbyMargins: true,
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const swiftCode = generateSwiftSource(testConfig);
|
|
239
|
+
assert(swiftCode.includes('struct TestLiveWidgetsBundle: WidgetBundle'));
|
|
240
|
+
assert(swiftCode.includes('DynamicLiveActivityWidget()'));
|
|
241
|
+
assert(swiftCode.includes('DynamicHomeScreenWidget()'));
|
|
242
|
+
assert(swiftCode.includes('CounterHomeScreenWidget()'));
|
|
243
|
+
assert(swiftCode.includes('DynamicControlWidget()'));
|
|
244
|
+
assert(swiftCode.includes('struct DynamicHomeScreenWidget: Widget'));
|
|
245
|
+
assert(swiftCode.includes('struct CounterHomeScreenWidget: Widget'));
|
|
246
|
+
assert(swiftCode.includes('DynamicWidgetProvider(widgetKey: "counter")'));
|
|
247
|
+
assert(swiftCode.includes('.supportedFamilies([.systemSmall, .systemMedium])'));
|
|
248
|
+
assert(swiftCode.includes('.applyStandByMargins()'));
|
|
249
|
+
|
|
250
|
+
// ── Test 11: i18n Catalog & String Catalog Generator ─────────────────────────
|
|
251
|
+
console.log(' ✓ Test 11: Verifying i18n Catalog & LocalizedStringKey...');
|
|
252
|
+
const { buildI18nCatalog, flattenObject } = require('../cli/codegen');
|
|
253
|
+
const flatTest = flattenObject({
|
|
254
|
+
widgets: {
|
|
255
|
+
counter: { title: 'Bộ đếm', desc: 'Bấm nút để đếm' },
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
assert.strictEqual(flatTest['widgets.counter.title'], 'Bộ đếm');
|
|
259
|
+
assert.strictEqual(flatTest['widgets.counter.desc'], 'Bấm nút để đếm');
|
|
260
|
+
|
|
261
|
+
const i18nTestConfig = {
|
|
262
|
+
i18n: {
|
|
263
|
+
defaultLocale: 'vi',
|
|
264
|
+
translations: {
|
|
265
|
+
vi: { 'widgets.counter.title': 'Bộ đếm (VI)' },
|
|
266
|
+
en: { 'widgets.counter.title': 'Counter (EN)' },
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
widgets: [
|
|
270
|
+
{
|
|
271
|
+
key: 'counter',
|
|
272
|
+
displayName: 'widgets.counter.title',
|
|
273
|
+
description: {
|
|
274
|
+
vi: 'Mô tả tiếng Việt',
|
|
275
|
+
en: 'English description',
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const { catalog, defaultLocale } = buildI18nCatalog(process.cwd(), i18nTestConfig);
|
|
282
|
+
assert.strictEqual(catalog.vi['widgets.counter.title'], 'Bộ đếm (VI)');
|
|
283
|
+
assert.strictEqual(catalog.en['widgets.counter.title'], 'Counter (EN)');
|
|
284
|
+
assert.strictEqual(catalog.vi['widget.counter.desc'], 'Mô tả tiếng Việt');
|
|
285
|
+
assert.strictEqual(catalog.en['widget.counter.desc'], 'English description');
|
|
286
|
+
|
|
287
|
+
const i18nSwiftCode = generateSwiftSource(i18nTestConfig, catalog, defaultLocale);
|
|
288
|
+
assert(i18nSwiftCode.includes('.configurationDisplayName(LocalizedStringKey("widgets.counter.title"))'));
|
|
289
|
+
assert(i18nSwiftCode.includes('.description(LocalizedStringKey("widget.counter.desc"))'));
|
|
290
|
+
|
|
291
|
+
// ── Test 12: Android i18n strings.xml Resource Mapping ───────────────────────
|
|
292
|
+
console.log(' ✓ Test 12: Verifying Android i18n Resource Mapping (toAndroidStringName)...');
|
|
293
|
+
const { toAndroidStringName, ensureExtensionInfoPlist } = require('../cli/codegen');
|
|
294
|
+
assert.strictEqual(toAndroidStringName('widgets.counter.title'), 'widgets_counter_title');
|
|
295
|
+
assert.strictEqual(toAndroidStringName('widgets.shift-attendance.desc'), 'widgets_shift_attendance_desc');
|
|
296
|
+
assert.strictEqual(toAndroidStringName('123.kpi'), 'str_123_kpi');
|
|
297
|
+
|
|
298
|
+
// ── Test 13: Extension Info.plist Auto-generation ───────────────────────────
|
|
299
|
+
console.log(' ✓ Test 13: Verifying Extension Info.plist auto-generation (ensureExtensionInfoPlist)...');
|
|
300
|
+
const os = require('os');
|
|
301
|
+
const tmpTestDir = path.join(os.tmpdir(), 'live_widget_test_' + Date.now());
|
|
302
|
+
fs.mkdirSync(tmpTestDir, { recursive: true });
|
|
303
|
+
try {
|
|
304
|
+
ensureExtensionInfoPlist(tmpTestDir);
|
|
305
|
+
const generatedPlistPath = path.join(tmpTestDir, 'Info.plist');
|
|
306
|
+
assert(fs.existsSync(generatedPlistPath), 'Info.plist should be generated');
|
|
307
|
+
const plistContent = fs.readFileSync(generatedPlistPath, 'utf8');
|
|
308
|
+
assert(plistContent.includes('com.apple.widgetkit-extension'));
|
|
309
|
+
assert(plistContent.includes('RCTNewArchEnabled'));
|
|
310
|
+
} finally {
|
|
311
|
+
fs.rmSync(tmpTestDir, { recursive: true, force: true });
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
console.log('\n🎉 [Test Suite] All 13 test suites passed with 100% assertions satisfied!\n');
|