Skip to content

call resetDimensions on Text when we update the label #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chs-js-lib",
"version": "0.3.4",
"version": "0.3.5",
"description": "JavaScript graphics library used in CodeHS's platform.",
"main": "dist/chs.cjs",
"module": "dist/chs.mjs",
Expand Down
2 changes: 2 additions & 0 deletions src/graphics/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Text extends Thing {
);
}
this.label = label;
this.resetDimensions()
}

/**
Expand All @@ -143,6 +144,7 @@ class Text extends Thing {
);
}
this.label = label;
this.resetDimensions()
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ describe('Text', () => {
t.setText('fdsa');
expect(t.label).toEqual('fdsa');
});
it('Updates dimensions', () => {
const t = new Text('mmmm');
const originalWidth = t.getWidth();
t.setText('mmmmmmm');
expect(t.getWidth()).toBeGreaterThan(originalWidth);
});
});
describe('setLabel', () => {
it('Errors for invalid arguments', () => {
Expand All @@ -109,6 +115,12 @@ describe('Text', () => {
t.setLabel('fdsa');
expect(t.label).toEqual('fdsa');
});
it('Updates dimensions', () => {
const t = new Text('mmmm');
const originalWidth = t.getWidth();
t.setLabel('mmmmmmm');
expect(t.getWidth()).toBeGreaterThan(originalWidth);
});
});
describe('containsPoint', () => {
it('Checks if a point is contained in the Text', () => {
Expand Down