|
| 1 | +import configureStore from "redux-mock-store"; |
| 2 | +import { UserMenu } from "../src/components/UserMenu"; |
| 3 | +import { afterEach, beforeEach, describe, expect, test } from "@jest/globals"; |
| 4 | + |
| 5 | +// const mockStore = configureStore([]); |
| 6 | + |
| 7 | +describe("UserMenu Component", () => { |
| 8 | + beforeEach(() => { |
| 9 | + localStorage.setItem( |
| 10 | + "userInfo", |
| 11 | + JSON.stringify({ |
| 12 | + user: { |
| 13 | + id: "123", |
| 14 | + user_metadata: { |
| 15 | + username: "John Doe", |
| 16 | + |
| 17 | + }, |
| 18 | + }, |
| 19 | + }), |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(() => { |
| 24 | + localStorage.clear(); |
| 25 | + }); |
| 26 | + |
| 27 | + test("check local storage", () => { |
| 28 | + expect(localStorage.getItem("userInfo")).not.toBeNull(); |
| 29 | + }); |
| 30 | + |
| 31 | + // Will finish the rest of the tests below in Sprint 3 |
| 32 | + |
| 33 | + // test("opens edit account dialog", () => { |
| 34 | + // render( |
| 35 | + // <Provider store={store}> |
| 36 | + // <Router> |
| 37 | + // <UserMenu /> |
| 38 | + // </Router> |
| 39 | + // </Provider>, |
| 40 | + // ); |
| 41 | + |
| 42 | + // fireEvent.click(screen.getByText("John Doe")); |
| 43 | + // fireEvent.click(screen.getByText("Edit Account")); |
| 44 | + |
| 45 | + // expect(screen.getByText("Edit Account")).toBeInTheDocument(); |
| 46 | + // expect(screen.getByLabelText("New User Name")).toBeInTheDocument(); |
| 47 | + // }); |
| 48 | + |
| 49 | + // test("opens delete account dialog", () => { |
| 50 | + // render( |
| 51 | + // <Provider store={store}> |
| 52 | + // <Router> |
| 53 | + // <UserMenu /> |
| 54 | + // </Router> |
| 55 | + // </Provider>, |
| 56 | + // ); |
| 57 | + |
| 58 | + // fireEvent.click(screen.getByText("John Doe")); |
| 59 | + // fireEvent.click(screen.getByText("Delete Account")); |
| 60 | + |
| 61 | + // expect(screen.getByText("Delete Account")).toBeInTheDocument(); |
| 62 | + // expect( |
| 63 | + // screen.getByText( |
| 64 | + // "Are you sure you want to delete your account? This action cannot be undone.", |
| 65 | + // ), |
| 66 | + // ).toBeInTheDocument(); |
| 67 | + // }); |
| 68 | + |
| 69 | + // test("logs out user", () => { |
| 70 | + // render( |
| 71 | + // <Provider store={store}> |
| 72 | + // <Router> |
| 73 | + // <UserMenu /> |
| 74 | + // </Router> |
| 75 | + // </Provider>, |
| 76 | + // ); |
| 77 | + |
| 78 | + // fireEvent.click(screen.getByText("John Doe")); |
| 79 | + // fireEvent.click(screen.getByText("Logout")); |
| 80 | + |
| 81 | + // // Add assertions to check if the user is logged out |
| 82 | + // }); |
| 83 | +}); |
0 commit comments