openpencil/tests/helpers/store.ts
Danila Poyarkov fae190a673 chore(lint): remove unsafe test casts
- Enforce explicit-any and TypeScript suppression bans in tests
- Remove remaining broad any casts from engine and e2e coverage
- Split markdown ambient declarations from typed browser globals
2026-05-06 00:42:45 +03:00

96 lines
2.5 KiB
TypeScript

import type { Page } from '@playwright/test'
export function getSelectedIds(page: Page) {
return page.evaluate(() => window.__OPEN_PENCIL_STORE__!.state.selectedIds.size)
}
export function getPageChildren(page: Page) {
return page.evaluate(() => {
const store = window.__OPEN_PENCIL_STORE__!
return store.graph.getChildren(store.state.currentPageId).map((n) => ({
id: n.id,
type: n.type,
x: n.x,
y: n.y,
width: n.width,
height: n.height,
layoutMode: n.layoutMode,
childIds: n.childIds,
vectorNetwork: n.vectorNetwork
}))
})
}
export function getSelectedNode(page: Page) {
return page.evaluate(() => {
const store = window.__OPEN_PENCIL_STORE__!
const id = [...store.state.selectedIds][0]
if (!id) return null
const n = store.graph.getNode(id)
if (!n) return null
return {
id: n.id,
type: n.type,
x: n.x,
y: n.y,
width: n.width,
height: n.height,
rotation: n.rotation,
layoutMode: n.layoutMode,
primaryAxisAlign: n.primaryAxisAlign,
counterAxisAlign: n.counterAxisAlign,
itemSpacing: n.itemSpacing,
childIds: n.childIds,
cornerRadius: n.cornerRadius,
flipX: n.flipX,
clipsContent: n.clipsContent,
fills: n.fills,
fontWeight: n.fontWeight,
italic: n.italic
}
})
}
export function getNodeById(page: Page, id: string) {
return page.evaluate((nodeId: string) => {
const store = window.__OPEN_PENCIL_STORE__!
const n = store.graph.getNode(nodeId)
if (!n) return null
return {
id: n.id,
type: n.type,
x: n.x,
y: n.y,
width: n.width,
height: n.height,
rotation: n.rotation,
layoutMode: n.layoutMode,
primaryAxisAlign: n.primaryAxisAlign,
counterAxisAlign: n.counterAxisAlign,
itemSpacing: n.itemSpacing,
counterAxisSpacing: n.counterAxisSpacing,
layoutWrap: n.layoutWrap,
paddingTop: n.paddingTop,
paddingRight: n.paddingRight,
paddingBottom: n.paddingBottom,
paddingLeft: n.paddingLeft,
minWidth: n.minWidth,
maxWidth: n.maxWidth,
minHeight: n.minHeight,
maxHeight: n.maxHeight,
childIds: n.childIds,
cornerRadius: n.cornerRadius,
flipX: n.flipX,
clipsContent: n.clipsContent,
fills: n.fills,
fontWeight: n.fontWeight,
italic: n.italic,
styleRuns: n.styleRuns
}
}, id)
}
export function getEditingTextId(page: Page) {
return page.evaluate(() => window.__OPEN_PENCIL_STORE__!.state.editingTextId)
}