Skip to content

Commit 477a36a

Browse files
Change tests (#113)
* Decouple thead from tbodies. * Handle null error by using optional chaining and checking for ! undefined * WIP fixed missing thead... * change each col to have td property. * Fix formatting of table.
1 parent 3b60a17 commit 477a36a

File tree

3 files changed

+101
-85
lines changed

3 files changed

+101
-85
lines changed

test/order-by-desc.test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const createTestTable = require("./table");
33
test("Alpha - Capitalized: order-by-desc", () => {
44
expect(
55
createTestTable(
6-
{ col0: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] },
6+
{ col0: {td: ["Echo", "Alpha", "Bravo", "Charlie", "Delta"] }},
77
{
88
classTags: "order-by-desc",
99
}
@@ -14,7 +14,7 @@ test("Alpha - Capitalized: order-by-desc", () => {
1414
test("Alpha - Lowercase: order-by-desc ", () => {
1515
expect(
1616
createTestTable(
17-
{ col0: ["echo", "alpha", "bravo", "charlie", "delta"] },
17+
{ col0: {td: ["echo", "alpha", "bravo", "charlie", "delta"] }},
1818
{
1919
classTags: "order-by-desc",
2020
}
@@ -24,14 +24,14 @@ test("Alpha - Lowercase: order-by-desc ", () => {
2424

2525
test("Numerical: order-by-desc", () => {
2626
expect(
27-
createTestTable({ col0: [5, 3, 4, 1, 2] }, { classTags: "order-by-desc" })
27+
createTestTable({ col0: {td:[5, 3, 4, 1, 2] }}, { classTags: "order-by-desc" })
2828
).toStrictEqual({ col0: ["5", "4", "3", "2", "1"] });
2929
});
3030

3131
test("Alphanumeric: order-by-desc", () => {
3232
expect(
3333
createTestTable(
34-
{ col0: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] },
34+
{ col0:{td: ["Alpha1", "Echo5", "Bravo2", "Charlie3", "Delta4"] }},
3535
{
3636
classTags: "order-by-desc",
3737
}
@@ -44,7 +44,7 @@ test("Alphanumeric: order-by-desc", () => {
4444
test("Dates: order-by-desc", () => {
4545
expect(
4646
createTestTable(
47-
{ col0: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"] },
47+
{ col0: {td: ["1979/9/6", "2008/4/9", "1879/12/16", "1978/4/6", "1978/4/16"] }},
4848
{ classTags: "order-by-desc" }
4949
)
5050
).toStrictEqual({
@@ -55,7 +55,7 @@ test("Dates: order-by-desc", () => {
5555
test("Money: order-by-desc", () => {
5656
expect(
5757
createTestTable(
58-
{ col0: ["$29", "$93", "$84", "$20", "$58"] },
58+
{ col0: {td: ["$29", "$93", "$84", "$20", "$58"] }},
5959
{
6060
classTags: "order-by-desc",
6161
}
@@ -66,7 +66,7 @@ test("Money: order-by-desc", () => {
6666
test("Empty cells sort at the end: order-by-desc", () => {
6767
expect(
6868
createTestTable(
69-
{ col0: ["Echo", "", "Bravo", "", "Alpha"] },
69+
{ col0: {td: ["Echo", "", "Bravo", "", "Alpha"] }},
7070
{
7171
classTags: "order-by-desc",
7272
}
@@ -78,7 +78,7 @@ test("Order by file-size: file-size order-by-desc", () => {
7878
expect(
7979
createTestTable(
8080
{
81-
col0: [
81+
col0: {td:[
8282
"10MB",
8383
"10GB",
8484
"10TB",
@@ -89,7 +89,7 @@ test("Order by file-size: file-size order-by-desc", () => {
8989
"10KB",
9090
"10GiB",
9191
],
92-
},
92+
}},
9393
{ classTags: "order-by-desc file-size-sort" }
9494
)
9595
).toStrictEqual({
@@ -110,7 +110,7 @@ test("Order by file-size: file-size order-by-desc", () => {
110110
test("Floating point numbers: order-by-desc", () => {
111111
expect(
112112
createTestTable(
113-
{ col0: [6.23, 0.25, 3.15, 9.09, 0.35] },
113+
{ col0: {td:[6.23, 0.25, 3.15, 9.09, 0.35] }},
114114
{
115115
classTags: "order-by-desc",
116116
}
@@ -121,7 +121,7 @@ test("Floating point numbers: order-by-desc", () => {
121121
test("Release Versions: order-by-desc", () => {
122122
expect(
123123
createTestTable(
124-
{ col0: ["4.0.1", "3.0.2", "4.1.0", "3.0.4", "4.2.0"] },
124+
{ col0: {td: ["4.0.1", "3.0.2", "4.1.0", "3.0.4", "4.2.0"] }},
125125
{
126126
classTags: "order-by-desc",
127127
}
@@ -133,7 +133,7 @@ test("data-sort: example days of week - reversed", () => {
133133
expect(
134134
createTestTable(
135135
{
136-
col0: [
136+
col0: {td:[
137137
"Saturday",
138138
"Wednesday",
139139
"Sunday",
@@ -142,7 +142,7 @@ test("data-sort: example days of week - reversed", () => {
142142
"Tuesday",
143143
"Monday",
144144
],
145-
},
145+
}},
146146
{ classTags: "data-sort order-by-desc" }
147147
)
148148
).toStrictEqual({
@@ -162,14 +162,14 @@ test("visible-tr-sort: example sort only visible trs", () => {
162162
expect(
163163
createTestTable(
164164
{
165-
col0: [
165+
col0: {td:[
166166
"row1", // invisible
167167
"row2",
168168
"row3", // invisible
169169
"row4",
170170
"row5",
171171
],
172-
},
172+
}},
173173
{ classTags: "order-by-desc" },
174174
{ invisibleIndex: [0, 2] }
175175
)
@@ -179,7 +179,7 @@ test("visible-tr-sort: example sort only visible trs", () => {
179179
test("onload-sort: testing that it sorts without a click from user", () => {
180180
expect(
181181
createTestTable(
182-
{ col0: [5, 3, 4, 1, 2] },
182+
{ col0: {td: [5, 3, 4, 1, 2] }},
183183
{ classTags: "order-by-desc onload-sort" }
184184
)
185185
).toStrictEqual({ col0: ["5", "4", "3", "2", "1"] });
@@ -189,8 +189,8 @@ test("order-by-desc Remember-sort: Sorting cols without rememeber-sort class.",
189189
expect(
190190
createTestTable(
191191
{
192-
col0: ["charlie", "alpha", "beta"],
193-
col1: ["carrie", "doris", "fisher"],
192+
col0: {td: ["charlie", "alpha", "beta"]},
193+
col1: {td: ["carrie", "doris", "fisher"]},
194194
},
195195
{
196196
classTags: "order-by-desc",
@@ -210,8 +210,8 @@ test("order-by-desc Remember-sort: Sorting cols with rememeber-sort class.", ()
210210
expect(
211211
createTestTable(
212212
{
213-
col0: ["charlie", "alpha", "beta"],
214-
col1: ["carrie", "doris", "fisher"],
213+
col0: {td:["charlie", "alpha", "beta"]},
214+
col1: {td:["carrie", "doris", "fisher"]},
215215
},
216216
{
217217
classTags: "order-by-desc",

test/table.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ function createTestTable(
1919
function getRowsOfTd(index, type) {
2020
let rowsOfTd = "";
2121
for (let key in testTableData) {
22-
if (testTableData[key]) {
22+
if (testTableData[key].td) {
2323
if (type === "data-sort") {
24-
rowsOfTd += `<td data-sort="${index}">${testTableData[key][index]}</td>`;
24+
rowsOfTd += `<td data-sort="${index}">${testTableData[key].td[index]}</td>`;
2525
} else {
26-
rowsOfTd += `<td>${testTableData[key][index]}</td>`;
26+
rowsOfTd += `<td>${testTableData[key].td[index]}</td>`;
2727
}
2828
}
2929
}
3030
return rowsOfTd;
3131
}
3232

3333
let testTableTdRows = [];
34-
for (let i = 0; i < testTableData["col0"].length; i++) {
34+
for (let i = 0; i < testTableData["col0"].td.length; i++) {
3535
let testTableTdRow;
3636
if (thAttributes.classTags.includes("data-sort")) {
3737
testTableTdRow = `${getRowsOfTd(i, "data-sort")}`;
@@ -63,12 +63,12 @@ function createTestTable(
6363
<body>
6464
<table class="table-sort ${props.tableTags}">
6565
<thead>
66-
${testTableHeaders}
66+
${testTableHeaders}
6767
</thead>
68-
<tbody>
69-
${testTableTdRows}
70-
</tbody>
71-
</table>
68+
<tbody>
69+
${testTableTdRows}
70+
</tbody>
71+
</table>
7272
</body>
7373
</html>`);
7474

0 commit comments

Comments
 (0)