Skip to content

Commit

Permalink
Improve complexity of multi-line layout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Jun 23, 2022
1 parent d93c78f commit 4efe6bd
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions packages/core/src/data-grid/multi-line-layout.test.tsx
Expand Up @@ -5,6 +5,24 @@ import { splitMultilineText } from "./multi-line-layout";
// 1 char === 1 px according to the testing library. This is not realistic but nice for testing.

describe("multi-line-layout", () => {
beforeEach(() => {
CanvasRenderingContext2D.prototype.measureText = jest.fn((str: string) => {
let width = 0;
for (const char of str) {
width += char.charCodeAt(0) / 12;
}
return {
width,
actualBoundingBoxAscent: 1,
actualBoundingBoxDescent: 1,
actualBoundingBoxLeft: 1,
actualBoundingBoxRight: width,
fontBoundingBoxAscent: 1,
fontBoundingBoxDescent: 1,
};
});
});

test("short-sentence", () => {
render(<canvas data-testid="canvas" />);

Expand Down Expand Up @@ -41,18 +59,13 @@ describe("multi-line-layout", () => {
ctx,
"This is a quite long string that will need to wrap at least a couple times in order to fit on the screen. Who knows how many times?",
"12px bold",
20,
400,
false
);
expect(spanned).toEqual([
"This is a quite long",
"string that will",
"need to wrap at",
"least a couple",
"times in order to",
"fit on the screen.",
"Who knows how many",
"times?",
"This is a quite long string that will need to wrap",
"at least a couple times in order to fit on the",
"screen. Who knows how many times?",
]);
});

Expand All @@ -74,19 +87,14 @@ describe("multi-line-layout", () => {
ctx,
"This is a quite long string \nthat will need to wrap at least a \ncouple times in order to \nfit on the screen. Who knows how many times?",
"12px bold",
20,
400,
false
);
expect(spanned).toEqual([
"This is a quite long",
"string",
"that will need to",
"wrap at least a",
"couple times in",
"order to",
"fit on the screen.",
"Who knows how many",
"times?",
"This is a quite long string",
"that will need to wrap at least a",
"couple times in order to",
"fit on the screen. Who knows how many times?",
]);
});
});

0 comments on commit 4efe6bd

Please sign in to comment.