Skip to content

Commit

Permalink
Add tests for disable state syncronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine authored and romaricpascal committed Jan 9, 2025
1 parent ea87121 commit 834d32e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,51 @@ describe('/components/file-upload', () => {
})
})
})

describe('disabled state syncing', () => {
it('disables the button if the input is disabled on page load', async () => {
await render(page, 'file-upload', examples.disabled)

const buttonDisabled = await page.$eval(buttonSelector, (el) =>
el.hasAttribute('disabled')
)

expect(buttonDisabled).toBeTruthy()
})

it('disables the button if the input is disabled programatically', async () => {
await render(page, 'file-upload', examples.default)

await page.$eval(inputSelector, (el) =>
el.setAttribute('disabled', '')
)

const buttonDisabledAfter = await page.$eval(buttonSelector, (el) =>
el.hasAttribute('disabled')
)

expect(buttonDisabledAfter).toBeTruthy()
})

it('enables the button if the input is enabled programatically', async () => {
await render(page, 'file-upload', examples.disabled)

const buttonDisabledBefore = await page.$eval(buttonSelector, (el) =>
el.hasAttribute('disabled')
)

await page.$eval(inputSelector, (el) =>
el.removeAttribute('disabled')
)

const buttonDisabledAfter = await page.$eval(buttonSelector, (el) =>
el.hasAttribute('disabled')
)

expect(buttonDisabledBefore).toBeTruthy()
expect(buttonDisabledAfter).toBeFalsy()
})
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ examples:
text: Upload a file
attributes:
capture: 'user'
- name: is disabled
- name: disabled
options:
id: file-upload-1
name: file-upload-1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ describe('File upload', () => {
expect($component.attr('multiple')).toBeTruthy()
})

it('renders with multiple', () => {
const $ = render('file-upload', examples['is disabled'])
it('renders with disabled', () => {
const $ = render('file-upload', examples.disabled)

const $component = $('.govuk-file-upload')
expect($component.attr('disabled')).toBeTruthy()
Expand Down

0 comments on commit 834d32e

Please sign in to comment.