diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-04-19 12:58:17 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-04-19 12:58:17 -0400 |
| commit | e91740e812080fafa058b13b63218eeda4449135 (patch) | |
| tree | dd4f37b3a545d0cf8b1a13c66d0fbfd57f469d7e /frontend/__tests__ | |
| parent | dfc6977317473f0ba8bc7be66994a39968097b4f (diff) | |
take my money
Diffstat (limited to 'frontend/__tests__')
| -rw-r--r-- | frontend/__tests__/TakeMyMoney.test.js | 69 | ||||
| -rw-r--r-- | frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap | 55 |
2 files changed, 90 insertions, 34 deletions
diff --git a/frontend/__tests__/TakeMyMoney.test.js b/frontend/__tests__/TakeMyMoney.test.js index 2b33ca6..0117d30 100644 --- a/frontend/__tests__/TakeMyMoney.test.js +++ b/frontend/__tests__/TakeMyMoney.test.js @@ -2,54 +2,61 @@ import React from 'react'; import { shallow, mount } from 'enzyme'; import toJSON from 'enzyme-to-json'; import NProgress from 'nprogress'; -import { TakeMyMoney } from '../components/TakeMyMoney'; +import TakeMyMoney from '../components/TakeMyMoney'; import Router from 'next/router'; - -const wait = amount => new Promise(resolve => setTimeout(resolve, amount)); +import wait from 'waait'; +import mountOptions from './mockMang'; Router.router = { push() {} }; -const cartItem = { - item: { price: 5000 }, - quantity: 10, -}; - -const currentUser = { - me: { - cart: [cartItem, cartItem, cartItem], - }, - refetch() {}, -}; - describe('<TakeMyMoney />', () => { - it('renders', () => { - const wrapper = shallow(<TakeMyMoney createOrder={() => {}} currentUser={currentUser} />); - expect(toJSON(wrapper)).toMatchSnapshot(); + it('renders', async () => { + const wrapper = mount(<TakeMyMoney />, mountOptions); + // wait for it to load + await wait(); + wrapper.update(); + // find the button + const checkoutButton = wrapper.find('ReactStripeCheckout'); + expect(toJSON(checkoutButton)).toMatchSnapshot(); }); - it('creates an order onToken', () => { - const createOrderSpy = jest.fn(() => Promise.resolve({ data: { createOrder: { id: 'xyz789' } } })); - const wrapper = shallow(<TakeMyMoney createOrder={createOrderSpy} currentUser={currentUser} />); + it('creates an order onToken', async () => { + // TODO can this be done with a resolve jest fn? + const createOrderSpy = jest.fn(() => + Promise.resolve({ data: { createOrder: { id: 'xyz789' } } }) + ); + const wrapper = mount(<TakeMyMoney />, mountOptions); // manually run onToken - wrapper.instance().onToken({ id: 'abc123' }); + wrapper.instance().onToken({ id: 'abc123' }, createOrderSpy); + // check it expect(createOrderSpy).toBeCalled(); expect(createOrderSpy).toBeCalledWith({ variables: { token: 'abc123' } }); }); it('turns the progress bar on', () => { - const createOrderSpy = jest.fn(() => Promise.resolve({ data: { createOrder: { id: 'xyz789' } } })); + const createOrderSpy = jest.fn().mockResolvedValue({ + data: { createOrder: { id: 'xyz789' } }, + }); + + // spy on .start() NProgress.start = jest.fn(); - const wrapper = shallow(<TakeMyMoney createOrder={createOrderSpy} currentUser={currentUser} />); - wrapper.instance().onToken({ id: 'abc123' }); + const wrapper = mount(<TakeMyMoney />, mountOptions); + wrapper.instance().onToken({ id: 'abc123' }, createOrderSpy); expect(NProgress.start).toHaveBeenCalled(); }); - it('routes to the order page', async () => { + it('routes to the order page when completed', async () => { + const createOrderSpy = jest.fn().mockResolvedValue({ + data: { createOrder: { id: 'xyz789' } }, + }); + Router.router.push = jest.fn(); - const createOrderSpy = jest.fn(() => Promise.resolve({ data: { createOrder: { id: 'xyz789' } } })); - const wrapper = shallow(<TakeMyMoney createOrder={createOrderSpy} currentUser={currentUser} />); - wrapper.instance().onToken({ id: 'abc123' }); - await wait(0); - expect(Router.router.push).toHaveBeenCalledWith({ pathname: '/order/xyz789', query: { id: 'xyz789' } }); + const wrapper = mount(<TakeMyMoney />, mountOptions); + wrapper.instance().onToken({ id: 'abc123' }, createOrderSpy); + await wait(); + expect(Router.router.push).toHaveBeenCalledWith({ + pathname: '/order', + query: { id: 'xyz789' }, + }); }); }); diff --git a/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap b/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap index 8c77e01..cc83945 100644 --- a/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap +++ b/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap @@ -3,10 +3,12 @@ exports[`<TakeMyMoney /> renders 1`] = ` <ReactStripeCheckout ComponentClass="span" - amount={150000} + amount={281050000} className="StripeCheckout" currency="USD" - description="Order of 30 Items From Sick Fits" + description="Order of 5621 Items From Sick Fits" + email="Ella_Douglas@Lou.info" + image="dog.jpg" label="Pay With Card" locale="auto" name="Sick Fits Haul" @@ -14,5 +16,52 @@ exports[`<TakeMyMoney /> renders 1`] = ` stripeKey="pk_lclTtThFp8CnO3QtEZSd8HA9mFUps" token={[Function]} triggerEvent="onClick" -/> +> + <button + className="StripeCheckout" + onBlur={[Function]} + onClick={[Function]} + onFocus={[Function]} + onMouseDown={[Function]} + onMouseOut={[Function]} + onMouseUp={[Function]} + style={ + Object { + "background": "linear-gradient(#28a0e5,#015e94)", + "border": 0, + "borderRadius": 5, + "boxShadow": "0 1px 0 rgba(0,0,0,0.2)", + "cursor": "pointer", + "display": "inline-block", + "overflow": "hidden", + "padding": 1, + "textDecoration": "none", + "userSelect": "none", + "visibility": "visible", + } + } + > + <span + style={ + Object { + "backgroundImage": "linear-gradient(#7dc5ee,#008cdd 85%,#30a2e4)", + "borderRadius": 4, + "boxShadow": "inset 0 1px 0 rgba(255,255,255,0.25)", + "color": "#fff", + "display": "block", + "fontFamily": "\\"Helvetica Neue\\",Helvetica,Arial,sans-serif", + "fontSize": 14, + "fontWeight": "bold", + "height": 30, + "lineHeight": "30px", + "padding": "0 12px", + "position": "relative", + "textShadow": "0 -1px 0 rgba(0,0,0,0.25)", + } + } + > + Pay With Card + </span> + </button> +</ReactStripeCheckout> `; |
