Skip to content

Commit 23d3603

Browse files
committed
Adjustments
1 parent e4c810f commit 23d3603

6 files changed

Lines changed: 251 additions & 80 deletions

File tree

-82.5 KB
Loading
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { defineScreenshot } from '@/scripts/capture-screenshots'
2+
import type { Page } from 'playwright'
3+
4+
export default defineScreenshot({
5+
path: '/projects/docs_examples/branches/screenshots/components/screenshot-card-container?mode=design&canvas-tool=select&selection=onLoad&rightpanel=attributes',
6+
description: 'Add initialization logic to a component',
7+
setup: async (page: Page) => {
8+
await page.waitForTimeout(500)
9+
},
10+
annotations: [
11+
{
12+
x: 538,
13+
y: 6,
14+
type: 'badge',
15+
text: '1',
16+
},
17+
{
18+
x: 565,
19+
y: 6,
20+
type: 'label',
21+
text: 'View data panel',
22+
},
23+
{
24+
x: 662,
25+
y: 275,
26+
type: 'badge',
27+
text: '2',
28+
},
29+
{
30+
x: 573,
31+
y: 75,
32+
type: 'badge',
33+
text: '3',
34+
},
35+
],
36+
})
-14.8 KB
Loading

‎scripts/annotations.test.ts‎

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import {
3+
type Annotation,
4+
buildSvgOverlay,
5+
} from './annotations'
6+
7+
describe('scripts/annotations.ts', () => {
8+
it('should render an empty SVG when annotations array is empty', () => {
9+
const svg = buildSvgOverlay([], 800, 450).toString()
10+
expect(svg).toContain('<svg width="800" height="450" viewBox="0 0 800 450"')
11+
expect(svg).not.toContain('<rect')
12+
expect(svg).not.toContain('<text')
13+
})
14+
15+
it('should render badge annotations with single and multi-character text', () => {
16+
const annotations: Annotation[] = [
17+
{ type: 'badge', x: 100, y: 50, text: '1' },
18+
{ type: 'badge', x: 200, y: 150, text: '12' },
19+
]
20+
21+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
22+
expect(svg).toContain('<svg width="800" height="450"')
23+
expect(svg).toContain('fill="#ffffff" stroke="#1a1a1a"')
24+
expect(svg).toContain('>1<')
25+
expect(svg).toContain('>12<')
26+
27+
// Single character badge width is 20, multi-character badge width is 24
28+
expect(svg).toContain('width="20"')
29+
expect(svg).toContain('width="24"')
30+
})
31+
32+
it('should render selection, box, and highlight annotations with default and custom styling', () => {
33+
const annotations: Annotation[] = [
34+
{
35+
type: 'box',
36+
x: 24,
37+
y: 84,
38+
width: 104,
39+
height: 64,
40+
rx: 4,
41+
},
42+
{
43+
type: 'highlight',
44+
x: 50,
45+
y: 100,
46+
width: 200,
47+
height: 80,
48+
stroke: '#ff0000',
49+
strokeWidth: 2,
50+
},
51+
{
52+
type: 'selection',
53+
x: 10,
54+
y: 20,
55+
width: 50,
56+
height: 30,
57+
},
58+
]
59+
60+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
61+
expect(svg).toContain('x="24"')
62+
expect(svg).toContain('y="84"')
63+
expect(svg).toContain('width="104"')
64+
expect(svg).toContain('height="64"')
65+
expect(svg).toContain('rx="4"')
66+
expect(svg).toContain('fill="none"')
67+
expect(svg).toContain('stroke="#ffffff"')
68+
69+
// Custom highlight stroke and strokeWidth
70+
expect(svg).toContain('stroke="#ff0000"')
71+
expect(svg).toContain('stroke-width="2"')
72+
73+
// Selection defaults
74+
expect(svg).toContain('x="10"')
75+
expect(svg).toContain('y="20"')
76+
expect(svg).toContain('width="50"')
77+
expect(svg).toContain('height="30"')
78+
})
79+
80+
it('should scale box and highlight annotations proportionally for large resolutions (3200x1800)', () => {
81+
const annotations: Annotation[] = [
82+
{
83+
type: 'box',
84+
x: 24,
85+
y: 84,
86+
width: 104,
87+
height: 64,
88+
},
89+
{
90+
type: 'highlight',
91+
x: 50,
92+
y: 100,
93+
width: 200,
94+
height: 80,
95+
stroke: '#00ff00',
96+
strokeWidth: 2,
97+
},
98+
]
99+
100+
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
101+
expect(svgLarge).toContain('x="96"')
102+
expect(svgLarge).toContain('y="336"')
103+
expect(svgLarge).toContain('width="416"')
104+
expect(svgLarge).toContain('height="256"')
105+
expect(svgLarge).toContain('stroke="#00ff00"')
106+
expect(svgLarge).toContain('stroke-width="8"')
107+
})
108+
109+
it('should render text and label annotations with automatic width calculation', () => {
110+
const annotations: Annotation[] = [
111+
{
112+
type: 'text',
113+
x: 24,
114+
y: 152,
115+
width: 188,
116+
height: 20,
117+
text: 'Placeholder content for the slot',
118+
},
119+
{
120+
type: 'label',
121+
x: 100,
122+
y: 200,
123+
text: 'Auto width label',
124+
backgroundColor: '#000000',
125+
color: '#ffffff',
126+
fontWeight: 'normal',
127+
},
128+
]
129+
130+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
131+
expect(svg).toContain('x="24"')
132+
expect(svg).toContain('y="152"')
133+
expect(svg).toContain('width="188"')
134+
expect(svg).toContain('fill="#ffffff"')
135+
expect(svg).toContain('Placeholder content for the slot')
136+
expect(svg).toContain('text-anchor="middle"')
137+
138+
// Label with custom colors and auto-computed width
139+
expect(svg).toContain('fill="#000000"')
140+
expect(svg).toContain('fill="#ffffff"')
141+
expect(svg).toContain('font-weight="normal"')
142+
expect(svg).toContain('Auto width label')
143+
})
144+
145+
it('should scale text annotations properly at 3200x1800', () => {
146+
const annotations: Annotation[] = [
147+
{
148+
type: 'text',
149+
x: 24,
150+
y: 152,
151+
width: 188,
152+
height: 20,
153+
text: 'Scaled text',
154+
},
155+
]
156+
157+
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
158+
expect(svgLarge).toContain('x="96"')
159+
expect(svgLarge).toContain('y="608"')
160+
expect(svgLarge).toContain('width="752"')
161+
expect(svgLarge).toContain('height="80"')
162+
expect(svgLarge).toContain('font-size="46"')
163+
})
164+
165+
it('should ignore unrecognized annotation types gracefully', () => {
166+
const annotations = [
167+
{ type: 'unsupported-type', x: 0, y: 0 } as unknown as Annotation,
168+
]
169+
170+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
171+
expect(svg).toContain('<svg')
172+
expect(svg).not.toContain('<rect')
173+
})
174+
})
Lines changed: 23 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,31 @@
11
import { describe, expect, it } from 'bun:test'
2-
import { type Annotation, buildSvgOverlay } from './capture-screenshots'
3-
4-
describe('buildSvgOverlay', () => {
5-
it('should render badge annotations', () => {
6-
const annotations: Annotation[] = [
7-
{ type: 'badge', x: 100, y: 50, text: '1' },
8-
{ type: 'badge', x: 200, y: 150, text: '12' },
9-
]
10-
11-
const svg = buildSvgOverlay(annotations, 800, 450).toString()
12-
expect(svg).toContain('<svg width="800" height="450"')
13-
expect(svg).toContain('fill="#ffffff" stroke="#1a1a1a"')
14-
expect(svg).toContain('>1<')
15-
expect(svg).toContain('>12<')
2+
import {
3+
defineScreenshot,
4+
loadScreenshotTargets,
5+
TARGETS,
6+
} from './capture-screenshots'
7+
8+
describe('scripts/capture-screenshots.ts', () => {
9+
it('should define a screenshot configuration', () => {
10+
const config = defineScreenshot({
11+
path: '/test/path',
12+
description: 'Test target',
13+
})
14+
expect(config.path).toBe('/test/path')
15+
expect(config.description).toBe('Test target')
1616
})
1717

18-
it('should render selection/highlight box annotations', () => {
19-
const annotations: Annotation[] = [
20-
{
21-
type: 'box',
22-
x: 24,
23-
y: 84,
24-
width: 104,
25-
height: 64,
26-
rx: 4,
27-
},
28-
{
29-
type: 'highlight',
30-
x: 50,
31-
y: 100,
32-
width: 200,
33-
height: 80,
34-
stroke: '#ff0000',
35-
strokeWidth: 2,
36-
},
37-
]
38-
39-
const svg = buildSvgOverlay(annotations, 800, 450).toString()
40-
expect(svg).toContain('x="24"')
41-
expect(svg).toContain('y="84"')
42-
expect(svg).toContain('width="104"')
43-
expect(svg).toContain('height="64"')
44-
expect(svg).toContain('rx="4"')
45-
expect(svg).toContain('fill="none"')
46-
expect(svg).toContain('stroke="#ffffff"')
18+
it('should load screenshot targets from docs/', async () => {
19+
const targets = await loadScreenshotTargets()
20+
expect(targets.length).toBeGreaterThan(0)
4721

48-
// Scaled to 3200x1800
49-
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
50-
expect(svgLarge).toContain('x="96"')
51-
expect(svgLarge).toContain('y="336"')
52-
expect(svgLarge).toContain('width="416"')
53-
expect(svgLarge).toContain('height="256"')
54-
expect(svgLarge).toContain('stroke="#ff0000"')
55-
expect(svgLarge).toContain('stroke-width="8"')
22+
const bottomBar = targets.find((t) => t.id === 'bottom-bar')
23+
expect(bottomBar).toBeDefined()
24+
expect(bottomBar?.outputDir).toBe('docs/the-editor/bottom-bar')
25+
expect(bottomBar?.name).toBe('bottom-bar')
5626
})
5727

58-
it('should render text on white background annotations', () => {
59-
const annotations: Annotation[] = [
60-
{
61-
type: 'text',
62-
x: 24,
63-
y: 152,
64-
width: 188,
65-
height: 20,
66-
text: 'Placeholder content for the slot',
67-
},
68-
]
69-
70-
const svg = buildSvgOverlay(annotations, 800, 450).toString()
71-
expect(svg).toContain('x="24"')
72-
expect(svg).toContain('y="152"')
73-
expect(svg).toContain('width="188"')
74-
expect(svg).toContain('height="20"')
75-
expect(svg).toContain('fill="#ffffff"')
76-
expect(svg).toContain('Placeholder content for the slot')
77-
expect(svg).toContain('text-anchor="middle"')
78-
79-
// Scaled to 3200x1800
80-
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
81-
expect(svgLarge).toContain('x="96"')
82-
expect(svgLarge).toContain('y="608"')
83-
expect(svgLarge).toContain('width="752"')
84-
expect(svgLarge).toContain('height="80"')
85-
expect(svgLarge).toContain('font-size="46"')
28+
it('should export TARGETS array', () => {
29+
expect(Array.isArray(TARGETS)).toBe(true)
8630
})
8731
})

‎scripts/capture-screenshots.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface ScreenshotConfig {
1313
id?: string
1414
name?: string
1515
outputDir?: string
16-
path: string
16+
path: `/${string}`
1717
description: string
1818
setup?: (page: Page) => Promise<void>
1919
annotations?: Annotation[]
@@ -40,6 +40,13 @@ export async function captureTarget(
4040
target: ScreenshotTarget,
4141
baseUrl: string = DEFAULT_BASE_URL,
4242
) {
43+
if (!target.path || target.path.startsWith('TODO')) {
44+
console.log(
45+
`\n⚠️ Skipping [${target.id}]: path not configured yet (${target.description})`,
46+
)
47+
return
48+
}
49+
4350
console.log(`\n📸 Capturing [${target.id}]: ${target.description}`)
4451
const page = await browser.newPage({
4552
viewport: { width: 1920, height: 1080 },
@@ -98,6 +105,16 @@ export async function captureTarget(
98105
}
99106

100107
async function runDirectTarget(target: ScreenshotTarget) {
108+
if (!target.path || target.path.startsWith('TODO')) {
109+
console.warn(
110+
`\n⚠️ Cannot capture [${target.id}]: path is not configured yet.`,
111+
)
112+
console.warn(
113+
` Please update 'path' in ${target.outputDir}/${target.name}.screenshot.ts`,
114+
)
115+
return
116+
}
117+
101118
console.log(`🚀 Starting direct screenshot capture`)
102119
console.log(` Target: ${target.id} (${target.name})`)
103120
console.log(` Destination: ${target.outputDir}`)

0 commit comments

Comments
 (0)