Skip to content

Commit 16fd365

Browse files
Move order-by-desc tests into their own file.
1 parent 197ad84 commit 16fd365

File tree

2 files changed

+179
-167
lines changed

2 files changed

+179
-167
lines changed

test/order-by-desc.test.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
2+
const createTestTable = require("./table");
3+
4+
test("Alpha - Capitalized: order-by-desc", () => {
5+
expect(
6+
createTestTable(
7+
{ col1: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] },
8+
{
9+
classTags: "order-by-desc",
10+
}
11+
)
12+
).toStrictEqual({ col1: ["Echo", "Delta", "Charlie", "Bravo", "Alpha"] });
13+
});
14+
15+
16+
test("Alpha - Lowercase: order-by-desc ", () => {
17+
expect(
18+
createTestTable(
19+
{ col1: ["echo", "alpha", "bravo", "charlie", "delta"] },
20+
{
21+
classTags: "order-by-desc",
22+
}
23+
)
24+
).toStrictEqual({ col1: ["echo", "delta", "charlie", "bravo", "alpha"] });
25+
});
26+
27+
test("Numerical: order-by-desc", () => {
28+
expect(
29+
createTestTable({ col1: [5, 3, 4, 1, 2] }, { classTags: "order-by-desc" })
30+
).toStrictEqual({ col1: ["5", "4", "3", "2", "1"] });
31+
});
32+
33+
test("Alphanumeric: order-by-desc", () => {
34+
expect(
35+
createTestTable(
36+
{ col1: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] },
37+
{
38+
classTags: "order-by-desc",
39+
}
40+
)
41+
).toStrictEqual({
42+
col1: ["Echo5", "Delta4", "Charlie3", "Bravo2", "Alpha1"],
43+
});
44+
});
45+
46+
test("Dates: order-by-desc", () => {
47+
expect(
48+
createTestTable(
49+
{ col1: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"] },
50+
{ classTags: "order-by-desc" }
51+
)
52+
).toStrictEqual({
53+
col1: ["2008/4/9", "1979/9/6", "1978/4/16", "1978/4/6", "1879/12/16"],
54+
});
55+
});
56+
57+
test("Money: order-by-desc", () => {
58+
expect(
59+
createTestTable(
60+
{ col1: ["$29", "$93", "$84", "$20", "$58"] },
61+
{
62+
classTags: "order-by-desc",
63+
}
64+
)
65+
).toStrictEqual({ col1: ["$93", "$84", "$58", "$29", "$20"] });
66+
});
67+
68+
test("Empty cells sort at the end: order-by-desc", () => {
69+
expect(
70+
createTestTable(
71+
{ col1: ["Echo", "", "Bravo", "", "Alpha"] },
72+
{
73+
classTags: "order-by-desc",
74+
}
75+
)
76+
).toStrictEqual({ col1: ["", "", "Echo", "Bravo", "Alpha"] });
77+
});
78+
79+
test("Order by file-size: file-size order-by-desc", () => {
80+
expect(
81+
createTestTable(
82+
{
83+
col1: [
84+
"10MB",
85+
"10GB",
86+
"10TB",
87+
"10B",
88+
"10MiB",
89+
"10TiB",
90+
"10Kib",
91+
"10KB",
92+
"10GiB",
93+
],
94+
},
95+
{ classTags: "order-by-desc file-size" }
96+
)
97+
).toStrictEqual({
98+
col1: [
99+
"10.00 TiB",
100+
"9.09 TiB",
101+
"10.00 GiB",
102+
"9.31 GiB",
103+
"10.00 MiB",
104+
"9.53 MiB",
105+
"10.00 KiB",
106+
"9.77 KiB",
107+
"10.00 B",
108+
],
109+
});
110+
});
111+
112+
test("Floating point numbers: order-by-desc", () => {
113+
expect(
114+
createTestTable(
115+
{ col1: [6.23, 0.25, 3.15, 9.09, 0.35] },
116+
{
117+
classTags: "order-by-desc",
118+
}
119+
)
120+
).toStrictEqual({ col1: ["9.09", "6.23", "3.15", "0.35", "0.25"] });
121+
});
122+
123+
test("Release Versions: order-by-desc", () => {
124+
expect(
125+
createTestTable(
126+
{ col1: ["4.0.1", "3.0.2", "4.1.0", "3.0.4", "4.2.0"] },
127+
{
128+
classTags: "order-by-desc",
129+
}
130+
)
131+
).toStrictEqual({ col1: ["4.2.0", "4.1.0", "4.0.1", "3.0.4", "3.0.2"] });
132+
});
133+
134+
test("data-sort: example days of week - reversed", () => {
135+
expect(
136+
createTestTable(
137+
{
138+
col1: [
139+
"Saturday",
140+
"Wednesday",
141+
"Sunday",
142+
"Friday",
143+
"Thursday",
144+
"Tuesday",
145+
"Monday",
146+
],
147+
},
148+
{ classTags: "data-sort order-by-desc" }
149+
)
150+
).toStrictEqual({
151+
col1: [
152+
"Monday",
153+
"Tuesday",
154+
"Thursday",
155+
"Friday",
156+
"Sunday",
157+
"Wednesday",
158+
"Saturday",
159+
],
160+
});
161+
});
162+
163+
test("visible-tr-sort: example sort only visible trs", () => {
164+
expect(
165+
createTestTable(
166+
{
167+
col1: [
168+
"row1", // invisible
169+
"row2",
170+
"row3", // invisible
171+
"row4",
172+
"row5",
173+
],
174+
},
175+
{ classTags: "order-by-desc" },
176+
[0, 2]
177+
)
178+
).toStrictEqual({ col1: ["row5", "row4", "row2"] });
179+
});

0 commit comments

Comments
 (0)