11import { describe , expect , it , vi } from "vite-plus/test" ;
2- import { userEvent } from "vite-plus/test/browser" ;
2+ import { page , userEvent } from "vite-plus/test/browser" ;
33
44import { useState , type ReactNode } from "react" ;
55
@@ -124,6 +124,89 @@ async function renderAccentPicker(value: string) {
124124}
125125
126126describe ( "provider accent color picker" , ( ) => {
127+ it ( "leaves the optional color unset when the preview is dismissed" , async ( ) => {
128+ const onCommit = vi . fn ( ) ;
129+ await using _screen = await renderPicker (
130+ < ProviderAccentColorPicker
131+ displayName = "Example provider"
132+ value = { undefined }
133+ onCommit = { onCommit }
134+ /> ,
135+ ) ;
136+
137+ await open ( "Add accent color for Example provider" ) ;
138+ expect ( byLabel < HTMLInputElement > ( "Custom hex accent color" ) . value ) . toBe ( "#2563eb" ) ;
139+ expect ( onCommit ) . not . toHaveBeenCalled ( ) ;
140+ await userEvent . keyboard ( "{Escape}" ) ;
141+ expect ( onCommit ) . not . toHaveBeenCalled ( ) ;
142+ } ) ;
143+
144+ it ( "adds the displayed default without adjusting a color control" , async ( ) => {
145+ const onCommit = vi . fn ( ) ;
146+ await using screen = await renderPicker (
147+ < ProviderAccentColorPicker
148+ displayName = "Example provider"
149+ value = { undefined }
150+ onCommit = { onCommit }
151+ /> ,
152+ ) ;
153+
154+ await open ( "Add accent color for Example provider" ) ;
155+ await userEvent . click ( page . getByRole ( "button" , { name : "Add color" , exact : true } ) ) ;
156+
157+ expect ( onCommit ) . toHaveBeenCalledExactlyOnceWith ( "#2563eb" ) ;
158+ await expect
159+ . element ( screen . getByRole ( "button" , { name : "Change accent color for Example provider" } ) )
160+ . toBeVisible ( ) ;
161+ await vi . waitFor ( ( ) =>
162+ expect ( document . querySelector ( '[aria-label="Custom hex accent color"]' ) ) . toBeNull ( ) ,
163+ ) ;
164+ } ) ;
165+
166+ it ( "lets keyboard users add the displayed default" , async ( ) => {
167+ const onCommit = vi . fn ( ) ;
168+ await using screen = await renderPicker (
169+ < ProviderAccentColorPicker
170+ displayName = "Example provider"
171+ value = { undefined }
172+ onCommit = { onCommit }
173+ /> ,
174+ ) ;
175+
176+ await open ( "Add accent color for Example provider" ) ;
177+ await act ( async ( ) => byLabel ( "Accent color saturation" ) . focus ( ) ) ;
178+ await userEvent . tab ( ) ;
179+ await userEvent . tab ( ) ;
180+ await userEvent . tab ( ) ;
181+ await userEvent . tab ( ) ;
182+ await userEvent . keyboard ( "{Enter}" ) ;
183+
184+ expect ( onCommit ) . toHaveBeenCalledExactlyOnceWith ( "#2563eb" ) ;
185+ await expect
186+ . element ( screen . getByRole ( "button" , { name : "Change accent color for Example provider" } ) )
187+ . toBeVisible ( ) ;
188+ } ) ;
189+
190+ it ( "keeps live color editing and allows clearing back to unset" , async ( ) => {
191+ const onCommit = vi . fn ( ) ;
192+ await using screen = await renderPicker (
193+ < ProviderAccentColorPicker
194+ displayName = "Example provider"
195+ value = "#ff0000"
196+ onCommit = { onCommit }
197+ /> ,
198+ ) ;
199+
200+ await open ( "Change accent color for Example provider" ) ;
201+ await press ( HUE , "ArrowRight" , true ) ;
202+ expect ( onCommit ) . toHaveBeenLastCalledWith ( "#ff2a00" ) ;
203+ await userEvent . click ( page . getByRole ( "button" , { name : "Clear color" , exact : true } ) ) ;
204+ expect ( onCommit ) . toHaveBeenLastCalledWith ( "" ) ;
205+ await expect
206+ . element ( screen . getByRole ( "button" , { name : "Add accent color for Example provider" } ) )
207+ . toBeVisible ( ) ;
208+ } ) ;
209+
127210 it ( "commits a drag that is still in progress when the popover closes" , async ( ) => {
128211 await using screen = await renderAccentPicker ( "#ff0000" ) ;
129212
@@ -145,6 +228,9 @@ describe("provider accent color picker", () => {
145228 await userEvent . fill ( byLabel ( "Custom hex accent color" ) , "#ff0000" ) ;
146229
147230 expect ( screen . onCommit ) . toHaveBeenLastCalledWith ( "#ff0000" ) ;
231+ await userEvent . fill ( byLabel ( "Custom hex accent color" ) , "#00FF00" ) ;
232+ await screen . echo ( "#00FF00" ) ;
233+ expect ( byLabel < HTMLInputElement > ( "Custom hex accent color" ) . value ) . toBe ( "#00FF00" ) ;
148234 } ) ;
149235
150236 it ( "shows the saved color again when it is reverted outside the picker" , async ( ) => {
@@ -155,6 +241,12 @@ describe("provider accent color picker", () => {
155241 await screen . echo ( "#00ff00" ) ;
156242 await screen . echo ( "#ff0000" ) ;
157243
158- expect ( byLabel ( "Change accent color for Codex" ) . style . backgroundColor ) . toBe ( "rgb(255, 0, 0)" ) ;
244+ expect ( byLabel < HTMLInputElement > ( "Custom hex accent color" ) . value ) . toBe ( "#ff0000" ) ;
245+ await screen . echo ( "" ) ;
246+ expect ( byLabel < HTMLInputElement > ( "Custom hex accent color" ) . value ) . toBe ( "#2563eb" ) ;
247+ await userEvent . click ( page . getByRole ( "button" , { name : "Add color" , exact : true } ) ) ;
248+ expect ( screen . onCommit ) . toHaveBeenLastCalledWith ( "#2563eb" ) ;
249+
250+ expect ( byLabel ( "Change accent color for Codex" ) . style . backgroundColor ) . toBe ( "rgb(37, 99, 235)" ) ;
159251 } ) ;
160252} ) ;
0 commit comments