diff --git a/public/index.html b/public/index.html index 7503393..1ebc88e 100644 --- a/public/index.html +++ b/public/index.html @@ -10,11 +10,11 @@
Last Name | +Last Name | First Name | Birth Date | Employee ID | -Department | +Department |
---|---|---|---|---|---|---|
benjamin | 1706,1,17 | - | C-level | +k-level | ||
da Vinci | diff --git a/public/table-sort.js b/public/table-sort.js index 4939ec3..bcaa6e4 100644 --- a/public/table-sort.js +++ b/public/table-sort.js @@ -326,6 +326,10 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) { getTableData(tableProperties); updateTable(tableProperties); }); + let isOnloadSort = th.classList.contains("onload-sort"); + if (isOnloadSort) { + th.click(); + } } } diff --git a/test/order-by-desc.test.js b/test/order-by-desc.test.js index 226d819..67d8664 100644 --- a/test/order-by-desc.test.js +++ b/test/order-by-desc.test.js @@ -175,3 +175,10 @@ test("visible-tr-sort: example sort only visible trs", () => { ) ).toStrictEqual({ col0: ["row5", "row4", "row2"] }); }); + + +test("onload-sort: testing that it sorts without a click from user", () => { + expect( + createTestTable({ col0: [5, 3, 4, 1, 2] }, { classTags: "order-by-desc onload-sort" }) + ).toStrictEqual({ col0: ["5", "4", "3", "2", "1"] }); +}); diff --git a/test/table.js b/test/table.js index d59e0dc..104bf51 100644 --- a/test/table.js +++ b/test/table.js @@ -78,7 +78,9 @@ function createTestTable( } } else { for (let i = 0; i < numberOfTableColumns; i++) { - dom.window.document.querySelectorAll("table th")[i].click(); + if (!thAttributes.classTags.includes("onload-sort")) { + dom.window.document.querySelectorAll("table th")[i].click(); + } } } diff --git a/test/table.test.js b/test/table.test.js index 4fd519a..c18407a 100644 --- a/test/table.test.js +++ b/test/table.test.js @@ -219,3 +219,14 @@ test("testing that multiple columns works", () => { col1: ["carrie", "fisher", "doris"], }); }); + +test("onload-sort: testing that it sorts without a click from user", () => { + expect( + createTestTable( + { col0: ["echo", "alpha", "bravo", "charlie", "delta"] }, + { + classTags: "onload-sort", + } + ) + ).toStrictEqual({ col0: ["alpha", "bravo", "charlie", "delta", "echo"] }); +});