-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(electron): stabilize canvas-first shell #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
|
|
||
| import { render, screen } from '@testing-library/react' | ||
| import React from 'react' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { CanvasView } from './CanvasView' | ||
|
|
||
| const mockUseIdentity = vi.fn() | ||
| const mockUseNode = vi.fn() | ||
|
|
||
| vi.mock('@xnetjs/canvas', async () => { | ||
| const ReactModule = await import('react') | ||
|
|
||
| return { | ||
| Canvas: ReactModule.forwardRef(function MockCanvas() { | ||
| return <div data-testid="mock-canvas">canvas</div> | ||
| }), | ||
| createNode: vi.fn(() => ({ | ||
| id: 'node-1', | ||
| type: 'card', | ||
| position: { x: 0, y: 0, width: 100, height: 100 }, | ||
| properties: {} | ||
| })) | ||
| } | ||
| }) | ||
|
|
||
| vi.mock('@xnetjs/data', () => ({ | ||
| CanvasSchema: { | ||
| schema: { | ||
| '@id': 'xnet://schema/canvas' | ||
| } | ||
| } | ||
| })) | ||
|
|
||
| vi.mock('@xnetjs/react', () => ({ | ||
| useIdentity: (...args: unknown[]) => mockUseIdentity(...args), | ||
| useNode: (...args: unknown[]) => mockUseNode(...args) | ||
| })) | ||
|
|
||
| describe('CanvasView', () => { | ||
| beforeEach(() => { | ||
| const nodesMap = { | ||
| size: 0, | ||
| observe: vi.fn(), | ||
| unobserve: vi.fn() | ||
| } | ||
|
|
||
| mockUseIdentity.mockReturnValue({ did: 'did:key:test' }) | ||
| mockUseNode.mockReturnValue({ | ||
| data: { title: 'Workspace Canvas' }, | ||
| doc: { | ||
| getMap: vi.fn(() => nodesMap) | ||
| }, | ||
| loading: false, | ||
| awareness: null | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps the canvas host at full height for the renderer shell', () => { | ||
| render(<CanvasView docId="canvas-1" />) | ||
|
|
||
| const canvas = screen.getByTestId('mock-canvas') | ||
| const canvasHost = canvas.parentElement?.parentElement | ||
|
|
||
| expect(canvasHost).not.toBeNull() | ||
| expect(canvasHost?.className).toContain('h-full') | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,11 +115,7 @@ export function MenuSeparator() { | |
| * A label for use with the simple Menu component. | ||
| */ | ||
| export function MenuLabel({ children }: { children: React.ReactNode }) { | ||
| return ( | ||
| <BaseMenu.GroupLabel className="px-2 py-1.5 text-xs font-semibold text-foreground-muted"> | ||
| {children} | ||
| </BaseMenu.GroupLabel> | ||
| ) | ||
| return <div className="px-2 py-1.5 text-xs font-semibold text-foreground-muted">{children}</div> | ||
| } | ||
|
Comment on lines
117
to
119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessibility regression: ARIA group label semantics removed Replacing If the intention is to avoid the crash entirely, the minimal fix that preserves semantics is to wrap any // at the call site
<BaseMenu.Group>
<MenuLabel>Section heading</MenuLabel>
<MenuItem …>…</MenuItem>
</BaseMenu.Group>Alternatively, if the |
||
|
|
||
| // ─── Compound Components (for advanced usage) ─────────────────────── | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Brittle DOM traversal for host element lookup
The test navigates up the DOM via
canvas.parentElement?.parentElementto find the canvas host container. This couples the test to the exact depth of nesting between themock-canvaselement and the target div. If an additional wrapper element is ever introduced inside<div className="h-full">(the inner wrapper at line 247 ofCanvasView.tsx), this traversal silently resolves to the wrong element and the assertion either gives a false positive or a confusing failure.A more resilient approach is to add a
data-testidto the host div inCanvasView.tsxand query it directly:This makes the test resilient to structural changes while still locking the
h-fullbehaviour.