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

chore: add tests for react-* headless components #347

Merged
merged 8 commits into from
Feb 3, 2023

Conversation

travis
Copy link
Member

@travis travis commented Feb 2, 2023

Basic testing to verify the components in Authenticator, Uploader, and UploadsList call the expected API functions from their respective providers.

Basic testing to verify the components in `Authenticator` call the expected API functions from the Keyring provider.
@travis travis requested review from alanshaw and olizilla February 2, 2023 09:36
@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 2, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b0bbb59:

Sandbox Source
@w3ui/example-react-file-upload Configuration
@w3ui/example-react-sign-up-in Configuration
@w3ui/example-react-uploads-list Configuration
@w3ui/example-solid-file-upload Configuration
@w3ui/example-solid-sign-up-in Configuration
@w3ui/example-solid-uploads-list Configuration
@w3ui/example-vue-file-upload Configuration
@w3ui/example-vue-sign-up-in Configuration
@w3ui/example-vue-uploads-list Configuration

Comment on lines 13 to 34
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement('div')
document.body.appendChild(container)
})

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container)
container.remove()
})

test('CancelButton', async () => {
const user = userEvent.setup()

const cancelRegisterSpace = vi.fn()
const contextValue: KeyringContextValue = [
keyringContextDefaultValue[0],
{ ...keyringContextDefaultValue[1], cancelRegisterSpace }
]
act(() => {
render((
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm new to testing-library, but i like the look of it and its goals. From looking at some examples it looks like we should be able to avoid the beforeEach / afterEach boilerplate and maybe the act step can go too? If we can get our tests looking more like this example that'd be rad https://github.com/kentcdodds/react-testing-library-course/blob/5abc1039d677767b8de5197c049bfd0428fa7420/src/__tests__/app-03.js#L12-L38

Copy link
Contributor

Choose a reason for hiding this comment

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

a handy list of things to avoid https://kentcdodds.com/blog/common-mistakes-with-react-testing-library which can be used to extrapolate what should be possible

Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

I think it's a good direction! Is it possible to reduce the boilerplate?

@travis
Copy link
Member Author

travis commented Feb 3, 2023

IT SURE IS - that blogpost is a gem - under its tutelage this is now much much cleaner

I used these in earlier versions of these tests but don't now
@travis
Copy link
Member Author

travis commented Feb 3, 2023

added a test for the Uploader as well

it would be nice to test that the uploads list renders something that
makes sense, but that's going to require a bit of restructuring to let
us mock out the `list` function
@travis travis changed the title feat: add tests for react-keyring Authenticator feat: add tests for react-* headless components Feb 3, 2023
@travis travis changed the title feat: add tests for react-* headless components chore: add tests for react-* headless components Feb 3, 2023
@travis
Copy link
Member Author

travis commented Feb 3, 2023

annnnd UploadsList

Copy link
Contributor

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

This is great!

We should do some learning around getByRole and use our tests to check that our components follow aria guidelines. It's not a replacement for a11y testing, but it's a baseline we can put in early to ensure we get the basics. No need to change anything in this PR, I'm just surfacing a thought that occurred as I read through.

@travis travis merged commit 46fa273 into main Feb 3, 2023
@travis travis deleted the feat/authenticator-tests branch February 3, 2023 13:56
@travis travis linked an issue Feb 3, 2023 that may be closed by this pull request
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.

add unit tests for React components
2 participants