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

fix cell generated test template #1142

Merged
merged 5 commits into from
Sep 17, 2020
Merged

Conversation

thedavidprice
Copy link
Contributor

@peterp looping you in on this one. Dom and I are coordinating the generated tests that need to be fixed/completed. This seemed to do the trick for cells but would welcome your eyes/improvement.

@thedavidprice
Copy link
Contributor Author

Looking further, I found this original Cell test template sketch:
#629

Now looking into using the mock file to do something closer to ^^

@thedavidprice thedavidprice added this to In progress in Testing via automation Sep 12, 2020
@thedavidprice
Copy link
Contributor Author

closes #629

@thedavidprice
Copy link
Contributor Author

@peterp This one is ready for review -- any suggests about other/better ways to incorporate the existing mock file into the tests? Also, I took some notes from Robert for specific Jest queries used. Please confirm that's what you'd like to see in the template.

@RobertBroersma
Copy link
Contributor

RobertBroersma commented Sep 14, 2020

Hey @thedavidprice

Rendering the individual parts of a cell is kind of testing implementation details. What I would love to see is something more like in #629, but with MSW instead of MockedProvider

Something like this:

import { render, screen, graphql } from '@redwoodjs/testing'

import BlogPostCell from './BlogPostCell'

describe('BlogPostCell', () => {
  it('renders post succesfully', async () => {
    graphql.query('GetPost', (req, res, ctx) => {
      return res(
        ctx.data({
          post: {
            title: 'Post Title',
            id: 'id-123',
            body: 'Test',
            __typename: 'Post',
          },
        })
      )
    })

    render(<BlogPostCell id="id-123" />)

    expect(await screen.findByText(/Post Title/)).toBeInTheDocument()
  })

  it('handles errors', async () => {
    graphql.query('GetPost', (req, res, ctx) => {
      return res(
        ctx.errors([
          {
            message: 'Whoops!',
          },
        ])
      )
    })

    render(<BlogPostCell id={1} />)

    expect(await screen.findByText(/Whoops!/)).toBeInTheDocument()
  })
})

I'm not so familiar with the generator outputs, so I'm not sure if this is possible, but I think it is!

This way the test is closer to the real world use of BlogPostCell. The user will after all be using <BlogPostCell /> and not the individual parts of the cell.

Does that make sense?

Let me know if you'd like me to take a stab at writing the generator template!

Copy link
Contributor

@peterp peterp 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 @RobertBroersma's suggestion make sense, but this pull-request may have been focusing on fixing the test templates. Maybe we should open another issue for improving them?

@RobertBroersma
Copy link
Contributor

RobertBroersma commented Sep 16, 2020

@peterp Oh my bad, I didn't realize it was broken! I think the new issue you're describing is #629 . I'll put my snippet there.

All good here then!

@thedavidprice thedavidprice merged commit 840e449 into main Sep 17, 2020
Testing automation moved this from In progress to Done Sep 17, 2020
@thedavidprice thedavidprice deleted the dsp-fix-generator-test-templates branch September 17, 2020 23:41
@thedavidprice thedavidprice added this to the Next Release milestone Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Testing
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants