github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/__tests__/profile.test.tsx (about) 1 import { User } from "../../proto/qf/types_pb" 2 import { Provider } from "overmind-react" 3 import { createOvermindMock } from "overmind" 4 import { config } from "../overmind" 5 import Profile from "../components/profile/Profile" 6 import { Router } from "react-router-dom" 7 import { createMemoryHistory } from "history" 8 import React from "react" 9 import { render, screen } from "@testing-library/react" 10 11 12 describe("Profile", () => { 13 it("Renders with logged in user", () => { 14 const mockedOvermind = createOvermindMock(config, (state) => { 15 state.self = new User({ 16 ID: BigInt(1), 17 Name: "Test User", 18 }) 19 }) 20 const history = createMemoryHistory() 21 render( 22 <Provider value={mockedOvermind}> 23 <Router history={history}> 24 <Profile /> 25 </Router> 26 </Provider> 27 ) 28 const loggedIn = mockedOvermind.state.isLoggedIn 29 expect(loggedIn).toBe(true) 30 expect(screen.getByRole("heading").textContent).toBe("Hi, Test User") 31 }) 32 33 it("Logged in is false if the user is invalid", () => { 34 const mockedOvermind = createOvermindMock(config, (state) => { 35 state.self = new User({ 36 ID: BigInt(0), 37 }) 38 }) 39 const loggedIn = mockedOvermind.state.isLoggedIn 40 expect(loggedIn).toBe(false) 41 }) 42 })