From 88ef4bd2df970cb6ea89123ffdd7fcb21dbc0f15 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Thu, 19 Apr 2018 10:09:51 -0400 Subject: xxxxxx --- frontend/__tests__/AddToCart.test.js | 8 +- frontend/__tests__/Order.test.js | 16 ++ frontend/__tests__/SingleItem.test.js | 20 +- .../__tests__/__snapshots__/Order.test.js.snap | 262 +++++++++++++++++++++ frontend/__tests__/mockMang.js | 13 +- frontend/components/AddToCart.js | 3 - frontend/components/Nav.js | 11 - frontend/components/Order.js | 4 +- 8 files changed, 303 insertions(+), 34 deletions(-) create mode 100644 frontend/__tests__/Order.test.js create mode 100644 frontend/__tests__/__snapshots__/Order.test.js.snap (limited to 'frontend') diff --git a/frontend/__tests__/AddToCart.test.js b/frontend/__tests__/AddToCart.test.js index 2285b3b..f049152 100644 --- a/frontend/__tests__/AddToCart.test.js +++ b/frontend/__tests__/AddToCart.test.js @@ -10,13 +10,17 @@ const currentUser = { describe('', () => { it('renders and matches snapshot', () => { - const wrapper = shallow( {}} currentUser={currentUser} />); + const wrapper = shallow( + {}} currentUser={currentUser} /> + ); expect(toJSON(wrapper)).toMatchSnapshot(); }); it('adds an item to the cart', () => { const addToCart = jest.fn(() => Promise.resolve()); - const wrapper = shallow(); + const wrapper = shallow( + + ); wrapper.simulate('click'); expect(addToCart).toHaveBeenCalled(); expect(addToCart).toHaveBeenCalledWith({ variables: { id: 'abc123' } }); diff --git a/frontend/__tests__/Order.test.js b/frontend/__tests__/Order.test.js new file mode 100644 index 0000000..6bcf0b9 --- /dev/null +++ b/frontend/__tests__/Order.test.js @@ -0,0 +1,16 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import wait from 'waait'; +import toJSON from 'enzyme-to-json'; +import Order from '../components/Order'; +import mountOptions from './mockMang'; + +describe('', () => { + it('Renders with Proper Data', async () => { + const wrapper = mount(, mountOptions); + await wait(); + wrapper.update(); + const order = wrapper.find('[data-test="order"]'); + expect(toJSON(order)).toMatchSnapshot(); + }); +}); diff --git a/frontend/__tests__/SingleItem.test.js b/frontend/__tests__/SingleItem.test.js index 313784e..3fe3943 100644 --- a/frontend/__tests__/SingleItem.test.js +++ b/frontend/__tests__/SingleItem.test.js @@ -1,19 +1,13 @@ import React from 'react'; -import { shallow, mount } from 'enzyme'; +import { mount } from 'enzyme'; import wait from 'waait'; import toJSON from 'enzyme-to-json'; import SingleItem from '../components/SingleItem'; -import { ApolloProvider } from 'react-apollo'; -import mockClient from './mockMang'; -import { SINGLE_ITEM_QUERY } from '../queries/queries'; +import mountOptions from './mockMang'; describe('', () => { it('Renders with Proper Data', async () => { - const wrapper = mount( - - - - ); + const wrapper = mount(, mountOptions); await wait(); wrapper.update(); @@ -21,11 +15,7 @@ describe('', () => { expect(toJSON(Item)).toMatchSnapshot(); }); - it('Errors with a not found Item', async () => { - const wrapper = mount( - - - - ); + xit('Errors with a not found Item', async () => { + const wrapper = mount(, mountOptions); }); }); diff --git a/frontend/__tests__/__snapshots__/Order.test.js.snap b/frontend/__tests__/__snapshots__/Order.test.js.snap new file mode 100644 index 0000000..21b9c35 --- /dev/null +++ b/frontend/__tests__/__snapshots__/Order.test.js.snap @@ -0,0 +1,262 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` Renders with Proper Data 1`] = ` +Array [ + +
+ + + +

+ + Order Id: + + + 3a430a73-c9e9-4bcc-b46a-41618965ffea + +

+

+ + Charge + + + Hello World + +

+

+ + Date + + + May 13, 2014 12:53 PM + +

+

+ + Order Total + + + $24.04 + +

+

+ + Item Count + + + 2 + +

+
+
+ Ut assumenda sint +
+

+ + Ut assumenda sint + +

+

+ Qty: + 8 +

+

+ Each: + $500 +

+

+ Subtotal: + $4,000 +

+

+ SubTotal: + Exercitationem omnis laborum exercitationem est sapiente laudantium. Assumenda quasi adipisci mollitia iste itaque omnis. +

+

+ Exercitationem omnis laborum exercitationem est sapiente laudantium. Assumenda quasi adipisci mollitia iste itaque omnis. +

+
+
+
+ Similique temporibus +
+

+ + Similique temporibus + +

+

+ Qty: + 9 +

+

+ Each: + $500 +

+

+ Subtotal: + $4,500 +

+

+ SubTotal: + Sapiente soluta corporis commodi. Nisi cum ducimus. Doloremque maiores esse atque et. +

+

+ Sapiente soluta corporis commodi. Nisi cum ducimus. Doloremque maiores esse atque et. +

+
+
+
+
+
, +
+ + + +

+ + Order Id: + + + 3a430a73-c9e9-4bcc-b46a-41618965ffea + +

+

+ + Charge + + + Hello World + +

+

+ + Date + + + May 13, 2014 12:53 PM + +

+

+ + Order Total + + + $24.04 + +

+

+ + Item Count + + + 2 + +

+
+
+ Ut assumenda sint +
+

+ + Ut assumenda sint + +

+

+ Qty: + 8 +

+

+ Each: + $500 +

+

+ Subtotal: + $4,000 +

+

+ SubTotal: + Exercitationem omnis laborum exercitationem est sapiente laudantium. Assumenda quasi adipisci mollitia iste itaque omnis. +

+

+ Exercitationem omnis laborum exercitationem est sapiente laudantium. Assumenda quasi adipisci mollitia iste itaque omnis. +

+
+
+
+ Similique temporibus +
+

+ + Similique temporibus + +

+

+ Qty: + 9 +

+

+ Each: + $500 +

+

+ Subtotal: + $4,500 +

+

+ SubTotal: + Sapiente soluta corporis commodi. Nisi cum ducimus. Doloremque maiores esse atque et. +

+

+ Sapiente soluta corporis commodi. Nisi cum ducimus. Doloremque maiores esse atque et. +

+
+
+
+
, +] +`; diff --git a/frontend/__tests__/mockMang.js b/frontend/__tests__/mockMang.js index 5a98c6a..7d65cd7 100644 --- a/frontend/__tests__/mockMang.js +++ b/frontend/__tests__/mockMang.js @@ -4,7 +4,7 @@ import casual from 'casual'; import PropTypes from 'prop-types'; // seed it so we get consistent results -casual.seed(123); +casual.seed(777); const typeDefs = importSchema('../backend/src/schema.graphql'); @@ -13,10 +13,21 @@ const typeDefs = importSchema('../backend/src/schema.graphql'); const mocks = { ID: () => casual.uuid, + DateTime: () => new Date(1400000000000), + Int: () => casual.integer(400, 5500), + OrderItem: () => ({ + quantity: casual.integer(1, 10), + image: 'dog.jpg', + title: casual.title, + description: casual.description, + price: () => 50000, + }), Item: () => ({ title: casual.title, description: casual.description, price: () => 50000, + image: 'dog.jpg', + largeImage: 'large-dog.jpg', }), User: () => ({ email: casual.email, diff --git a/frontend/components/AddToCart.js b/frontend/components/AddToCart.js index 01f9dc1..eead8f0 100644 --- a/frontend/components/AddToCart.js +++ b/frontend/components/AddToCart.js @@ -9,11 +9,8 @@ class AddToCart extends Component { }; update = (proxy, payload) => { - console.log('Updating!'); - console.log(payload); const newCartItem = payload.data.addToCart; const data = proxy.readQuery({ query: CURRENT_USER_QUERY }); - console.log(newCartItem); const existingIndex = data.me.cart.findIndex(cartItem => cartItem.id === newCartItem.id); if (existingIndex >= 0) { diff --git a/frontend/components/Nav.js b/frontend/components/Nav.js index a0bed90..acfdfd1 100644 --- a/frontend/components/Nav.js +++ b/frontend/components/Nav.js @@ -99,17 +99,6 @@ class Nav extends React.Component { My Account - {/* - {context => ( - - )} - */} {cache => (