Skip to content

Commit 48188dd

Browse files
committed
test(artist): update tests for elements and utils
1 parent a974c27 commit 48188dd

File tree

4 files changed

+78
-31
lines changed

4 files changed

+78
-31
lines changed

packages/misc/artist-ui/__tests__/artist.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ describe("artist ui", () => {
1111

1212
it("should load default elements", () => {
1313
expect(Object.keys(artist["elements"])).toEqual([
14-
"text",
15-
"newline",
16-
"row",
1714
"column",
1815
"div",
19-
"span",
16+
"newline",
17+
"row",
2018
"space",
19+
"span",
20+
"text",
2121
"spinner",
2222
"progress",
2323
"unknown",

packages/misc/artist-ui/__tests__/elements.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,41 @@ describe("artist elements", () => {
8787

8888
artist.paint("<spinner></spinner>");
8989
});
90+
91+
it("should render the row when no column is defined", () => {
92+
const row = "";
93+
artist.paint("<row>hello</row>");
94+
expect(output).toEqual(row);
95+
});
96+
97+
it("should render the row when columns are defined", () => {
98+
artist.paint(`
99+
<row>
100+
<column>Name</column>
101+
<column>Kevin</column>
102+
</row>
103+
`);
104+
expect(/Name(\s+)Kevin/.test(output)).toBeTruthy();
105+
});
106+
107+
it("should render the column", () => {
108+
artist.paint("<column>hello</column>");
109+
expect(output).toEqual("hello");
110+
});
111+
112+
it("should render the space", () => {
113+
artist.paint("<space length='5'></space>");
114+
expect(output).toEqual(" ".repeat(5));
115+
});
116+
117+
it("should render the list", () => {
118+
const names = ["Peter", "Kevin", "John"];
119+
artist.createStore({ names });
120+
artist.paint(`
121+
{{#list names}}
122+
<text>{{this}}</text>
123+
{{/list}}
124+
`);
125+
expect(output).toEqual("PeterKevinJohn");
126+
});
90127
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { flatten, flattenToStr } from "../src/utils";
2+
3+
describe("utils", () => {
4+
it("should deep flatten the array", () => {
5+
const input = ["one", "two", ["three", "four"], ["five", ["six", "seven"]]];
6+
expect(flattenToStr(input)).toEqual([
7+
"one",
8+
"two",
9+
"three four",
10+
"five six seven",
11+
]);
12+
});
13+
14+
it("should flatten the array to one level", () => {
15+
const input = ["one", "two", ["three", "four"], ["five", ["six", "seven"]]];
16+
expect(flatten(input)).toEqual([
17+
"one",
18+
"two",
19+
"three",
20+
"four",
21+
"five",
22+
["six", "seven"],
23+
]);
24+
});
25+
});
Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
import { column } from "./column";
2-
import { div } from "./div";
3-
import { newline } from "./newline";
4-
import { row } from "./row";
5-
import { space } from "./space";
6-
import { span } from "./span";
7-
import { text } from "./text";
8-
import { spinner } from "./spinner";
9-
import { progress } from "./progress";
10-
import { unknown } from "./unknown";
11-
import { key } from "./key";
12-
import { box } from "./box";
13-
14-
export {
15-
text,
16-
newline,
17-
row,
18-
column,
19-
div,
20-
span,
21-
space,
22-
spinner,
23-
progress,
24-
unknown,
25-
key,
26-
box,
27-
};
1+
export { column } from "./column";
2+
export { div } from "./div";
3+
export { newline } from "./newline";
4+
export { row } from "./row";
5+
export { space } from "./space";
6+
export { span } from "./span";
7+
export { text } from "./text";
8+
export { spinner } from "./spinner";
9+
export { progress } from "./progress";
10+
export { unknown } from "./unknown";
11+
export { key } from "./key";
12+
export { box } from "./box";

0 commit comments

Comments
 (0)