From 08b5ef556c5ea73219c46504abd99b6e645a1a20 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:12:22 -0500 Subject: [PATCH] test: add `view.getBounds|setBounds` tests (#48961) test: add view.getBounds|setBounds tests Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- spec/api-view-spec.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/api-view-spec.ts b/spec/api-view-spec.ts index 48c8ccae0c48..fc39bccb29d6 100644 --- a/spec/api-view-spec.ts +++ b/spec/api-view-spec.ts @@ -92,4 +92,46 @@ describe('View', () => { expect(v.getVisible()).to.be.false(); }); }); + + describe('view.getBounds|setBounds', () => { + it('defaults to 0,0,0,0', () => { + const v = new View(); + expect(v.getBounds()).to.deep.equal({ x: 0, y: 0, width: 0, height: 0 }); + }); + + it('can be set and retrieved', () => { + const v = new View(); + v.setBounds({ x: 10, y: 20, width: 300, height: 400 }); + expect(v.getBounds()).to.deep.equal({ x: 10, y: 20, width: 300, height: 400 }); + }); + + it('emits bounds-changed when bounds mutate', () => { + const v = new View(); + let called = 0; + v.once('bounds-changed', () => { called++; }); + v.setBounds({ x: 5, y: 6, width: 7, height: 8 }); + expect(called).to.equal(1); + }); + + it('allows zero-size bounds', () => { + const v = new View(); + v.setBounds({ x: 1, y: 2, width: 0, height: 0 }); + expect(v.getBounds()).to.deep.equal({ x: 1, y: 2, width: 0, height: 0 }); + }); + + it('allows negative coordinates', () => { + const v = new View(); + v.setBounds({ x: -10, y: -20, width: 100, height: 50 }); + expect(v.getBounds()).to.deep.equal({ x: -10, y: -20, width: 100, height: 50 }); + }); + + it('child bounds remain relative after parent moves', () => { + const parent = new View(); + const child = new View(); + parent.addChildView(child); + child.setBounds({ x: 10, y: 15, width: 25, height: 30 }); + parent.setBounds({ x: 50, y: 60, width: 500, height: 600 }); + expect(child.getBounds()).to.deep.equal({ x: 10, y: 15, width: 25, height: 30 }); + }); + }); });