Skip to content

Commit

Permalink
test: more tests for closePanel callback
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald committed Oct 20, 2023
1 parent 5e0cd3f commit 29d32fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { render, screen } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { TabMode } from "../../../src/components/propertiesPanel/tabPanels"
import { closeButton } from "../../testHelpers/selectors/components/closeButton"

jest
.spyOn(dateTime, "now")
Expand Down Expand Up @@ -110,6 +111,23 @@ describe("GhostPropertiesPanel", () => {
expect(tree).toMatchSnapshot()
})

test("calls closePanel callback on close", async () => {
const mockClosePanel = jest.fn()

render(
<GhostPropertiesPanel
selectedGhost={ghost}
tabMode="status"
setTabMode={jest.fn()}
closePanel={mockClosePanel}
/>
)

await userEvent.click(closeButton.get())

expect(mockClosePanel).toHaveBeenCalled()
})

test.each<{ tab: TabMode; clickTarget: string; initialTab?: TabMode }>([
{ tab: "run", clickTarget: "Run" },
{ tab: "block", clickTarget: "Block" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "../../../src/hooks/useMinischedule"
import userEvent from "@testing-library/user-event"
import { TabMode } from "../../../src/components/propertiesPanel/tabPanels"
import { closeButton } from "../../testHelpers/selectors/components/closeButton"

jest.mock("../../../src/hooks/useMinischedule")

Expand Down Expand Up @@ -63,6 +64,24 @@ describe("StaleDataPropertiesPanel", () => {
expect(result.queryByText(/Run/)).toBeNull()
})

test("calls closePanel callback on close", async () => {
const vehicle = vehicleFactory.build()
const mockClosePanel = jest.fn()

render(
<StaleDataPropertiesPanel
selectedVehicle={vehicle}
tabMode="status"
setTabMode={jest.fn()}
closePanel={mockClosePanel}
/>
)

await userEvent.click(closeButton.get())

expect(mockClosePanel).toHaveBeenCalled()
})

test.each<{ tab: TabMode; clickTarget: string; initialTab?: TabMode }>([
{ tab: "run", clickTarget: "Run" },
{ tab: "block", clickTarget: "Block" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "../../../src/hooks/useMinischedule"
import { useTripShape } from "../../../src/hooks/useShapes"
import { fullStoryEvent } from "../../../src/helpers/fullStory"
import { closeButton } from "../../testHelpers/selectors/components/closeButton"

jest
.spyOn(dateTime, "now")
Expand Down Expand Up @@ -406,6 +407,23 @@ describe("VehiclePropertiesPanel", () => {
expect(container.innerHTML).toContain("c-station-icon")
})

test("calls closePanel callback on close", async () => {
const mockClosePanel = jest.fn()

render(
<VehiclePropertiesPanel
selectedVehicle={vehicle}
tabMode="status"
setTabMode={jest.fn()}
closePanel={mockClosePanel}
/>
)

await userEvent.click(closeButton.get())

expect(mockClosePanel).toHaveBeenCalled()
})

test.each<{ tab: TabMode; clickTarget: string; initialTab?: TabMode }>([
{ tab: "run", clickTarget: "Run" },
{ tab: "block", clickTarget: "Block" },
Expand Down

0 comments on commit 29d32fb

Please sign in to comment.