Skip to content

Create custom GraphQL types for UserPage and UserList - #279

Merged
peacheym merged 21 commits into
masterfrom
create-custom-graphql-types
Apr 14, 2020
Merged

Create custom GraphQL types for UserPage and UserList#279
peacheym merged 21 commits into
masterfrom
create-custom-graphql-types

Conversation

@peacheym

@peacheym peacheym commented Apr 9, 2020

Copy link
Copy Markdown
Contributor

Additions

  • adds custom gql type for userPage
  • adds custom gql type (and dependents) for userList
  • Updates files and tests to use these new types.

peacheym and others added 18 commits April 9, 2020 10:07
This is the commit with the strange unused 'import App' that when removed breaks the tests.
Update error and loading state handlers for UserPage.
This test will check that when a listElement is clicked, the user is redirected to the user page which is at route '/user'.
Update logic for rendering in UserList.js
 - gcr.io/track-compliance/api:master-596f9ee
 - gcr.io/track-compliance/frontend:master-91c4299

[ci skip]
Add these types to the query type as well.
Update UserList.js to bind data based on new query format.
Update /graphql/queries to user new query format based on custom type.
Updated tests to user new query format.
Bind admin value to checkbox.

@Ethanljf Ethanljf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

UserPage and tests look good! Great stuff! 🍠

@nsdeschenes nsdeschenes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just checkout my comments

Comment thread frontend/schema.faker.graphql Outdated
Comment thread frontend/schema.faker.graphql
Use new subtype in query.
Update test and component to use new query.

@nsdeschenes nsdeschenes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect

import { UPDATE_PASSWORD } from '../graphql/mutations'

describe('<UserPage />', () => {
afterEach(cleanup)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is no longer required to call cleanup in the afterEach.

Comment on lines +54 to +69
it('renders without error', () => {
act(() => {
render(
<MockedProvider mocks={mocks} addTypename={false}>
<MemoryRouter initialEntries={['/']}>
<ThemeProvider theme={theme}>
<I18nProvider i18n={i18n}>
<UserPage />
</I18nProvider>
</ThemeProvider>
</MemoryRouter>
</MockedProvider>,
)
})
})
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If you asserted that the content you provided in the mocks was actually getting rendered this would be way better.
Since you are supplying the values in the mocks you can safely use getByText to find them in the output:
const { getByText } = render(...) and then await waitFor(() => getByText('sometext')).

newTag: master-4301b10
- name: gcr.io/track-compliance/frontend
newTag: master-7ee5ba8
newTag: master-91c4299

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't really belong in this commit.

Comment thread frontend/src/__tests__/UserList.test.js Outdated
</I18nProvider>
</ThemeProvider>,
)
expect(container).toBeDefined()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

container will always be defined here as it's the <div> within which the component is rendered.

Comment thread frontend/src/UserList.js Outdated
return (
<PseudoBox
key={edge.node.id}
role="userCard"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The role attribute refers to an ARIA role. There are fixed number of them defined in the standards and relied on by screen readers and other assistive technology. Most HTML elements have an implicit role (so a <button /> has an implied role=button.

PseudoBox here is probably a <div> by default, and the non-standard role of userCard is being added to it can be found by Testing Library's getAllByRole function later. I don't know if this would have actively negative consequences for assitive tech users (given that that role isn't a real ARIA role), but it's not a good idea.

Breaking these components down smaller and favouring composition makes it easier to test. Smaller components can spread props directly onto certain elements they render, allowing the use of getByTestId for really simple selections. This would be a better strategy to the way roles are being used here.

@peacheym peacheym Apr 11, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sleepycat Mike, thanks for the awesome feedback!!! Do you think a "userCard component would be better here???

Update UserList and UserList.test to accomodate these changes.  Update UserCard Test.

Add color check tests back to UserCard.test.js
@peacheym

Copy link
Copy Markdown
Contributor Author

@sleepycat please see my latest commit where I attempt to resolve all of the issues your found at the end of last week. Would love to chat about it more! 😄

@peacheym
peacheym merged commit 311a358 into master Apr 14, 2020
@peacheym
peacheym deleted the create-custom-graphql-types branch April 14, 2020 13:58
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.

4 participants