Skip to content

Commit

Permalink
some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tofsjonas committed Sep 19, 2023
1 parent fea8676 commit 92510ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/sortable.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,34 @@ <h2>class="no-sort"</h2>
</tbody>
</table>

<h2>times</h2>
<h2>numeric sorting</h2>
<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th>Time</th>
<th>Amount</th>
<th>Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>12:00:12</td>
<td>$18.49</td>
<td>2.49</td>
</tr>
<tr>
<td>Sidekick</td>
<td>12:22:11</td>
<td>$2.49</td>
<td>18.49</td>
</tr>
<tr>
<td>Butler</td>
<td>12:22:05</td>
<td>$1.96</td>
<td>1.96</td>
</tr>
</tbody>
</table>
Expand Down
26 changes: 26 additions & 0 deletions src/sortable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,30 @@ describe('sortable.test.html', () => {
expect(middle).toBe('12:22:11')
expect(last).toBe('12:00:12')
})

it('treats amounts like strings', async () => {
const table = getAllByRole(container, 'table')[5]
const th = getByRole(table, 'columnheader', { name: /Amount/ })
const first = getAllByRole(table, 'cell')[2].textContent
fireEvent.click(th)
const middle = getAllByRole(table, 'cell')[2].textContent
fireEvent.click(th)
const last = getAllByRole(table, 'cell')[2].textContent
expect(first).toBe('$18.49')
expect(middle).toBe('$2.49')
expect(last).toBe('$1.96')
})

it('treats numbers like numbers', async () => {
const table = getAllByRole(container, 'table')[5]
const th = getByRole(table, 'columnheader', { name: /Number/ })
const first = getAllByRole(table, 'cell')[3].textContent
fireEvent.click(th)
const middle = getAllByRole(table, 'cell')[3].textContent
fireEvent.click(th)
const last = getAllByRole(table, 'cell')[3].textContent
expect(first).toBe('2.49')
expect(middle).toBe('18.49')
expect(last).toBe('1.96')
})
})

0 comments on commit 92510ca

Please sign in to comment.