Skip to content

Commit

Permalink
Add unit tests for Cron value update management
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Jul 2, 2022
1 parent e50bdf5 commit 85b98ae
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 41 deletions.
49 changes: 36 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@testing-library/jest-dom": "5.16.4",
"@testing-library/react": "13.3.0",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "14.2.1",
"@types/node": "18.0.0",
"@types/react": "18.0.14",
"@types/react-dom": "18.0.5",
Expand Down
58 changes: 30 additions & 28 deletions src/tests/Cron.defaultValue.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render } from '@testing-library/react'
import { render, screen } from '@testing-library/react'

import Cron from '../Cron'
import {
Expand Down Expand Up @@ -559,7 +559,7 @@ describe('Cron defaultValue test suite', () => {
const setValue = jest.fn()
const onError = jest.fn()

const { getByTestId, queryByTestId } = render(
render(
<Cron
value={defaultValue}
setValue={setValue}
Expand Down Expand Up @@ -600,70 +600,72 @@ describe('Cron defaultValue test suite', () => {
// Check period dropdown

if (periodSelect) {
expect(getByTestId('select-period')).toBeVisible()
expect(getByTestId('select-period').textContent).toContain(periodSelect)
expect(screen.getByTestId('select-period')).toBeVisible()
expect(screen.getByTestId('select-period').textContent).toContain(
periodSelect
)
} else {
expect(queryByTestId(/select-period/i)).toBeNull()
expect(screen.queryByTestId(/select-period/i)).toBeNull()
}

//
// Check months dropdown

if (monthsSelect) {
expect(queryByTestId('custom-select-months')).toBeVisible()
expect(getByTestId('custom-select-months').textContent).toContain(
monthsSelect
)
expect(screen.queryByTestId('custom-select-months')).toBeVisible()
expect(
screen.getByTestId('custom-select-months').textContent
).toContain(monthsSelect)
} else {
expect(queryByTestId(/custom-select-months/i)).toBeNull()
expect(screen.queryByTestId(/custom-select-months/i)).toBeNull()
}

//
// Check month days dropdown

if (monthDaysSelect) {
expect(queryByTestId('custom-select-month-days')).toBeVisible()
expect(getByTestId('custom-select-month-days').textContent).toContain(
monthDaysSelect
)
expect(screen.queryByTestId('custom-select-month-days')).toBeVisible()
expect(
screen.getByTestId('custom-select-month-days').textContent
).toContain(monthDaysSelect)
} else {
expect(queryByTestId(/custom-select-month-days/i)).toBeNull()
expect(screen.queryByTestId(/custom-select-month-days/i)).toBeNull()
}

//
// Check week days dropdown

if (weekDaysSelect) {
expect(queryByTestId('custom-select-week-days')).toBeVisible()
expect(getByTestId('custom-select-week-days').textContent).toContain(
weekDaysSelect
)
expect(screen.queryByTestId('custom-select-week-days')).toBeVisible()
expect(
screen.getByTestId('custom-select-week-days').textContent
).toContain(weekDaysSelect)
} else {
expect(queryByTestId(/custom-select-week-days/i)).toBeNull()
expect(screen.queryByTestId(/custom-select-week-days/i)).toBeNull()
}

//
// Check hours dropdown

if (hoursSelect) {
expect(queryByTestId('custom-select-hours')).toBeVisible()
expect(getByTestId('custom-select-hours').textContent).toContain(
expect(screen.queryByTestId('custom-select-hours')).toBeVisible()
expect(screen.getByTestId('custom-select-hours').textContent).toContain(
hoursSelect
)
} else {
expect(queryByTestId(/custom-select-hours/i)).toBeNull()
expect(screen.queryByTestId(/custom-select-hours/i)).toBeNull()
}

//
// Check minutes dropdown

if (minutesSelect) {
expect(queryByTestId('custom-select-minutes')).toBeVisible()
expect(getByTestId('custom-select-minutes').textContent).toContain(
minutesSelect
)
expect(screen.queryByTestId('custom-select-minutes')).toBeVisible()
expect(
screen.getByTestId('custom-select-minutes').textContent
).toContain(minutesSelect)
} else {
expect(queryByTestId(/custom-select-minutes/i)).toBeNull()
expect(screen.queryByTestId(/custom-select-minutes/i)).toBeNull()
}
}
)
Expand Down
Loading

0 comments on commit 85b98ae

Please sign in to comment.