|
| 1 | +import { Provider } from "react-redux"; |
| 2 | +import store from "store/store"; |
| 3 | +import { MOCK_DATA } from "utils/mockData"; |
| 4 | +import App from "../../../App"; |
| 5 | +const { |
| 6 | + render, |
| 7 | + screen, |
| 8 | + waitFor, |
| 9 | + fireEvent, |
| 10 | +} = require("@testing-library/react"); |
| 11 | +const AppWrapper = () => { |
| 12 | + return ( |
| 13 | + <Provider store={store}> |
| 14 | + <App /> |
| 15 | + </Provider> |
| 16 | + ); |
| 17 | +}; |
| 18 | +jest.mock("utils/api", () => { |
| 19 | + return { |
| 20 | + get: () => ({ |
| 21 | + data: MOCK_DATA, |
| 22 | + }), |
| 23 | + }; |
| 24 | +}); |
| 25 | + |
| 26 | +test("data from API is displayed on initial load", async () => { |
| 27 | + render(<AppWrapper />); |
| 28 | + const benchmarkName = await screen.findByText("pbench_user_benchmark1"); |
| 29 | + const cells = await screen.findAllByRole("cell"); |
| 30 | + await waitFor(() => expect(benchmarkName).toBeInTheDocument()); |
| 31 | + await waitFor(() => expect(cells).toHaveLength(20)); |
| 32 | +}); |
| 33 | + |
| 34 | +test("row is favorited after clicking on favorite icon", async () => { |
| 35 | + render(<AppWrapper />); |
| 36 | + await screen.findByText("dhcp1"); |
| 37 | + const starBtn = screen.getAllByRole("button", { |
| 38 | + name: /not starred/i, |
| 39 | + }); |
| 40 | + fireEvent.click(starBtn[0]); |
| 41 | + fireEvent.click(starBtn[1]); |
| 42 | + const favoriteBtn = screen.getByRole("button", { |
| 43 | + name: /see favorites button/i, |
| 44 | + }); |
| 45 | + fireEvent.click(favoriteBtn); |
| 46 | + const favoriteCell = screen.getAllByRole("cell"); |
| 47 | + expect(favoriteCell).toHaveLength(8); |
| 48 | +}); |
0 commit comments