Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datepicker date change updates #1493

Merged
merged 5 commits into from Dec 7, 2020
Merged

datepicker date change updates #1493

merged 5 commits into from Dec 7, 2020

Conversation

jaketrent
Copy link
Contributor

@jaketrent jaketrent commented Dec 4, 2020

  • Several breaking API changes
    • onChange instead of onSelect
    • onSubBlur removal
    • onChange receives ChangeEvent instead of FocusEvent in union
  • Fix test problem where re-typing a date after a pre-selected date would cause loss of focus and lead to wrong values
  • Uncovered existing userEvent.type bug that we can work around but should be suspect for typing tests

After we ship, I'll send Will his updated test that works because of these internal DatePicker changes. But, also changed:

  • Use screen because queries don't need scoped to subtree
  • Use getByRole because there will only be one of what we're filtering to
  • Use toHaveValue because our codebase didn't have the to.have. chains setup
  • Use document.activeElement in tab tests, otherwise tabbing is less indicative of what's happening
  • Updated dd initial value to avoid uncovered testing-library bug
  it.only('wills test', async () => {
    render(<DatePicker value={new Date(2019, 0, 2)} />)
    const mm = screen.getByRole('textbox', { name: 'month' })
    const dd = screen.getByRole('textbox', { name: 'day' })
    const yyyy = screen.getByRole('textbox', { name: 'year' })
    expect(mm).toHaveValue('1')
    expect(dd).toHaveValue('2')
    expect(yyyy).toHaveValue('2019')
    mm.focus()
    userEvent.type(document.activeElement!, '07')
    userEvent.tab()
    userEvent.type(document.activeElement!, '15')
    userEvent.tab()
    userEvent.type(document.activeElement!, '2015')
    userEvent.tab()
    expect(mm).toHaveValue('7')
    expect(dd).toHaveValue('15')
    expect(yyyy).toHaveValue('2015')
  })

onSubBlur was unused.  Used in the old days as more of a bug workaround.

BREAKING CHANGE: Remove onSubBlur event listener
BREAKING CHANGE: onSelect event param type changed to receive
React.ChangeEvent instead of React.FocusEvent
BREAKING CHANGE: Rename onSelect to onChange to closer align with React
norms
Copy link
Contributor

@EdwardIrby EdwardIrby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an annoying bug if browser testing were faster or we felt like migrating I'd recommend unit testing in cypress so we could just use the real dom.

@jaketrent jaketrent merged commit be63c55 into master Dec 7, 2020
@jaketrent jaketrent deleted the fix/datepickerretype branch December 7, 2020 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants