Skip to content

Commit

Permalink
Add test for presence of "Show/Hide All" button on intialise
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtrussler committed Jun 3, 2024
1 parent 344611c commit 84e2b5e
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions spec/javascripts/spec/components/mainstream_table.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
/* global GOVUK */

describe('Table component', function () {
'use strict'

var table, mainstreamTable

beforeEach(function () {
table = $('<table data-module="mainstream-table"></table>')
var tableHtml =
`<thead>
<tr>
<th>Title</th>
<th>Assigned to</th>
<th>Status</th>
<th class="govuk-table__header--controls"></th>
</tr>
</thead>`

$('body').append(table)
table = document.createElement('table')
table.innerHTML = tableHtml
document.body.appendChild(table)

mainstreamTable = new GOVUK.Modules.MainstreamTable()
mainstreamTable = new GOVUK.Modules.MainstreamTable(table)
mainstreamTable.init()
})

afterEach(function () {
table.remove()
document.body.removeChild(table)
})

describe('when first initialized', function () {
it('should do nothing', function() {
expect(1).toBe(1)
describe('When initialised', function () {
it('should have a "Show/Hide All" button', function () {
var headerControls = table.querySelectorAll('th')[3]

expect(headerControls.querySelector('button')).not.toBeNull()
expect(headerControls.querySelector('button').classList).toContain('govuk-accordion__show-all')
expect(headerControls.querySelector('button').textContent).toBe('Show all')
})
})
})

0 comments on commit 84e2b5e

Please sign in to comment.