summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/__tests__')
-rw-r--r--frontend/__tests__/AddToCart.test.js24
-rw-r--r--frontend/__tests__/Cart.test.js30
-rw-r--r--frontend/__tests__/TakeMyMoney.test.js55
-rw-r--r--frontend/__tests__/__snapshots__/AddToCart.test.js.snap9
-rw-r--r--frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap18
5 files changed, 136 insertions, 0 deletions
diff --git a/frontend/__tests__/AddToCart.test.js b/frontend/__tests__/AddToCart.test.js
new file mode 100644
index 0000000..2285b3b
--- /dev/null
+++ b/frontend/__tests__/AddToCart.test.js
@@ -0,0 +1,24 @@
+import React from 'react';
+import { shallow, mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import { AddToCart } from '../components/AddToCart';
+
+const currentUser = {
+ me: {},
+ refetch() {},
+};
+
+describe('<AddtoCart/>', () => {
+ it('renders and matches snapshot', () => {
+ const wrapper = shallow(<AddToCart id="abc123" addToCart={() => {}} currentUser={currentUser} />);
+ expect(toJSON(wrapper)).toMatchSnapshot();
+ });
+
+ it('adds an item to the cart', () => {
+ const addToCart = jest.fn(() => Promise.resolve());
+ const wrapper = shallow(<AddToCart id="abc123" addToCart={addToCart} currentUser={currentUser} />);
+ wrapper.simulate('click');
+ expect(addToCart).toHaveBeenCalled();
+ expect(addToCart).toHaveBeenCalledWith({ variables: { id: 'abc123' } });
+ });
+});
diff --git a/frontend/__tests__/Cart.test.js b/frontend/__tests__/Cart.test.js
new file mode 100644
index 0000000..0936e97
--- /dev/null
+++ b/frontend/__tests__/Cart.test.js
@@ -0,0 +1,30 @@
+import React from 'react';
+import { shallow, mount } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import { Cart } from '../components/Cart';
+
+const cartItem = {
+ item: { price: 5000 },
+ quantity: 10,
+};
+
+const currentUser = {
+ me: {
+ cart: [cartItem, cartItem, cartItem],
+ },
+ refetch() {},
+};
+
+describe('<Cart/>', () => {
+ it('renders', () => {
+ const wrapper = shallow(<Cart currentUser={currentUser} />);
+ });
+
+ xit('opens', () => {
+ const wrapper = shallow(<Cart currentUser={currentUser} />);
+ expect('wes').toEqual('figure out how to call test context');
+ });
+ // it('renders', () => {
+ // shallow(<Cart currentUser={currentUserLoggedOut} />);
+ // });
+});
diff --git a/frontend/__tests__/TakeMyMoney.test.js b/frontend/__tests__/TakeMyMoney.test.js
new file mode 100644
index 0000000..2b33ca6
--- /dev/null
+++ b/frontend/__tests__/TakeMyMoney.test.js
@@ -0,0 +1,55 @@
+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 Router from 'next/router';
+
+const wait = amount => new Promise(resolve => setTimeout(resolve, amount));
+
+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('creates an order onToken', () => {
+ const createOrderSpy = jest.fn(() => Promise.resolve({ data: { createOrder: { id: 'xyz789' } } }));
+ const wrapper = shallow(<TakeMyMoney createOrder={createOrderSpy} currentUser={currentUser} />);
+ // manually run onToken
+ wrapper.instance().onToken({ id: 'abc123' });
+ 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' } } }));
+ NProgress.start = jest.fn();
+ const wrapper = shallow(<TakeMyMoney createOrder={createOrderSpy} currentUser={currentUser} />);
+ wrapper.instance().onToken({ id: 'abc123' });
+ expect(NProgress.start).toHaveBeenCalled();
+ });
+
+ it('routes to the order page', async () => {
+ 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' } });
+ });
+});
diff --git a/frontend/__tests__/__snapshots__/AddToCart.test.js.snap b/frontend/__tests__/__snapshots__/AddToCart.test.js.snap
new file mode 100644
index 0000000..999161c
--- /dev/null
+++ b/frontend/__tests__/__snapshots__/AddToCart.test.js.snap
@@ -0,0 +1,9 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<AddtoCart/> renders and matches snapshot 1`] = `
+<button
+ onClick={[Function]}
+>
+ 🛒 Add To Cart
+</button>
+`;
diff --git a/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap b/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap
new file mode 100644
index 0000000..8c77e01
--- /dev/null
+++ b/frontend/__tests__/__snapshots__/TakeMyMoney.test.js.snap
@@ -0,0 +1,18 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`<TakeMyMoney /> renders 1`] = `
+<ReactStripeCheckout
+ ComponentClass="span"
+ amount={150000}
+ className="StripeCheckout"
+ currency="USD"
+ description="Order of 30 Items From Sick Fits"
+ label="Pay With Card"
+ locale="auto"
+ name="Sick Fits Haul"
+ reconfigureOnUpdate={false}
+ stripeKey="pk_lclTtThFp8CnO3QtEZSd8HA9mFUps"
+ token={[Function]}
+ triggerEvent="onClick"
+/>
+`;