perf: break early if the line width <= max width of the container (#6347)

* fix: break early if the line width <= max width of the container

* Remove dead code

* remove dead code

* lint

* remove
This commit is contained in:
Aakansha Doshi 2023-03-14 17:18:16 +05:30 committed by GitHub
parent 6aeb18b784
commit ab49cad6b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 29 deletions

View file

@ -16,7 +16,7 @@ describe("Test wrapText", () => {
const text = "Hello whats up ";
const maxWidth = 200 - BOUND_TEXT_PADDING * 2;
const res = wrapText(text, font, maxWidth);
expect(res).toBe("Hello whats up ");
expect(res).toBe(text);
});
it("should work with emojis", () => {
@ -26,7 +26,7 @@ describe("Test wrapText", () => {
expect(res).toBe("😀");
});
it("should show the text correctly when min width reached", () => {
it("should show the text correctly when max width reached", () => {
const text = "Hello😀";
const maxWidth = 10;
const res = wrapText(text, font, maxWidth);
@ -136,6 +136,7 @@ whats up`,
});
});
});
describe("When text is long", () => {
const text = `hellolongtextthisiswhatsupwithyouIamtypingggggandtypinggg break it now`;
[
@ -175,6 +176,14 @@ break it now`,
});
});
});
it("should wrap the text correctly when word length is exactly equal to max width", () => {
const text = "Hello Excalidraw";
// Length of "Excalidraw" is 100 and exacty equal to max width
const res = wrapText(text, font, 100);
expect(res).toEqual(`Hello
Excalidraw`);
});
});
describe("Test measureText", () => {