Skip to content

Commit

Permalink
style: avoid calling expect conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Jan 31, 2025
1 parent 6c3e4f1 commit 158f3a1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
32 changes: 20 additions & 12 deletions src/moj/components/date-picker/date-picker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,21 @@ describe('button menu JS API', () => {

new MOJFrontend.DatePicker(component, config).init()
calendarButton = screen.getByRole('button', { name: 'Choose date' })

await user.click(calendarButton)

for (let i = 1; i <= lastDayinMonth; i++) {
for (let i = 1; i <= minDay; i++) {
const testId = dayjs().date(i).startOf('day').format('D/M/YYYY')
const dayButton = screen.getByTestId(testId)

if (i <= minDay) {
expect(dayButton).toHaveAttribute('aria-disabled', 'true')
} else {
expect(dayButton).not.toHaveAttribute('aria-disabled')
}
expect(dayButton).toHaveAttribute('aria-disabled', 'true')
}

for (let i = minDay + 1; i <= lastDayinMonth; i++) {
const testId = dayjs().date(i).startOf('day').format('D/M/YYYY')
const dayButton = screen.getByTestId(testId)

expect(dayButton).not.toHaveAttribute('aria-disabled')
}
})

Expand All @@ -806,17 +810,21 @@ describe('button menu JS API', () => {

new MOJFrontend.DatePicker(component, config).init()
calendarButton = screen.getByRole('button', { name: 'Choose date' })

await user.click(calendarButton)

for (let i = 1; i <= lastDayinMonth; i++) {
for (let i = 1; i <= maxDay; i++) {
const testId = dayjs().date(i).startOf('day').format('D/M/YYYY')
const dayButton = screen.getByTestId(testId)

if (i > maxDay) {
expect(dayButton).toHaveAttribute('aria-disabled', 'true')
} else {
expect(dayButton).not.toHaveAttribute('aria-disabled')
}
expect(dayButton).not.toHaveAttribute('aria-disabled')
}

for (let i = maxDay + 1; i <= lastDayinMonth; i++) {
const testId = dayjs().date(i).startOf('day').format('D/M/YYYY')
const dayButton = screen.getByTestId(testId)

expect(dayButton).toHaveAttribute('aria-disabled', 'true')
}
})

Expand Down
17 changes: 9 additions & 8 deletions src/moj/components/sortable-table/sortable-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ describe('sortable table', () => {
})

test('initialises with buttons in headers', () => {
const headers = component.querySelectorAll('th')
headers.forEach((header) => {
if (header.getAttribute('aria-sort')) {
const button = header.querySelector('button')
expect(button).toBeInTheDocument()
expect(button).toHaveTextContent(header.textContent)
}
})
const headers = Array.from(component.querySelectorAll('th')).filter(
(header) => header.getAttribute('aria-sort')
)

for (const header of headers) {
const button = header.querySelector('button')
expect(button).toBeInTheDocument()
expect(button).toHaveTextContent(header.textContent)
}
})

test('creates status box for announcements', () => {
Expand Down

0 comments on commit 158f3a1

Please sign in to comment.