@tantawowa/hosanna-ui 2.0.0 → 2.0.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/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
|
|
package/dist-manifest.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"artifact": "npm-sdk",
|
|
4
4
|
"packageName": "@tantawowa/hosanna-ui",
|
|
5
|
-
"version": "2.0.
|
|
6
|
-
"sourceCommit": "
|
|
5
|
+
"version": "2.0.2",
|
|
6
|
+
"sourceCommit": "811a31c682344d9aead9b495245eb6b479df33d5",
|
|
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": "
|
|
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"
|
|
@@ -2615,7 +2619,7 @@
|
|
|
2615
2619
|
},
|
|
2616
2620
|
{
|
|
2617
2621
|
"path": "src/hosanna-ui/views/lib/BaseView.ts",
|
|
2618
|
-
"sha256": "
|
|
2622
|
+
"sha256": "ad210cb3e4b0483f32d3944a0be826aa099fd325ac087f46a6169663a5df371e"
|
|
2619
2623
|
},
|
|
2620
2624
|
{
|
|
2621
2625
|
"path": "src/hosanna-ui/views/lib/BuildConfig.ts",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tantawowa/hosanna-ui",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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.
|
|
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
|
+
}
|
|
@@ -214,6 +214,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
214
214
|
private boundViewModelHid = '';
|
|
215
215
|
private isApplyingViewModelFocus = false;
|
|
216
216
|
private lastReportedViewModelFocusId = '';
|
|
217
|
+
private pendingViewModelFocus = '';
|
|
217
218
|
|
|
218
219
|
//these parent child relationships refer to the view tree
|
|
219
220
|
parent?: IHosannaView<ViewState> = undefined;
|
|
@@ -811,6 +812,10 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
811
812
|
this.invalidateParentLayout();
|
|
812
813
|
this.notifyResize();
|
|
813
814
|
}
|
|
815
|
+
|
|
816
|
+
if (this.pendingViewModelFocus !== '') {
|
|
817
|
+
this.applyPendingViewModelFocus();
|
|
818
|
+
}
|
|
814
819
|
}
|
|
815
820
|
}
|
|
816
821
|
|
|
@@ -3352,9 +3357,52 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
3352
3357
|
return;
|
|
3353
3358
|
}
|
|
3354
3359
|
this.lastReportedViewModelFocusId = focusedId;
|
|
3360
|
+
// Focus moved for another reason, so a request still waiting for its target is out of date.
|
|
3361
|
+
this.pendingViewModelFocus = '';
|
|
3355
3362
|
vm.focused(focusedId);
|
|
3356
3363
|
}
|
|
3357
3364
|
|
|
3365
|
+
private isViewModelFocusTargetReady(target: string): boolean {
|
|
3366
|
+
const child = this.getViewById(target) as IHosannaView<ViewState> | undefined;
|
|
3367
|
+
return child !== undefined && child.canReceiveFocus === true && child.visible === true;
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
/**
|
|
3371
|
+
* The model asked for a target before this view had rendered it, as when it
|
|
3372
|
+
* reveals a control and asks for focus on it in the same change. Called after
|
|
3373
|
+
* each render; applies the request once the target can take focus.
|
|
3374
|
+
*/
|
|
3375
|
+
private applyPendingViewModelFocus(): void {
|
|
3376
|
+
const target = this.pendingViewModelFocus;
|
|
3377
|
+
if (!this.viewModel || !this.isViewModelFocusTargetReady(target)) {
|
|
3378
|
+
return;
|
|
3379
|
+
}
|
|
3380
|
+
this.pendingViewModelFocus = '';
|
|
3381
|
+
if (this.isFocusOutsideThisView()) {
|
|
3382
|
+
// Focus left for another view while the request waited. Taking it back would steal it.
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
this.requestViewModelFocus(target);
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
/**
|
|
3389
|
+
* True when another view, outside this one, holds focus. This view is only
|
|
3390
|
+
* told about focus changes beneath it, so a move to a sibling is found here.
|
|
3391
|
+
*/
|
|
3392
|
+
private isFocusOutsideThisView(): boolean {
|
|
3393
|
+
let view = this.focusManager.focusedView as IHosannaView<ViewState> | undefined;
|
|
3394
|
+
if (!view) {
|
|
3395
|
+
return false;
|
|
3396
|
+
}
|
|
3397
|
+
while (view) {
|
|
3398
|
+
if (view._hid === this._hid) {
|
|
3399
|
+
return false;
|
|
3400
|
+
}
|
|
3401
|
+
view = view.parent as IHosannaView<ViewState> | undefined;
|
|
3402
|
+
}
|
|
3403
|
+
return true;
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3358
3406
|
private getFocusedViewId(): string {
|
|
3359
3407
|
const focusedView = this.focusManager.focusedView as IHosannaView<ViewState> | undefined;
|
|
3360
3408
|
return focusedView?.id ?? '';
|
|
@@ -3376,8 +3424,14 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
3376
3424
|
if (!current) {
|
|
3377
3425
|
return;
|
|
3378
3426
|
}
|
|
3379
|
-
if (field === 'focus'
|
|
3380
|
-
this.
|
|
3427
|
+
if (field === 'focus') {
|
|
3428
|
+
// A target that this view has not rendered yet is asked for again once it has.
|
|
3429
|
+
// An empty target means none, which also withdraws a request still waiting.
|
|
3430
|
+
const target = current.focus;
|
|
3431
|
+
this.pendingViewModelFocus = target === '' || this.isViewModelFocusTargetReady(target) ? '' : target;
|
|
3432
|
+
if (target !== '') {
|
|
3433
|
+
this.requestViewModelFocus(target);
|
|
3434
|
+
}
|
|
3381
3435
|
}
|
|
3382
3436
|
if (this.onViewModelChanged(field)) {
|
|
3383
3437
|
this.makeDirty('viewModel');
|
|
@@ -3402,6 +3456,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
3402
3456
|
this.hasStartedViewModel = false;
|
|
3403
3457
|
this.boundViewModelHid = '';
|
|
3404
3458
|
this.lastReportedViewModelFocusId = '';
|
|
3459
|
+
this.pendingViewModelFocus = '';
|
|
3405
3460
|
this.bindViewModel();
|
|
3406
3461
|
}
|
|
3407
3462
|
|
|
@@ -3414,6 +3469,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
3414
3469
|
vm.removeObservers(this);
|
|
3415
3470
|
this.boundViewModelHid = '';
|
|
3416
3471
|
this.lastReportedViewModelFocusId = '';
|
|
3472
|
+
this.pendingViewModelFocus = '';
|
|
3417
3473
|
if (!this.disposesViewModelOnUnmount) {
|
|
3418
3474
|
if (this.hasStartedViewModel) {
|
|
3419
3475
|
vm.suspend();
|
|
@@ -3442,6 +3498,7 @@ export class BaseView<T extends ViewState, R extends ISGNGroup = ISGNGroup> impl
|
|
|
3442
3498
|
this.hasStartedViewModel = false;
|
|
3443
3499
|
this.boundViewModelHid = '';
|
|
3444
3500
|
this.lastReportedViewModelFocusId = '';
|
|
3501
|
+
this.pendingViewModelFocus = '';
|
|
3445
3502
|
}
|
|
3446
3503
|
|
|
3447
3504
|
/** Assignment to an `@observable` field: observe the new object, then store it. */
|