@tantawowa/hosanna-ui 2.0.0-bootstrap.0 → 2.0.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/README.md CHANGED
@@ -14,6 +14,9 @@ and `npx hst sdk:install`. The tooling maintains the existing `hosanna-ui` and
14
14
  `src/hosanna-*` links so application imports and build paths keep working.
15
15
  Generated application files stay in the application's `src-generated` directory.
16
16
 
17
+ Application tests can import `src/hosanna-ui/lib/test-utils.ts` from the installed
18
+ SDK. This test helper requires Vitest in the application and is not a runtime import.
19
+
17
20
  The proprietary TypeScript-to-BrightScript compiler is installed separately and
18
21
  requires its existing Hosanna compiler license. It is not included in this SDK.
19
22
 
@@ -2,8 +2,8 @@
2
2
  "schemaVersion": 2,
3
3
  "artifact": "npm-sdk",
4
4
  "packageName": "@tantawowa/hosanna-ui",
5
- "version": "2.0.0-bootstrap.0",
6
- "sourceCommit": "82bf902f7d7992091268c5857b6fcec71a9c605f",
5
+ "version": "2.0.1",
6
+ "sourceCommit": "673a83b1ec2c9587b09c4822bc47e08a8947228d",
7
7
  "files": [
8
8
  {
9
9
  "path": "LICENSE",
@@ -11,7 +11,7 @@
11
11
  },
12
12
  {
13
13
  "path": "hosanna-consumer-dependencies.json",
14
- "sha256": "986f959b4be831b658f1140b26571b3798fb9bf84125a1bbc1ea4422246ec874"
14
+ "sha256": "d2c606fa9a5050596c44906c2d15380363175fc51c0152cdb28f958bd596cd65"
15
15
  },
16
16
  {
17
17
  "path": "hosanna.json",
@@ -2353,6 +2353,10 @@
2353
2353
  "path": "src/hosanna-ui/lib/test-utils.md",
2354
2354
  "sha256": "64dd1010b70acd4bba6dc2377b29aeca638e8f4b628daf3fad7cb54f9d6e3971"
2355
2355
  },
2356
+ {
2357
+ "path": "src/hosanna-ui/lib/test-utils.ts",
2358
+ "sha256": "88bef77909337e36dc1c48cc3fa96db93123fcd9675b060253a469973b49f8a2"
2359
+ },
2356
2360
  {
2357
2361
  "path": "src/hosanna-ui/lib/video/ThumbnailManager.ts",
2358
2362
  "sha256": "15e705df2349d52e8c2f7770327de0993e095183cc627687ec7f7c2679c8f2f0"
@@ -6,7 +6,7 @@
6
6
  "crypto-js": "^4.2.0",
7
7
  "dashjs": "^5.0.3",
8
8
  "dayjs": "1.11.13",
9
- "fflate": "0.8.2",
9
+ "fflate": "0.8.3",
10
10
  "hls.js": "1.5.11",
11
11
  "lottie-web": "^5.13.0"
12
12
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tantawowa/hosanna-ui",
3
- "version": "2.0.0-bootstrap.0",
3
+ "version": "2.0.1",
4
4
  "description": "Hosanna UI source SDK for Roku and its browser emulator",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -17,7 +17,7 @@
17
17
  "crypto-js": "^4.2.0",
18
18
  "dashjs": "^5.0.3",
19
19
  "dayjs": "1.11.13",
20
- "fflate": "0.8.2",
20
+ "fflate": "0.8.3",
21
21
  "hls.js": "1.5.11",
22
22
  "lottie-web": "^5.13.0",
23
23
  "@types/crypto-js": "^4.2.2",
@@ -0,0 +1,183 @@
1
+ // hs:exclude-from-platform roku
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ import { vi } from 'vitest';
4
+ import { AppUtils } from '@hs-src/hosanna-bridge-core/AppUtils';
5
+ import { addWebGlobals } from '@hs-src/hosanna-bridge-targets/web/sg/sg-global-functions-web';
6
+ import { WebSGNode } from '@hs-src/hosanna-bridge-targets/web/sg/WebSGNode';
7
+
8
+ /**
9
+ * Mocks platform-specific modules that don't exist in the web test environment.
10
+ * This should be called at the very top of test files, before any other imports.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // At the very top of your test file, before any other imports:
15
+ * import { mockPlatformModules } from '../lib/test-utils';
16
+ * mockPlatformModules();
17
+ *
18
+ * // Then your regular imports:
19
+ * import { describe, it, expect } from 'vitest';
20
+ * ```
21
+ */
22
+ export function mockPlatformModules(): void {
23
+ // CRITICAL: Pre-emptively mock platform-only modules that may be imported transitively
24
+ // These do not exist in the web test environment and must be mocked BEFORE any imports execute
25
+ vi.mock('@hs-platform/PlatformTaskAppInitializer', () => ({
26
+ PlatformTaskAppInitializer: {},
27
+ default: {}
28
+ }));
29
+
30
+ vi.mock('@hs-platform/PlatformAppInitializer', () => ({
31
+ default: {}
32
+ }));
33
+
34
+ vi.mock('../async/AsyncApi.ts', () => ({
35
+ AsyncCommand: { inject: vi.fn() },
36
+ AsyncCommandState: {
37
+ Terminated: 'Terminated',
38
+ Initializing: 'Initializing',
39
+ Idle: 'Idle',
40
+ Running: 'Running',
41
+ Paused: 'Paused',
42
+ Cancelled: 'Cancelled',
43
+ Completed: 'Completed',
44
+ Updated: 'Updated',
45
+ Failed: 'Failed',
46
+ Pending: 'Pending',
47
+ },
48
+ IAsyncCommand: {},
49
+ IAsyncEvent: {},
50
+ }));
51
+ }
52
+
53
+ /**
54
+ * Prepares the UI test environment by mocking global objects and methods.
55
+ * Sets up a mock document, initializes global application state, and stubs required methods for testing.
56
+ * @param globalAA - The global associative array (application state).
57
+ * @param documentProps - Optional properties to override or add to the mock document.
58
+ */
59
+ export function prepareUITestEnv(globalAA: any, documentProps: any = {}) {
60
+ // Define a mock document with a cookie property
61
+ global.document = {
62
+ cookie: 'example.com/path1=cookie1; example.com/path2=cookie2; another.com/path1=cookie3',
63
+ ...documentProps,
64
+ } as Document;
65
+ addWebGlobals();
66
+ globalAA.scene = new WebSGNode();
67
+
68
+ // Ensure __hs_pre_init_commands exists (required for async command queueing)
69
+ if (!globalAA.__hs_pre_init_commands) {
70
+ globalAA.__hs_pre_init_commands = [];
71
+ }
72
+
73
+ // Ensure __hs_container exists
74
+ if (!globalAA.__hs_container) {
75
+ globalAA.__hs_container = {};
76
+ }
77
+
78
+ // Ensure systemService is always registered to prevent AsyncManager errors
79
+ // This prevents errors when AsyncManager.runWebLoop() tries to access systemService
80
+ // via @inject decorator, which calls AppUtils.resolve('systemService')
81
+ if (!globalAA.__hs_container.systemService) {
82
+ globalAA.__hs_container.systemService = {
83
+ _tick: vi.fn(),
84
+ now: () => Date.now(),
85
+ };
86
+ }
87
+
88
+ // Ensure __hs_ioc exists and can resolve systemService
89
+ if (!globalAA.__hs_ioc) {
90
+ globalAA.__hs_ioc = {
91
+ resolve: vi.fn().mockImplementation((key: string) => {
92
+ // Check container first
93
+ if (globalAA.__hs_container[key]) {
94
+ return globalAA.__hs_container[key];
95
+ }
96
+ // Fallback for systemService
97
+ if (key === 'systemService') {
98
+ return globalAA.__hs_container.systemService;
99
+ }
100
+ return undefined;
101
+ }),
102
+ };
103
+ } else if (typeof globalAA.__hs_ioc.resolve === 'function') {
104
+ // Enhance existing resolve to ensure systemService fallbacks
105
+ const originalResolve = globalAA.__hs_ioc.resolve;
106
+ // Check if originalResolve is already a vi.fn() mock
107
+ const isMock = typeof originalResolve.getMockImplementation === 'function';
108
+
109
+ const createResolveWrapper = (originalImpl: (key: string) => any) => {
110
+ return vi.fn().mockImplementation((key: string) => {
111
+ try {
112
+ const result = originalImpl(key);
113
+ if (result !== undefined) {
114
+ return result;
115
+ }
116
+ } catch (e) {
117
+ // If original resolve throws and it's a known service, return the mock
118
+ if (key === 'systemService') {
119
+ return globalAA.__hs_container.systemService;
120
+ }
121
+ throw e;
122
+ }
123
+ // Fallback: check container directly
124
+ if (globalAA.__hs_container[key]) {
125
+ return globalAA.__hs_container[key];
126
+ }
127
+ // Final fallback for systemService
128
+ if (key === 'systemService') {
129
+ return globalAA.__hs_container.systemService;
130
+ }
131
+ return undefined;
132
+ });
133
+ };
134
+
135
+ if (isMock) {
136
+ // If it's already a mock, get its implementation and wrap it
137
+ const originalImpl = (originalResolve as any).getMockImplementation?.() || (() => undefined);
138
+ globalAA.__hs_ioc.resolve = createResolveWrapper(originalImpl);
139
+ } else {
140
+ // If it's a regular function, wrap it normally
141
+ globalAA.__hs_ioc.resolve = createResolveWrapper(originalResolve);
142
+ }
143
+ }
144
+
145
+ SetGlobalAA(globalAA);
146
+ (AppUtils.instance as any).__hs_global = GetGlobalAA();
147
+
148
+ //create a stu method for document.createElement('div')
149
+
150
+ /**
151
+ * Mocks the document.createElement method to return a stub div element.
152
+ */
153
+ global.document.createElement = vi.fn().mockImplementation((tagName: string) => {
154
+ const element = {
155
+ tagName,
156
+ id: '',
157
+ style: {
158
+ left: '',
159
+ top: '',
160
+ position: '',
161
+ opacity: '',
162
+ },
163
+ children: [] as any[],
164
+ appendChild: vi.fn((child: any) => {
165
+ element.children.push(child);
166
+ return child;
167
+ }),
168
+ removeChild: vi.fn((child: any) => {
169
+ const index = element.children.indexOf(child);
170
+ if (index > -1) {
171
+ element.children.splice(index, 1);
172
+ }
173
+ return child;
174
+ }),
175
+ remove: vi.fn(),
176
+ setAttribute: vi.fn(),
177
+ insertBefore: vi.fn(),
178
+ querySelector: vi.fn(),
179
+ parentElement: null,
180
+ };
181
+ return element;
182
+ });
183
+ }