File tree Expand file tree Collapse file tree
apps/web/src/components/device Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,6 +161,23 @@ it("keeps actions disabled when settings cannot be confirmed after a detached co
161161 expect ( controls . error ) . toBeNull ( ) ;
162162} ) ;
163163
164+ it ( "disables stale settings after a failed reopen read and recovers on a successful read" , async ( ) => {
165+ await mount ( ) ;
166+ await act ( async ( ) => renderer ! . update ( < Probe visible = { false } /> ) ) ;
167+ read . mockResolvedValueOnce ( { _tag : "Failure" , cause : "offline" } ) ;
168+ await act ( async ( ) => renderer ! . update ( < Probe visible /> ) ) ;
169+ expect ( controls . detail ) . toBeNull ( ) ;
170+ expect ( controls . disabled ) . toBe ( true ) ;
171+ expect ( controls . error ) . toBe ( "Device action failed" ) ;
172+ await act ( async ( ) => controls . act ( { type : "setAppearance" , value : "dark" } ) ) ;
173+ expect ( action ) . not . toHaveBeenCalled ( ) ;
174+ await act ( async ( ) => renderer ! . update ( < Probe visible = { false } /> ) ) ;
175+ await act ( async ( ) => renderer ! . update ( < Probe visible /> ) ) ;
176+ expect ( controls . detail ?. settings . appearance ) . toBe ( "light" ) ;
177+ expect ( controls . disabled ) . toBe ( false ) ;
178+ expect ( controls . error ) . toBeNull ( ) ;
179+ } ) ;
180+
164181it ( "does not let an older refresh overwrite a newer confirmed action" , async ( ) => {
165182 await mount ( ) ;
166183 await act ( async ( ) => renderer ! . update ( < Probe visible = { false } /> ) ) ;
Original file line number Diff line number Diff line change @@ -51,7 +51,10 @@ export function useDeviceControls(options: {
5151 if ( result . _tag === "Success" ) {
5252 setDetail ( result . value ) ;
5353 setError ( null ) ;
54- } else setError ( formatEnvironmentQueryError ( result . cause ) ) ;
54+ } else {
55+ setDetail ( null ) ;
56+ setError ( formatEnvironmentQueryError ( result . cause ) ) ;
57+ }
5558 } ) ;
5659 return ( ) => {
5760 visibleRead . current = null ;
You can’t perform that action at this time.
0 commit comments