From f02a5dc73ac4a14c1d641a6ddbfcd2f1bd2ea0b5 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Wed, 2 May 2018 14:45:20 -0400 Subject: TESTS --- frontend/__tests__/Cart.test.js | 34 +- frontend/__tests__/Item.test.js | 15 +- frontend/__tests__/Nav.test.js | 77 +++-- frontend/__tests__/Order.test.js | 40 ++- frontend/__tests__/Pagination.test.js | 27 +- frontend/__tests__/PleaseSignIn.test.js | 75 ++++- frontend/__tests__/RemoveFromCart.test.js | 3 +- frontend/__tests__/SingleItem.test.js | 3 +- frontend/__tests__/__snapshots__/Item.test.js.snap | 14 +- frontend/__tests__/__snapshots__/Nav.test.js.snap | 64 +--- .../__tests__/__snapshots__/Order.test.js.snap | 360 +++++++-------------- .../__snapshots__/Pagination.test.js.snap | 6 - frontend/__tests__/mockMang.js | 27 +- 13 files changed, 380 insertions(+), 365 deletions(-) (limited to 'frontend/__tests__') diff --git a/frontend/__tests__/Cart.test.js b/frontend/__tests__/Cart.test.js index b62d0de..c9c1fc3 100644 --- a/frontend/__tests__/Cart.test.js +++ b/frontend/__tests__/Cart.test.js @@ -4,13 +4,37 @@ import toJSON from 'enzyme-to-json'; import mountOptions from './mockMang'; import wait from 'waait'; import Cart from '../components/Cart'; +import { MockedProvider } from 'react-apollo/test-utils'; +import { fakeOrder } from './mockMang'; +import { LOCAL_STATE_QUERY } from '../queries/queries'; + +const mocks = [ + { + request: { query: CURRENT_USER_QUERY }, + result: { + data: { + me: { + ...fakeUser(), + cart: fakeCart(), + }, + }, + }, + }, +]; describe('', () => { + // TODO fix this one + expect('wes').toBe('fixed'); it('renders', async () => { - const wrapper = mount(, mountOptions); - await wait(); - wrapper.update(); - expect(toJSON(wrapper.find('header'))).toMatchSnapshot(); - expect(wrapper.find('CartItem')).toHaveLength(2); + const wrapper = mount( + + + + ); + console.log(wrapper.debug()); + // await wait(); + // wrapper.update(); + // expect(toJSON(wrapper.find('header'))).toMatchSnapshot(); + // expect(wrapper.find('CartItem')).toHaveLength(2); }); }); diff --git a/frontend/__tests__/Item.test.js b/frontend/__tests__/Item.test.js index 2990b1f..129efa9 100644 --- a/frontend/__tests__/Item.test.js +++ b/frontend/__tests__/Item.test.js @@ -3,7 +3,7 @@ import React from 'react'; import Enzyme, { shallow, mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; -import { ItemComponent } from '../components/Item'; +import ItemComponent from '../components/Item'; const fakeItem = { id: 'ABC123', @@ -15,17 +15,8 @@ const fakeItem = { }; describe('', () => { - it('Renders an item', () => { - const removeItem = jest.fn(); - const wrapper = shallow(); + it('Renders and matches snapshot', () => { + const wrapper = shallow(); expect(toJSON(wrapper)).toMatchSnapshot(); }); - it('handles button clicks', async () => { - const removeItem = jest.fn(); - global.confirm = jest.fn().mockReturnValue(true); - const wrapper = shallow(); - wrapper.find('button').simulate('click'); - expect(removeItem).toHaveBeenCalled(); - expect(global.confirm).toHaveBeenCalled(); - }); }); diff --git a/frontend/__tests__/Nav.test.js b/frontend/__tests__/Nav.test.js index 49d16d6..532ed3e 100644 --- a/frontend/__tests__/Nav.test.js +++ b/frontend/__tests__/Nav.test.js @@ -1,35 +1,70 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow, mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; -import { Nav } from '../components/Nav'; +import Nav from '../components/Nav'; +import { MockedProvider } from 'react-apollo/test-utils'; +import { fakeUser, fakeOrder } from './mockMang'; +import { CURRENT_USER_QUERY } from '../queries/queries'; +import wait from 'waait'; +// Mock the router +import Router from 'next/router'; + +Router.router = { push() {} }; const currentUserLoggedOut = { refetch() {}, }; -const currentUser = { - me: {}, - refetch() {}, -}; +const loggedOutMocks = [ + { + request: { query: CURRENT_USER_QUERY }, + delay: 0, + result: { + data: { + me: null, + }, + }, + }, +]; -describe('', () => { - it('renders', () => { - shallow(