From 246af8dec8723329a16f2f48302c899c7bd3316c Mon Sep 17 00:00:00 2001 From: "HomePC\\Kevin" Date: Mon, 30 Nov 2026 23:10:40 +0100 Subject: [PATCH] test(apps): validate and draw the SDK's UI kit fixtures Part of closing #626: the platform used none of the shared contract fixtures for UI kit elements. @rentnerproxy/app-contracts 1.8.1 ships one accepted and one rejected node for each of the 27 elements (RentnerProxy/app-sdk#17). The platform now checks all 54 with its own tree rules, placing a tab panel or a description item inside its parent as an app would: the accepted nodes enter the tree and are drawn without the loading skeleton, the rejected ones leave the tree untouched. The contracts package moves from 1.7.0 to 1.8.1; between them only version strings and the new fixture file changed. Co-Authored-By: Claude Opus 5.5 --- bun.lock | 4 +- package.json | 2 +- .../features/AppUi/ui-kit-fixtures.test.tsx | 71 +++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 web/src/tests/features/AppUi/ui-kit-fixtures.test.tsx diff --git a/bun.lock b/bun.lock index b01a27b1..10b211b5 100644 --- a/bun.lock +++ b/bun.lock @@ -23,7 +23,7 @@ "@rentnerkev/select": "6.2.1", "@rentnerkev/toasts": "3.9.1", "@rentnerkev/tooltips": "2.3.3", - "@rentnerproxy/app-contracts": "1.7.0", + "@rentnerproxy/app-contracts": "1.8.1", "@simplewebauthn/browser": "14.0.0", "@simplewebauthn/server": "14.1.0", "@tanstack/charts": "1.5.0", @@ -472,7 +472,7 @@ "@rentnerkev/tooltips": ["@rentnerkev/tooltips@2.3.3", "", { "peerDependencies": { "react": "^19.0.0", "react-dom": "^19.0.0" } }, "sha512-TOxANbayMB9iU97Jh1Pgh8ylDbLAzZQykLQyP/JTkokYTnn9PZnK/CiZYAz7qQymDsXHYSNxhZALpevzVp+uPw=="], - "@rentnerproxy/app-contracts": ["@rentnerproxy/app-contracts@1.7.0", "", { "dependencies": { "zod": "^4.6.7" } }, "sha512-+mpMlPYEwXnXBcjyUSYiN8ASz1vvK2AIx+xTlGmhyQCOzVpaQbI9+fa3xLpxJ/P/ZZKC1nzMHkM2RQ/DNPPK3Q=="], + "@rentnerproxy/app-contracts": ["@rentnerproxy/app-contracts@1.8.1", "", { "dependencies": { "zod": "^4.6.7" } }, "sha512-OtK4Ok9wIUzQLdkfFMMz8yDdGy0ViMAWdcgF1LxqeNiTr8ZiqrHW3KomkAAKRh0vFPkiJ0DlfQYTbWkdLGs2HA=="], "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.3.4", "", { "os": "android", "cpu": "arm" }, "sha512-xCW8CkL/ualx/SbYqeG9iK87lJCZGDQ0soE+kaORJ0Bd+pHALyE4qK7BStmEAyYWLEzZ3/biSIpA6/7GDFvzIg=="], diff --git a/package.json b/package.json index 0e1ba544..f0e513d0 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "@rentnerkev/select": "6.2.1", "@rentnerkev/toasts": "3.9.1", "@rentnerkev/tooltips": "2.3.3", - "@rentnerproxy/app-contracts": "1.7.0", + "@rentnerproxy/app-contracts": "1.8.1", "@simplewebauthn/browser": "14.0.0", "@simplewebauthn/server": "14.1.0", "@tanstack/charts": "1.5.0", diff --git a/web/src/tests/features/AppUi/ui-kit-fixtures.test.tsx b/web/src/tests/features/AppUi/ui-kit-fixtures.test.tsx new file mode 100644 index 00000000..d7a576a3 --- /dev/null +++ b/web/src/tests/features/AppUi/ui-kit-fixtures.test.tsx @@ -0,0 +1,71 @@ +import { afterEach, describe, expect, test } from 'bun:test' +import { GlobalRegistrator } from '@happy-dom/global-registrator' +import uiKitFixtures from '@rentnerproxy/app-contracts/ui-kit-fixtures.json' +import withTestLanguage from '@/tests/Helpers/withTestLanguage.tsx' + +if (!GlobalRegistrator.isRegistered) GlobalRegistrator.register({ url: 'https://platform.test/' }) +Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }) + +const { act } = await import('react') +const { createRoot } = await import('react-dom/client') +const { createRemoteUiStore } = await import('@/lib/AppUi/remote-tree.ts') +const { default: RemoteAppView } = + await import('@/features/AppUi/Components/RemoteAppView/index.tsx') + +type Node = { readonly id: string; readonly element: string; readonly [key: string]: unknown } + +// Elements that only live inside one parent are drawn inside it, as an app would place them. +const parents: Record = { + 'ui-tab-panel': { + id: '900', + type: 1, + element: 'ui-tabs', + properties: { label: 'Sections', value: 'overview' }, + children: [], + }, + 'ui-description-item': { + id: '900', + type: 1, + element: 'ui-description-list', + children: [], + }, +} + +function placed(node: Node) { + const parent = parents[node.element] + return parent ? { ...parent, children: [node] } : node +} + +let cleanup: (() => Promise) | undefined +afterEach(async () => { + await cleanup?.() + cleanup = undefined + document.body.innerHTML = '' +}) + +describe('shared UI kit fixtures', () => { + test('cover every element the platform draws', () => { + const elements = new Set(uiKitFixtures.cases.map(({ element }) => element)) + expect(elements.size).toBe(27) + }) + + for (const fixture of uiKitFixtures.cases) { + test(`${fixture.valid ? 'draws' : 'refuses'} ${fixture.title}`, async () => { + const store = createRemoteUiStore() + const accepted = store.apply([[0, '~', placed(fixture.document as Node), 0]]) + expect(accepted).toBe(fixture.valid) + if (!fixture.valid) return + + const container = document.createElement('div') + document.body.append(container) + const root = createRoot(container) + cleanup = async () => act(async () => root.unmount()) + await act(async () => + root.render(withTestLanguage( {}} />)), + ) + // The platform drew the element instead of its loading skeleton. + expect(document.querySelector('output[aria-busy="true"]')).toBeNull() + expect(document.body.innerHTML.length).toBeGreaterThan(0) + }) + } +})