summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-05-04 10:38:32 -0400
committerWes Bos <wesbos@gmail.com>2018-05-04 10:38:32 -0400
commit06003b7a5f66f61bde6bb2fc9443c8cf3bc8bd9b (patch)
tree4c47ee7c8c27db7d0b6ba9180ef49a720c06ba3a /frontend/__tests__
parentb6b0ee9c2ef43f4eef4df403897bcd8fd9ad2957 (diff)
First apollo mutation test
Diffstat (limited to 'frontend/__tests__')
-rw-r--r--frontend/__tests__/Cart.test.js4
-rw-r--r--frontend/__tests__/Nav.test.js2
-rw-r--r--frontend/__tests__/RemoveFromCart.test.js38
3 files changed, 23 insertions, 21 deletions
diff --git a/frontend/__tests__/Cart.test.js b/frontend/__tests__/Cart.test.js
index 9f4e98f..a215869 100644
--- a/frontend/__tests__/Cart.test.js
+++ b/frontend/__tests__/Cart.test.js
@@ -5,8 +5,8 @@ import mountOptions from '../lib/testUtils';
import wait from 'waait';
import Cart from '../components/Cart';
import { MockedProvider } from 'react-apollo/test-utils';
-import { fakeOrder } from '../lib/testUtils';
-import { LOCAL_STATE_QUERY } from '../queries/queries';
+import { fakeCart, fakeUser } from '../lib/testUtils';
+import { CURRENT_USER_QUERY } from '../queries/queries';
const mocks = [
{
diff --git a/frontend/__tests__/Nav.test.js b/frontend/__tests__/Nav.test.js
index 4989439..65f5eac 100644
--- a/frontend/__tests__/Nav.test.js
+++ b/frontend/__tests__/Nav.test.js
@@ -3,7 +3,7 @@ import { shallow, mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
import Nav from '../components/Nav';
import { MockedProvider } from 'react-apollo/test-utils';
-import { fakeUser, fakeOrder } from 'testUtils';
+import { fakeUser, fakeOrder } from './testUtils';
import { CURRENT_USER_QUERY } from '../queries/queries';
import wait from 'waait';
// Mock the router
diff --git a/frontend/__tests__/RemoveFromCart.test.js b/frontend/__tests__/RemoveFromCart.test.js
index a640722..acf5755 100644
--- a/frontend/__tests__/RemoveFromCart.test.js
+++ b/frontend/__tests__/RemoveFromCart.test.js
@@ -27,25 +27,36 @@ const mocks = [
query: REMOVE_FROM_CART_MUTATION,
variables: { id: 'abc123' },
},
- result: { data: { removeFromCart: { id: 'abc123' } } },
- },
- {
- request: { query: CURRENT_USER_QUERY },
result: {
data: {
- me: { name: 'hi', cart: [], permissions: [], orders: [], id: 22, email: 'jame@apollo.com' },
+ removeFromCart: {
+ __typename: 'CartItem',
+ id: 'abc123',
+ },
},
},
},
+ // {
+ // request: { query: CURRENT_USER_QUERY },
+ // result: {
+ // data: {
+ // me: { name: 'hi', cart: [], permissions: [], orders: [], id: 22, email: 'jame@apollo.com' },
+ // },
+ // },
+ // },
];
describe('<RemoveFromCart/>', () => {
it('renders and matches snapshot', () => {
- const wrapper = mountWithApollo(<RemoveFromCart id="123" />);
+ const wrapper = mount(
+ <MockedProvider mocks={mocks}>
+ <RemoveFromCart id="abc123" />
+ </MockedProvider>
+ );
expect(toJSON(wrapper.find('button'))).toMatchSnapshot();
});
- fit('removes an item from the cart', async () => {
+ it('removes an item from the cart', async () => {
// 1. Grab a copy of the current client
let apolloClient;
// const wrapper = mountWithApollo(<RemoveFromCart id="abc123" />);
@@ -64,21 +75,12 @@ describe('<RemoveFromCart/>', () => {
// check if it worked
const { me } = apolloClient.readQuery({ query: CURRENT_USER_QUERY });
expect(me.cart).toHaveLength(1);
- // expect(me.cart[0].item.price).toBe(5000);
+ expect(me.cart[0].item.price).toBe(5000);
// simulate a click, which will fire REMOVE_FROM_CART mock
wrapper.find('button').simulate('click');
await wait();
const { me: me2 } = apolloClient.readQuery({ query: CURRENT_USER_QUERY });
- // console.log('----------');
- // console.log(me2);
- // console.log('----------');
- // expect(me2.cart).toHaveLength(0);
- // await wait(2);
- // // the updated query from the mutation update
- // await apollo.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'cache-only' })
-
- // // sync
- // const user = apollo.readQuery({ query: CURRENT_USER_QUERY })
+ expect(me2.cart).toHaveLength(0);
});
});