-
Notifications
You must be signed in to change notification settings - Fork 685
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
PWA-989: Real Data Wishlists and Wishlist Create #3041
Merged
dpatil-magento
merged 19 commits into
magento:develop
from
magento-obsessive-owls:PWA-989
Mar 23, 2021
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
56c450c
PWA-989: Real Data Wishlists and Wishlist Create
eug123 7366994
PWA-989: Real Data Wishlists and Wishlist Create
eug123 fb11c50
PWA-989: Real Data Wishlists and Wishlist Create
eug123 597f55d
Merge remote-tracking branch 'mainline/develop' into PWA-989
eug123 f0a90cd
Merge branch 'develop' into PWA-989
eug123 7908916
PWA-989: Real Data Wishlists and Wishlist Create
eug123 586d663
Merge branch 'PWA-989' of github.com:magento-obsessive-owls/pwa-studi…
eug123 6bbfa3d
Merge branch 'develop' into PWA-989
eug123 36712af
PWA-989: Real Data Wishlists and Wishlist Create
eug123 4a71ca4
PWA-989: Real Data Wishlists and Wishlist Create
eug123 97993d5
Merge branch 'develop' into PWA-989
eug123 9c0e05f
Merge branch 'develop' into PWA-989
eug123 b16dbbb
PWA-989: Real Data Wishlists and Wishlist Create
eug123 5eebf8b
PWA-989: Real Data Wishlists and Wishlist Create
eug123 bac3020
Merge branch 'develop' into PWA-989
eug123 4b366a6
PWA-989: Real Data Wishlists and Wishlist Create
eug123 8a907e3
PWA-989: Real Data Wishlists and Wishlist Create
eug123 52227e3
Merge branch 'develop' into PWA-989
eug123 77e12c2
PWA-989: Real Data Wishlists and Wishlist Create
eug123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 76 additions & 38 deletions
114
packages/peregrine/lib/talons/WishlistPage/__tests__/useCreateWishlist.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,95 @@ | ||
import React from 'react'; | ||
|
||
import createTestInstance from '../../../util/createTestInstance'; | ||
import { useCreateWishlist } from '../useCreateWishlist'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
import { InMemoryCache } from '@apollo/client'; | ||
|
||
const Component = props => { | ||
const talonProps = useCreateWishlist(props); | ||
import { useCreateWishlist } from '../useCreateWishlist'; | ||
import defaultOperations from '../createWishlist.gql'; | ||
|
||
return <i talonProps={talonProps} />; | ||
const createWishlistVariables = { | ||
name: 'Test WishList', | ||
visibility: 'PUBLIC' | ||
}; | ||
|
||
const getTalonProps = props => { | ||
const tree = createTestInstance(<Component {...props} />); | ||
const { root } = tree; | ||
const { talonProps } = root.findByType('i').props; | ||
|
||
const update = newProps => { | ||
tree.update(<Component {...{ ...props, ...newProps }} />); | ||
const cache = new InMemoryCache().restore({ | ||
ROOT_QUERY: { | ||
customer: { | ||
id: 'customerId', | ||
firstName: 'Veronica', | ||
wishlists: [] | ||
} | ||
} | ||
}); | ||
|
||
return root.findByType('i').props.talonProps; | ||
}; | ||
const createWishlistMock = { | ||
request: { | ||
query: defaultOperations.createWishlistMutation, | ||
variables: createWishlistVariables | ||
}, | ||
result: () => { | ||
return { | ||
data: { | ||
createWishlist: { | ||
wishlist: { | ||
id: '42', | ||
name: 'Test WishList', | ||
visibility: 'PUBLIC' | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
return { talonProps, tree, update }; | ||
const renderHookWithProviders = ({ | ||
renderHookOptions = {}, | ||
mocks = [createWishlistMock] | ||
} = {}) => { | ||
const wrapper = ({ children }) => ( | ||
<MockedProvider mocks={mocks} cache={cache}> | ||
{children} | ||
</MockedProvider> | ||
); | ||
|
||
return renderHook(useCreateWishlist, { wrapper, ...renderHookOptions }); | ||
}; | ||
|
||
test('should return properly', () => { | ||
const { talonProps } = getTalonProps(); | ||
|
||
expect(talonProps).toMatchSnapshot(); | ||
const { result } = renderHookWithProviders(); | ||
expect(result.current).toMatchSnapshot(); | ||
}); | ||
|
||
test('handleShowModal should set isModalOpen to true', () => { | ||
const { talonProps, update } = getTalonProps(); | ||
|
||
talonProps.handleShowModal(); | ||
const { isModalOpen } = update(); | ||
|
||
expect(isModalOpen).toBeTruthy(); | ||
test('should return error', async () => { | ||
const createWishlistErrorMock = { | ||
request: createWishlistMock.request, | ||
error: new Error('Only 5 wish list(s) can be created.') | ||
}; | ||
const { result } = renderHookWithProviders({ | ||
mocks: [createWishlistErrorMock] | ||
}); | ||
await act(() => result.current.handleCreateList(createWishlistVariables)); | ||
expect( | ||
result.current.formErrors.get('createWishlistMutation') | ||
).toMatchInlineSnapshot(`[Error: Only 5 wish list(s) can be created.]`); | ||
}); | ||
|
||
test('handleHideModal should set isModalOpen to false', () => { | ||
const { talonProps, update } = getTalonProps(); | ||
|
||
talonProps.handleHideModal(); | ||
const { isModalOpen } = update(); | ||
|
||
expect(isModalOpen).toBeFalsy(); | ||
test('handleShowModal should set isModalOpen to true', async () => { | ||
const { result } = renderHookWithProviders(); | ||
await act(() => result.current.handleShowModal()); | ||
expect(result.current.isModalOpen).toBe(true); | ||
}); | ||
|
||
test('handleCreateList should set isModalOpen to false', () => { | ||
const { talonProps, update } = getTalonProps(); | ||
|
||
talonProps.handleCreateList(); | ||
const { isModalOpen } = update(); | ||
test('handleHideModal should set isModalOpen to false', async () => { | ||
const { result } = renderHookWithProviders(); | ||
await act(() => result.current.handleHideModal()); | ||
expect(result.current.isModalOpen).toBe(false); | ||
}); | ||
|
||
expect(isModalOpen).toBeFalsy(); | ||
test('handleCreateList should update cache and set isModalOpen to false', async () => { | ||
const { result } = renderHookWithProviders(); | ||
await act(() => result.current.handleCreateList(createWishlistVariables)); | ||
const updatedCache = cache.extract(); | ||
expect(updatedCache[`ROOT_QUERY`].customer.wishlists[0].id).toBe('42'); | ||
expect(result.current.isModalOpen).toBe(false); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/peregrine/lib/talons/WishlistPage/createWishlist.gql.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const CREATE_WISHLIST = gql` | ||
mutation createWishlist( | ||
$name: String! | ||
$visibility: WishlistVisibilityEnum! | ||
) { | ||
createWishlist(input: { name: $name, visibility: $visibility }) { | ||
tjwiebell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
wishlist { | ||
id | ||
items_count | ||
name | ||
visibility | ||
sharing_code | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const GET_CUSTOMER_WISHLISTS = gql` | ||
query GetCustomerWishlist { | ||
customer { | ||
id | ||
wishlists { | ||
id | ||
items_count | ||
name | ||
visibility | ||
sharing_code | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default { | ||
createWishlistMutation: CREATE_WISHLIST, | ||
getCustomerWishlistsQuery: GET_CUSTOMER_WISHLISTS | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you test the loading state of this mutation? I'm trying to do this in my PR but I'm having trouble...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, found it :D Just don't
await
the act'ed click.