@@ -54,7 +54,7 @@ function createTestTableMissingHeadTag(testTableData, classTags = "") {
5454 testTableTdRows . push ( testTableTdRow ) ;
5555 }
5656
57- const tableWithMissingHeadTag = new JSDOM ( `<!DOCTYPE html>
57+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
5858 <html>
5959 <head>
6060 </head>
@@ -69,10 +69,10 @@ function createTestTableMissingHeadTag(testTableData, classTags = "") {
6969 </html>` ) ;
7070
7171 // Call tablesort and make table sortable and simulate click from a user.
72- tableSortJs ( ( testing = true ) , tableWithMissingHeadTag . window . document ) ;
73- tableWithMissingHeadTag . window . document . querySelector ( "table th" ) . click ( ) ;
72+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
73+ htmlTableInStringForm . window . document . querySelector ( "table th" ) . click ( ) ;
7474 // Make an array from table contents to test if sorted correctly.
75- let table = tableWithMissingHeadTag . window . document . querySelector ( "table" ) ;
75+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
7676 const tableBody = table . querySelector ( "tbody" ) ;
7777 const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
7878 const testIfSortedList = tableRows . map (
@@ -92,7 +92,7 @@ function createTestTableMissingBodyTag(testTableData, classTags = "") {
9292 testTableTdRows . push ( testTableTdRow ) ;
9393 }
9494
95- const tablewithMissingBodyTag = new JSDOM ( `<!DOCTYPE html>
95+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
9696 <html>
9797 <head>
9898 </head>
@@ -107,10 +107,10 @@ function createTestTableMissingBodyTag(testTableData, classTags = "") {
107107 </html>` ) ;
108108
109109 // Call tablesort and make table sortable and simulate click from a user.
110- tableSortJs ( ( testing = true ) , tablewithMissingBodyTag . window . document ) ;
111- tablewithMissingBodyTag . window . document . querySelector ( "table th" ) . click ( ) ;
110+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
111+ htmlTableInStringForm . window . document . querySelector ( "table th" ) . click ( ) ;
112112 // Make an array from table contents to test if sorted correctly.
113- let table = tablewithMissingBodyTag . window . document . querySelector ( "table" ) ;
113+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
114114 const tableBody = table . querySelector ( "tbody" ) ;
115115 const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
116116 const testIfSortedList = tableRows . map (
@@ -130,7 +130,7 @@ function createTestTableMissingBodyAndHeadTag(testTableData, classTags = "") {
130130 testTableTdRows . push ( testTableTdRow ) ;
131131 }
132132
133- const tableWithMissingBodyAndHeadTag = new JSDOM ( `<!DOCTYPE html>
133+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
134134 <html>
135135 <head>
136136 </head>
@@ -143,13 +143,134 @@ function createTestTableMissingBodyAndHeadTag(testTableData, classTags = "") {
143143 </html>` ) ;
144144
145145 // Call tablesort and make table sortable and simulate click from a user.
146- tableSortJs ( ( testing = true ) , tableWithMissingBodyAndHeadTag . window . document ) ;
147- tableWithMissingBodyAndHeadTag . window . document
148- . querySelector ( "table th" )
149- . click ( ) ;
146+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
147+ htmlTableInStringForm . window . document . querySelector ( "table th" ) . click ( ) ;
150148 // Make an array from table contents to test if sorted correctly.
151- let table =
152- tableWithMissingBodyAndHeadTag . window . document . querySelector ( "table" ) ;
149+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
150+ const tableBody = table . querySelector ( "tbody" ) ;
151+ const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
152+ const testIfSortedList = tableRows . map (
153+ ( tr ) => tr . querySelectorAll ( "td" ) . item ( 0 ) . innerHTML
154+ ) ;
155+ return testIfSortedList ;
156+ }
157+
158+ // no th tags only td tags!
159+ function createTestTableTDNoTHMissingHeadAndBody (
160+ testTableData ,
161+ classTags = ""
162+ ) {
163+ let getClassTagsForTH = [ ] ;
164+ // use td instead of th
165+ let testTableThRow = `<tr><td class="${ classTags } ">Testing Column</td></tr>` ;
166+ getClassTagsForTH . push ( testTableThRow ) ;
167+
168+ let testTableTdRows = [ ] ;
169+ for ( let i = 0 ; i < testTableData . length ; i ++ ) {
170+ let testTableTdRow = `<tr><td>${ testTableData [ i ] } </td></tr>` ;
171+ testTableTdRows . push ( testTableTdRow ) ;
172+ }
173+
174+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
175+ <html>
176+ <head>
177+ </head>
178+ <body>
179+ <table class="table-sort">
180+ ${ getClassTagsForTH }
181+ ${ testTableTdRows }
182+ </table>
183+ </body>
184+ </html>` ) ;
185+
186+ // Call tablesort and make table sortable and simulate click from a user.
187+ // click on the td instead of th
188+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
189+ htmlTableInStringForm . window . document . querySelector ( "table td" ) . click ( ) ;
190+ // Make an array from table contents to test if sorted correctly.
191+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
192+ const tableBody = table . querySelector ( "tbody" ) ;
193+ const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
194+ const testIfSortedList = tableRows . map (
195+ ( tr ) => tr . querySelectorAll ( "td" ) . item ( 0 ) . innerHTML
196+ ) ;
197+ return testIfSortedList ;
198+ }
199+
200+ function createTestTableTDNoTHInsideBody ( testTableData , classTags = "" ) {
201+ let getClassTagsForTH = [ ] ;
202+ // use td instead of th
203+ let testTableThRow = `<tr><td class="${ classTags } ">Testing Column</td></tr>` ;
204+ getClassTagsForTH . push ( testTableThRow ) ;
205+
206+ let testTableTdRows = [ ] ;
207+ for ( let i = 0 ; i < testTableData . length ; i ++ ) {
208+ let testTableTdRow = `<tr><td>${ testTableData [ i ] } </td></tr>` ;
209+ testTableTdRows . push ( testTableTdRow ) ;
210+ }
211+
212+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
213+ <html>
214+ <head>
215+ </head>
216+ <body>
217+ <table class="table-sort">
218+ <tbody>
219+ ${ getClassTagsForTH }
220+ ${ testTableTdRows }
221+ </tbody>
222+ </table>
223+ </body>
224+ </html>` ) ;
225+
226+ // Call tablesort and make table sortable and simulate click from a user.
227+ // click on the td instead of th
228+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
229+ htmlTableInStringForm . window . document . querySelector ( "table td" ) . click ( ) ;
230+ // Make an array from table contents to test if sorted correctly.
231+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
232+ const tableBody = table . querySelector ( "tbody" ) ;
233+ const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
234+ const testIfSortedList = tableRows . map (
235+ ( tr ) => tr . querySelectorAll ( "td" ) . item ( 0 ) . innerHTML
236+ ) ;
237+ return testIfSortedList ;
238+ }
239+
240+ function createTestTableTDNoTHInsideHead ( testTableData , classTags = "" ) {
241+ let getClassTagsForTH = [ ] ;
242+ // use td instead of th
243+ let testTableThRow = `<tr><td class="${ classTags } ">Testing Column</td></tr>` ;
244+ getClassTagsForTH . push ( testTableThRow ) ;
245+
246+ let testTableTdRows = [ ] ;
247+ for ( let i = 0 ; i < testTableData . length ; i ++ ) {
248+ let testTableTdRow = `<tr><td>${ testTableData [ i ] } </td></tr>` ;
249+ testTableTdRows . push ( testTableTdRow ) ;
250+ }
251+
252+ const htmlTableInStringForm = new JSDOM ( `<!DOCTYPE html>
253+ <html>
254+ <head>
255+ </head>
256+ <body>
257+ <table class="table-sort">
258+ <thead>
259+ ${ getClassTagsForTH }
260+ <thead/>
261+ <tbody>
262+ ${ testTableTdRows }
263+ </tbody>
264+ </table>
265+ </body>
266+ </html>` ) ;
267+
268+ // Call tablesort and make table sortable and simulate click from a user.
269+ // click on the td instead of th
270+ tableSortJs ( ( testing = true ) , htmlTableInStringForm . window . document ) ;
271+ htmlTableInStringForm . window . document . querySelector ( "table td" ) . click ( ) ;
272+ // Make an array from table contents to test if sorted correctly.
273+ let table = htmlTableInStringForm . window . document . querySelector ( "table" ) ;
153274 const tableBody = table . querySelector ( "tbody" ) ;
154275 const tableRows = [ ...tableBody . querySelectorAll ( "tr" ) ] ;
155276 const testIfSortedList = tableRows . map (
@@ -178,7 +299,7 @@ function createTestTableMultipleTBodies(
178299 let testTableTdRows = makeTdRows ( testTableData ) ;
179300 let testTableTdRows2 = makeTdRows ( testTableData2 ) ;
180301 let testTableTdRows3 = makeTdRows ( testTableData3 ) ;
181- const tableWithMultipleTableBodies = new JSDOM ( `<!DOCTYPE html>
302+ const HTMLtableWithMultipleTableBodies = new JSDOM ( `<!DOCTYPE html>
182303 <html>
183304 <head>
184305 </head>
@@ -206,15 +327,20 @@ function createTestTableMultipleTBodies(
206327 </body>
207328 </html>` ) ;
208329 // Call tablesort and make table sortable and simulate click from a user.
209- tableSortJs ( ( testing = true ) , tableWithMultipleTableBodies . window . document ) ;
330+ tableSortJs (
331+ ( testing = true ) ,
332+ HTMLtableWithMultipleTableBodies . window . document
333+ ) ;
210334 const tableTH =
211- tableWithMultipleTableBodies . window . document . querySelectorAll ( "table th" ) ;
335+ HTMLtableWithMultipleTableBodies . window . document . querySelectorAll (
336+ "table th"
337+ ) ;
212338 for ( let th of tableTH ) {
213339 th . click ( ) ;
214340 }
215341 // Make an array from table contents to test if sorted correctly.
216342 let table =
217- tableWithMultipleTableBodies . window . document . querySelector ( "table" ) ;
343+ HTMLtableWithMultipleTableBodies . window . document . querySelector ( "table" ) ;
218344 const tableBodies = table . querySelectorAll ( "tbody" ) ;
219345 const tableHeads = table . querySelectorAll ( "thead" ) ;
220346
@@ -239,4 +365,7 @@ module.exports = {
239365 createTestTableMissingBodyTag,
240366 createTestTableMissingBodyAndHeadTag,
241367 createTestTableMultipleTBodies,
368+ createTestTableTDNoTHMissingHeadAndBody,
369+ createTestTableTDNoTHInsideBody,
370+ createTestTableTDNoTHInsideHead,
242371} ;
0 commit comments