test: share scene variable helper

This commit is contained in:
Danila Poyarkov 2026-06-11 23:07:38 +03:00
parent 4c26536e69
commit 3a5b6a5c37
2 changed files with 29 additions and 29 deletions

View file

@ -25,34 +25,7 @@ import {
} from '@open-pencil/core' } from '@open-pencil/core'
import { expectDefined, getNodeOrThrow, childIdAt } from '#tests/helpers/assert' import { expectDefined, getNodeOrThrow, childIdAt } from '#tests/helpers/assert'
import { makeSceneGraph } from '#tests/helpers/scene' import { addTestColorVariable, makeSceneGraph } from '#tests/helpers/scene'
function addTestColorVariable(
graph: ReturnType<typeof makeSceneGraph>,
id: string,
name: string,
value = { r: 1, g: 1, b: 1, a: 1 }
): void {
if (!graph.variableCollections.has('colors')) {
graph.addCollection({
id: 'colors',
name: 'Colors',
modes: [{ modeId: 'light', name: 'Light' }],
defaultModeId: 'light',
variableIds: []
})
}
graph.addVariable({
id,
name,
type: 'COLOR',
collectionId: 'colors',
valuesByMode: { light: value },
description: '',
hiddenFromPublishing: false
})
}
describe('renderTree', () => { describe('renderTree', () => {
it('renders a simple frame', async () => { it('renders a simple frame', async () => {

View file

@ -1,5 +1,5 @@
import { SceneGraph } from '@open-pencil/core' import { SceneGraph } from '@open-pencil/core'
import type { SceneNode } from '@open-pencil/core' import type { Color, SceneNode } from '@open-pencil/core'
export function makeSceneGraph(pageName = 'Test'): SceneGraph { export function makeSceneGraph(pageName = 'Test'): SceneGraph {
const graph = new SceneGraph() const graph = new SceneGraph()
@ -11,6 +11,33 @@ export function firstPageId(graph: SceneGraph): string {
return graph.getPages()[0].id return graph.getPages()[0].id
} }
export function addTestColorVariable(
graph: SceneGraph,
id: string,
name: string,
value: Color = { r: 1, g: 1, b: 1, a: 1 }
): void {
if (!graph.variableCollections.has('colors')) {
graph.addCollection({
id: 'colors',
name: 'Colors',
modes: [{ modeId: 'light', name: 'Light' }],
defaultModeId: 'light',
variableIds: []
})
}
graph.addVariable({
id,
name,
type: 'COLOR',
collectionId: 'colors',
valuesByMode: { light: value },
description: '',
hiddenFromPublishing: false
})
}
export function createRect( export function createRect(
graph: SceneGraph, graph: SceneGraph,
parentId: string, parentId: string,