Skip to content

Commit a94a406

Browse files
authored
Merge pull request #147 from codehs/z-text-dimension-fix
call resetDimensions on Text when we update the label
2 parents cf0777e + 9046bc3 commit a94a406

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chs-js-lib",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"description": "JavaScript graphics library used in CodeHS's platform.",
55
"main": "dist/chs.cjs",
66
"module": "dist/chs.mjs",

src/graphics/text.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Text extends Thing {
122122
);
123123
}
124124
this.label = label;
125+
this.resetDimensions()
125126
}
126127

127128
/**
@@ -143,6 +144,7 @@ class Text extends Thing {
143144
);
144145
}
145146
this.label = label;
147+
this.resetDimensions()
146148
}
147149

148150
/**

test/text.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ describe('Text', () => {
8787
t.setText('fdsa');
8888
expect(t.label).toEqual('fdsa');
8989
});
90+
it('Updates dimensions', () => {
91+
const t = new Text('mmmm');
92+
const originalWidth = t.getWidth();
93+
t.setText('mmmmmmm');
94+
expect(t.getWidth()).toBeGreaterThan(originalWidth);
95+
});
9096
});
9197
describe('setLabel', () => {
9298
it('Errors for invalid arguments', () => {
@@ -109,6 +115,12 @@ describe('Text', () => {
109115
t.setLabel('fdsa');
110116
expect(t.label).toEqual('fdsa');
111117
});
118+
it('Updates dimensions', () => {
119+
const t = new Text('mmmm');
120+
const originalWidth = t.getWidth();
121+
t.setLabel('mmmmmmm');
122+
expect(t.getWidth()).toBeGreaterThan(originalWidth);
123+
});
112124
});
113125
describe('containsPoint', () => {
114126
it('Checks if a point is contained in the Text', () => {

0 commit comments

Comments
 (0)