diff --git a/react-context-api/src/App.test.js b/react-context-api/src/App.test.js index 5c70fc828..161b89ab5 100644 --- a/react-context-api/src/App.test.js +++ b/react-context-api/src/App.test.js @@ -16,7 +16,10 @@ describe("Render App Component Without Error", () => { let wrapper; beforeEach(() => { const initialState = { - currentUser: {} + user: {}, + cart: [], + directory: [], + shop: [] }; wrapper = setUp(initialState); }); @@ -24,4 +27,8 @@ describe("Render App Component Without Error", () => { const component = findByDataAttr(wrapper, "app"); expect(component.length).toBe(1); }); + it("Should render App", () => { + const component = wrapper; + expect(component).toMatchSnapshot(); + }); }); diff --git a/react-context-api/src/__snapshots__/App.test.js.snap b/react-context-api/src/__snapshots__/App.test.js.snap new file mode 100644 index 000000000..ac9a59e37 --- /dev/null +++ b/react-context-api/src/__snapshots__/App.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Render App Component Without Error Should render App 1`] = `ShallowWrapper {}`; diff --git a/react-context-api/src/containers/CheckoutContainer/CheckoutContainer.js b/react-context-api/src/containers/CheckoutContainer/CheckoutContainer.js index e279a09d1..d19bfba81 100644 --- a/react-context-api/src/containers/CheckoutContainer/CheckoutContainer.js +++ b/react-context-api/src/containers/CheckoutContainer/CheckoutContainer.js @@ -12,8 +12,8 @@ import { import "./checkout.styles.scss"; import CheckoutItemContainer from "../CheckoutItemContainer/CheckoutItemContainer"; -const CheckoutPage = ({ cartItems, total }) => ( -
+const CheckoutContainer = ({ cartItems, total }) => ( +
Product @@ -49,4 +49,4 @@ const mapStateToProps = createStructuredSelector({ total: selectCartTotal }); -export default connect(mapStateToProps)(CheckoutPage); +export default connect(mapStateToProps)(CheckoutContainer); diff --git a/react-context-api/src/redux/cart/cart.actions.test.js b/react-context-api/src/redux/cart/cart.actions.test.js new file mode 100644 index 000000000..d7c187979 --- /dev/null +++ b/react-context-api/src/redux/cart/cart.actions.test.js @@ -0,0 +1,38 @@ +import CartActionTypes from "./cart.types"; +import { + toggleCartHidden, + addItem, + removeItem, + clearItemFromCart +} from "./cart.actions"; + +it("should create an action to toggleCartHidden", () => { + const expectedAction = { + type: CartActionTypes.TOGGLE_CART_HIDDEN + }; + expect(toggleCartHidden()).toEqual(expectedAction); +}); +it("should create an action to addItem", () => { + const item = { id: 2, title: "test 2" }; + const expectedAction = { + type: CartActionTypes.ADD_ITEM, + payload: item + }; + expect(addItem(item)).toEqual(expectedAction); +}); +it("should create an action to removeItem", () => { + const item = { id: 2, title: "test 2" }; + const expectedAction = { + type: CartActionTypes.REMOVE_ITEM, + payload: item + }; + expect(removeItem(item)).toEqual(expectedAction); +}); +it("should create an action to clearItemFromCart", () => { + const item = { id: 2, title: "test 2" }; + const expectedAction = { + type: CartActionTypes.CLEAR_ITEM_FROM_CART, + payload: item + }; + expect(clearItemFromCart(item)).toEqual(expectedAction); +}); diff --git a/react-context-api/src/redux/user/user.actions.test.js b/react-context-api/src/redux/user/user.actions.test.js new file mode 100644 index 000000000..2b74e5e57 --- /dev/null +++ b/react-context-api/src/redux/user/user.actions.test.js @@ -0,0 +1,11 @@ +import { UserActionTypes } from "./user.types"; +import { setCurrentUser } from "./user.actions"; + +it("should create an action to setCurrentUser", () => { + const user = { id: 2, email: "test@gmail.com" }; + const expectedAction = { + type: UserActionTypes.SET_CURRENT_USER, + payload: user + }; + expect(setCurrentUser(user)).toEqual(expectedAction); +});