|
| 1 | +import React from "react"; |
| 2 | +import { createStore } from "redux"; |
| 3 | +import { Provider } from "react-redux"; |
| 4 | +import format from "date-fns/format"; |
| 5 | +import uuid from "uuid/v4"; |
| 6 | +import { render, screen, fireEvent } from "@testing-library/react"; |
| 7 | +import HistoryContainer from "../src/client/components/containers/HistoryContainer"; |
| 8 | +import * as actions from "../src/client/actions/actions.js"; |
| 9 | +import reducers from "../src/client/reducers/index.js"; |
| 10 | +import "@testing-library/jest-dom/extend-expect"; |
| 11 | +// import store from "../src/client/store"; |
| 12 | +import { getAllByAltText, queryAllByRole } from "@testing-library/react"; |
| 13 | + |
| 14 | +//generate date for today |
| 15 | +let today = new Date(); |
| 16 | +//generate date for yesterday |
| 17 | +let yesterday = new Date(); |
| 18 | +yesterday.setDate(yesterday.getDate() - 1); |
| 19 | +//generate date for two days prior |
| 20 | +let twoDaysAgo = new Date(); |
| 21 | +twoDaysAgo.setDate(twoDaysAgo.getDate() - 2); |
| 22 | + |
| 23 | + |
| 24 | +describe("history container test", () => { |
| 25 | + const initialState = { |
| 26 | + business: {history: [ |
| 27 | + { |
| 28 | + date: format(today, "MM/DD/YYYY"), |
| 29 | + history: [ |
| 30 | + { |
| 31 | + id: 1, |
| 32 | + created_at: today, |
| 33 | + url: "http://google.com", |
| 34 | + request: { |
| 35 | + method: "GET", |
| 36 | + }, |
| 37 | + }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + { |
| 41 | + date: format(yesterday, "MM/DD/YYYY"), |
| 42 | + history: [ |
| 43 | + { |
| 44 | + id: 2, |
| 45 | + created_at: yesterday, |
| 46 | + url: "http://facebook.com", |
| 47 | + request: { |
| 48 | + method: "GET", |
| 49 | + }, |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | + { |
| 54 | + date: format(twoDaysAgo, "MM/DD/YYYY"), |
| 55 | + history: [ |
| 56 | + { |
| 57 | + id: 3, |
| 58 | + created_at: twoDaysAgo, |
| 59 | + url: "http://instagram.com", |
| 60 | + request: { |
| 61 | + method: "GET", |
| 62 | + }, |
| 63 | + }, |
| 64 | + ], |
| 65 | + }, |
| 66 | + ], |
| 67 | + }} |
| 68 | + const renderWithRedux = ( |
| 69 | + component, |
| 70 | + { store = createStore(reducers, initialState) } = {} |
| 71 | + ) => { |
| 72 | + console.log('store is: ', store.getState()) |
| 73 | + console.log('initial state is: ', initialState) |
| 74 | + return { |
| 75 | + ...render(<Provider store={store}>{component}</Provider>), |
| 76 | + store, |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + beforeEach(() => { |
| 81 | + renderWithRedux(<HistoryContainer />); |
| 82 | + screen.debug(); |
| 83 | + }); |
| 84 | + test("renders history from store", () => { |
| 85 | + console.log(screen.queryAllByRole("queryDate")); |
| 86 | + expect(screen.queryAllByRole("queryDate").length).toBe(3); |
| 87 | + }); |
| 88 | + // test('renders a history header', () => { |
| 89 | + // expect(screen.queryByRole('queryDate')).toBeInTheDocument(); |
| 90 | + // }) |
| 91 | +}); |
| 92 | +//test if container renders |
| 93 | +// test("renders", () => { |
| 94 | +// render(<HistoryContainer />); |
| 95 | + |
| 96 | +// screen.debug(); |
| 97 | +// }); |
| 98 | + |
| 99 | +// |
| 100 | + |
| 101 | +/* FOR EACH COMPONENT - UNIT TESTING */ |
| 102 | +//renders |
| 103 | +//buttons work (clear history, etc.) |
| 104 | +//forms function (accepts input) |
| 105 | +//state updates appropriately |
| 106 | + |
0 commit comments