Skip to content

Commit 6ba44ac

Browse files
committed
Added resize constraint tests (failing)
1 parent bc56e10 commit 6ba44ac

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/components/tests/Common.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,48 @@ export const commonResizableTests = (
288288
const style = window.getComputedStyle(sut);
289289
expect(size(style)).toBe("150px");
290290
});
291+
292+
test(`${name} resize with maximum size constraint has correct styles`, async () => {
293+
// arrange
294+
const { container } = render(<ViewPort>{mutateComponent(component, { id: "test", size: 50, maximumSize: 100 })}</ViewPort>);
295+
const sut = container.querySelector("#test")!;
296+
const resizeHandle = container.querySelector(".spaces-resize-handle")!;
297+
298+
// act (resize 100px)
299+
drag(
300+
resizeHandle,
301+
sut,
302+
{ width: horizontal ? 50 : 0, height: horizontal ? 0 : 50 },
303+
{ width: horizontal ? 150 : 0, height: horizontal ? 0 : 150 },
304+
horizontal ? (negate ? -100 : 100) : 0,
305+
horizontal ? 0 : negate ? -100 : 100,
306+
);
307+
308+
// assert
309+
const style = window.getComputedStyle(sut);
310+
expect(size(style)).toBe("calc(50px + 50px)"); // only 50px resized
311+
});
312+
313+
test(`${name} resize with minimum size constraint has correct styles`, async () => {
314+
// arrange
315+
const { container } = render(<ViewPort>{mutateComponent(component, { id: "test", size: 150, minimumSize: 100 })}</ViewPort>);
316+
const sut = container.querySelector("#test")!;
317+
const resizeHandle = container.querySelector(".spaces-resize-handle")!;
318+
319+
// act (resize -100px)
320+
drag(
321+
resizeHandle,
322+
sut,
323+
{ width: horizontal ? 150 : 0, height: horizontal ? 0 : 150 },
324+
{ width: horizontal ? 50 : 0, height: horizontal ? 0 : 50 },
325+
horizontal ? (negate ? 100 : -100) : 0,
326+
horizontal ? 0 : negate ? 100 : -100,
327+
);
328+
329+
// assert
330+
const style = window.getComputedStyle(sut);
331+
expect(size(style)).toBe("calc(150px + -50px)"); // only -50px resized
332+
});
291333
};
292334

293335
export const commonPositionedResizeTests = (

0 commit comments

Comments
 (0)