Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
71 changes: 71 additions & 0 deletions web/src/tests/features/AppUi/ui-kit-fixtures.test.tsx
Original file line number Diff line number Diff line change
@@ -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<string, Node> = {
'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<void>) | 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(<RemoteAppView store={store} onEvent={() => {}} />)),
)
// 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)
})
}
})