github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/web/src/StarredResourceBar.test.tsx (about) 1 import { render, screen } from "@testing-library/react" 2 import userEvent from "@testing-library/user-event" 3 import React from "react" 4 import { MemoryRouter } from "react-router" 5 import StarredResourceBar from "./StarredResourceBar" 6 import { ResourceStatus } from "./types" 7 8 const TEST_RESOURCES = [ 9 { name: "foo", status: ResourceStatus.Healthy }, 10 { name: "bar", status: ResourceStatus.Unhealthy }, 11 ] 12 13 describe("StarredResourceBar", () => { 14 let unstarSpy: jest.Mock 15 16 beforeEach(() => { 17 unstarSpy = jest.fn() 18 render( 19 <StarredResourceBar resources={TEST_RESOURCES} unstar={unstarSpy} />, 20 { wrapper: MemoryRouter } as any 21 ) 22 }) 23 24 it("renders the starred items", () => { 25 expect(screen.getByRole("button", { name: "foo" })).toBeInTheDocument() 26 expect(screen.getByRole("button", { name: "bar" })).toBeInTheDocument() 27 }) 28 29 it("renders starred logs link", () => { 30 expect( 31 screen.getByRole("button", { name: "All Starred" }) 32 ).toBeInTheDocument() 33 }) 34 35 it("calls unstar", () => { 36 userEvent.click(screen.getByLabelText("Unstar foo")) 37 38 expect(unstarSpy).toHaveBeenCalledWith("foo") 39 }) 40 })