Skip to content

Commit 3d2c4cb

Browse files
committed
ci: locate topbar buttons and configs without UI copy
Signed-off-by: Dhruv Arora <dhruv.arora1@autodesk.com>
1 parent ae2e5a4 commit 3d2c4cb

7 files changed

Lines changed: 65 additions & 61 deletions

File tree

fission/src/test/ui/MatchModeConfigPanel.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe("MatchModeConfigPanel", () => {
5858
}
5959

6060
function getMatchModeCount(container: HTMLElement): number {
61-
return parseInt(getByText(container, /^\d+ Match Modes?$/).textContent!, 10)
61+
return container.querySelectorAll("[data-testid='match-mode-config']").length
6262
}
6363

6464
async function uploadMatchModeConfig(container: HTMLElement, json: unknown) {

fission/src/test/ui/Scoreboard.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import EventSystem from "@/systems/EventSystem"
55
import { MatchModeType } from "@/systems/match_mode/MatchModeTypes"
66
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
77
import Scoreboard from "@/ui/components/Scoreboard"
8-
import ScoreboardButton from "@/ui/components/topbar/ScoreboardButton"
8+
import { ScoreboardButton } from "@/ui/components/topbar/GameplayControls"
99

1010
const isShown = (container: HTMLElement) => container.firstChild !== null
1111

fission/src/test/ui/TopBar.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react"
1+
import { fireEvent, render, screen, waitFor } from "@testing-library/react"
22
import { act } from "react"
33
import { describe, expect, test, vi } from "vitest"
44
import EventSystem from "@/systems/EventSystem"
5-
import TopBar from "@/ui/components/TopBar"
5+
import { DragModeButton } from "@/ui/components/TopBar"
66

7-
const dragButton = () => within(screen.getByLabelText(/Drag Mode$/)).getByRole("button")
7+
const button = () => screen.getByRole("button")
88

99
describe("TopBar drag mode", () => {
1010
test("mirrors the drag mode command in both directions", async () => {
1111
const listener = vi.fn()
1212
const unlisten = EventSystem.listen("SetDragModeEvent", listener)
1313

14-
render(<TopBar />)
15-
expect(dragButton()).toHaveAttribute("aria-pressed", "false")
14+
render(<DragModeButton />)
15+
expect(button()).toHaveAttribute("aria-pressed", "false")
1616

1717
act(() => EventSystem.dispatch("SetDragModeEvent", { enabled: true }))
1818

19-
await waitFor(() => expect(dragButton()).toHaveAttribute("aria-pressed", "true"))
19+
await waitFor(() => expect(button()).toHaveAttribute("aria-pressed", "true"))
2020

21-
fireEvent.click(dragButton())
21+
fireEvent.click(button())
2222

2323
expect(listener).toHaveBeenLastCalledWith(expect.objectContaining({ enabled: false }))
24-
await waitFor(() => expect(dragButton()).toHaveAttribute("aria-pressed", "false"))
24+
await waitFor(() => expect(button()).toHaveAttribute("aria-pressed", "false"))
2525

2626
unlisten()
2727
})

fission/src/ui/components/TopBar.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ import { hasSimBrain } from "@/systems/simulation/wpilib_brain/WPILibState"
3434

3535
const TUTORIALS_URL = "https://synthesis.autodesk.com/tutorials"
3636

37+
export const DragModeButton: React.FC = () => {
38+
const [enabled, setEnabled] = useState(World.isAlive && World.dragModeSystem.enabled)
39+
40+
useEffect(() => EventSystem.listen("SetDragModeEvent", e => setEnabled(e.enabled)), [])
41+
42+
const toggleDragMode = () => EventSystem.dispatch("SetDragModeEvent", { enabled: !enabled })
43+
44+
return (
45+
<TopBarButton
46+
label={enabled ? "Disable Drag Mode" : "Drag Mode"}
47+
active={enabled}
48+
icon={
49+
<Box sx={TOP_BAR_GLYPH_SX}>
50+
<SynthesisIcons.HAND />
51+
</Box>
52+
}
53+
onClick={toggleDragMode}
54+
/>
55+
)
56+
}
57+
3758
const TopBar: React.FC = () => {
3859
const { openModal, openPanel, togglePanel, addToast } = useUIContext()
3960
const { appMode } = useStateContext()
@@ -47,16 +68,13 @@ const TopBar: React.FC = () => {
4768
const [userInfo, setUserInfo] = useState(APS.userInfo)
4869
const [modeHovered, setModeHovered] = useState(false)
4970
const [modeMenuOpen, setModeMenuOpen] = useState(false)
50-
const [dragModeEnabled, setDragModeEnabled] = useState(World.isAlive && World.dragModeSystem.enabled)
5171
const [touchControlsVisible, setTouchControlsVisible] = useState(() =>
5272
PreferencesSystem.getUserPreference("TouchControls")
5373
)
5474

5575
const rowRef = useRef<HTMLDivElement>(null)
5676
const spacerRef = useRef<HTMLDivElement>(null)
5777

58-
useEffect(() => EventSystem.listen("SetDragModeEvent", ({ enabled }) => setDragModeEnabled(enabled)), [])
59-
6078
useEffect(
6179
() =>
6280
EventSystem.listen("TouchControlsVisibilityChangedEvent", ({ visible }) =>
@@ -196,16 +214,7 @@ const TopBar: React.FC = () => {
196214
onClick={() => EventSystem.dispatch("ToggleTouchControlsVisibilityEvent")}
197215
/>
198216
)}
199-
<TopBarButton
200-
label={dragModeEnabled ? "Disable Drag Mode" : "Drag Mode"}
201-
active={dragModeEnabled}
202-
icon={
203-
<Box sx={TOP_BAR_GLYPH_SX}>
204-
<SynthesisIcons.HAND />
205-
</Box>
206-
}
207-
onClick={() => EventSystem.dispatch("SetDragModeEvent", { enabled: !dragModeEnabled })}
208-
/>
217+
<DragModeButton />
209218
<TopBarButton
210219
label="Configure Camera"
211220
icon={

fission/src/ui/components/topbar/GameplayControls.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
1-
import { Stack } from "@mui/material"
1+
import { Box, Stack } from "@mui/material"
22
import type React from "react"
3+
import { useEffect, useState } from "react"
4+
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
35
import { useUIContext } from "@/ui/helpers/UIProviderHelpers"
46
import MatchModeConfigPanel from "@/ui/panels/configuring/MatchModeConfigPanel"
57
import MultiplayerStartModal from "@/ui/modals/MultiplayerStartModal"
68
import { startMultiplayerWorld } from "@/ui/helpers/StartMultiplayerWorld"
7-
import ScoreboardButton from "@/ui/components/topbar/ScoreboardButton"
9+
import { SynthesisIcons } from "@/ui/components/StyledComponents"
810
import { TopBarButton } from "@/ui/components/topbar/TopBarButton"
11+
import { TOP_BAR_GLYPH_SX } from "@/ui/components/topbar/TopBarConfig"
912
import { TopBarIcon } from "@/ui/components/topbar/TopBarIcons"
1013

14+
export const ScoreboardButton: React.FC = () => {
15+
const [alwaysOn, setAlwaysOn] = useState(() => PreferencesSystem.getUserPreference("AlwaysShowScoreboard"))
16+
17+
useEffect(
18+
() => PreferencesSystem.addPreferenceEventListener("AlwaysShowScoreboard", e => setAlwaysOn(e.prefValue)),
19+
[]
20+
)
21+
22+
const toggleAlwaysOn = () => {
23+
PreferencesSystem.setUserPreference("AlwaysShowScoreboard", !alwaysOn)
24+
PreferencesSystem.savePreferences()
25+
}
26+
27+
return (
28+
<TopBarButton
29+
label={alwaysOn ? "Scoreboard: Always On" : "Scoreboard: Only During Matches"}
30+
active={alwaysOn}
31+
icon={
32+
<Box sx={TOP_BAR_GLYPH_SX}>
33+
<SynthesisIcons.SCOREBOARD />
34+
</Box>
35+
}
36+
onClick={toggleAlwaysOn}
37+
/>
38+
)
39+
}
40+
1141
const GameplayControls: React.FC = () => {
1242
const { openModal, togglePanel } = useUIContext()
1343

fission/src/ui/components/topbar/ScoreboardButton.tsx

Lines changed: 0 additions & 36 deletions
This file was deleted.

fission/src/ui/panels/configuring/MatchModeConfigPanel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const ItemCard: React.FC<ItemCardProps> = ({ id, name, primaryOnClick, secondary
152152
<Stack
153153
direction="row"
154154
key={id}
155+
data-testid="match-mode-config"
155156
justifyContent={"space-between"}
156157
alignItems={"center"}
157158
gap={"1rem"}

0 commit comments

Comments
 (0)