Skip to content

Commit 94451eb

Browse files
Refactor SpotifyControls to strictly derive active device and tighten Playwright VRTs (#9684)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: arii <342438+arii@users.noreply.github.com>
1 parent 8a76ebe commit 94451eb

3 files changed

Lines changed: 4 additions & 16 deletions

File tree

app/client/control/components/SpotifyControls.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ const SpotifyControls = () => {
134134
})
135135
const { displayVolume } = state
136136
const isMuted = displayVolume === 0
137-
const [selectedDeviceId, setSelectedDeviceId] = useState<string>('')
138137

139138
const lastSentVolumeRef = useRef<string | null>(null)
140139
const lastWarningTimeRef = useRef<number>(0)
@@ -188,17 +187,7 @@ const SpotifyControls = () => {
188187

189188
const activeDeviceId = devices.find((device) => device.is_active)?.id
190189
const hrmDeviceId = hrmDevice?.id
191-
const resolvedId =
192-
activeDeviceId || (!selectedDeviceId ? hrmDeviceId || '' : selectedDeviceId)
193-
194-
useEffect(() => {
195-
if (devices.length === 0) return
196-
197-
if (resolvedId && selectedDeviceId !== resolvedId) {
198-
// eslint-disable-next-line react-hooks/set-state-in-effect
199-
setSelectedDeviceId(resolvedId)
200-
}
201-
}, [devices, selectedDeviceId, resolvedId])
190+
const resolvedId = activeDeviceId || hrmDeviceId || ''
202191

203192
const sendSpotifyCommand = useCallback(
204193
(
@@ -411,10 +400,9 @@ const SpotifyControls = () => {
411400
</Typography>
412401
<FormControl fullWidth size="small">
413402
<Select
414-
value={selectedDeviceId}
403+
value={resolvedId}
415404
onChange={(e) => {
416405
const deviceId = e.target.value as string
417-
setSelectedDeviceId(deviceId)
418406
if (deviceId) {
419407
sendSpotifyCommand('TRANSFER_PLAYBACK', deviceId)
420408
}

tests/playwright/vrt-components.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ test.describe('Component-Specific VRT', () => {
145145
await expect(menu).toHaveCSS('opacity', '1')
146146

147147
// Perform manual accessibility check on the specific menu element to ensure context validity
148-
await checkAccessibility(dashboardPage)
148+
await checkAccessibility(menu)
149149

150150
await takeScreenshot(menu, 'spotify-device-selector-menu.png', {
151151
threshold: 0.2, // Tighter threshold for the Paper element

tests/playwright/vrt-dashboard.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test.describe('Dashboard Visual Regression Tests', () => {
104104
const dashboard = dashboardPage.getByTestId('dashboard')
105105
await takeScreenshot(dashboard, 'dashboard-large-desktop.png', {
106106
mask: getDynamicContentMasks(dashboardPage),
107-
maxDiffPixelRatio: 0.15,
107+
maxDiffPixelRatio: 0.1,
108108
})
109109
})
110110

0 commit comments

Comments
 (0)