Skip to content

Commit 0c411ad

Browse files
committed
test(landing): cover uncapped graphic scaling
1 parent 1afc79a commit 0c411ad

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

apps/sim/app/(landing)/components/shared/responsive-design-stage/responsive-design-stage.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,43 @@ describe('calculateFitScale', () => {
114114
})
115115

116116
describe('ResponsiveDesignStage', () => {
117+
it.each([
118+
{ width: 280, height: 400, supportsZoom: true },
119+
{ width: 280, height: 400, supportsZoom: false },
120+
{ width: 350, height: 340, supportsZoom: true },
121+
{ width: 350, height: 340, supportsZoom: false },
122+
])(
123+
'fits an uncapped $width × $height stage with zoom support: $supportsZoom',
124+
({ width, height, supportsZoom }) => {
125+
vi.stubGlobal('CSS', { supports: vi.fn(() => supportsZoom) })
126+
act(() => {
127+
root.render(
128+
createElement(
129+
ResponsiveDesignStage,
130+
{ width, height, maxScale: Number.POSITIVE_INFINITY },
131+
createElement('span', null, 'Preview')
132+
)
133+
)
134+
})
135+
136+
const surface = container.firstElementChild?.firstElementChild
137+
if (!(surface instanceof HTMLElement) || !resizeObserver) {
138+
throw new Error('responsive stage did not mount')
139+
}
140+
const observer = resizeObserver
141+
142+
act(() => observer.deliver(width * 2, height * 1.5))
143+
expect(surface.style.zoom).toBe(supportsZoom ? '1.5' : '1')
144+
expect(surface.style.transform).toBe(supportsZoom ? '' : 'scale(1.5)')
145+
expect(surface.style.opacity).toBe('1')
146+
147+
act(() => observer.deliver(width / 2, height * 2))
148+
expect(surface.style.zoom).toBe(supportsZoom ? '0.5' : '1')
149+
expect(surface.style.transform).toBe(supportsZoom ? '' : 'scale(0.5)')
150+
expect(surface.style.opacity).toBe('1')
151+
}
152+
)
153+
117154
it('hides an already visible surface until a measurable size returns', () => {
118155
act(() => {
119156
root.render(

0 commit comments

Comments
 (0)