@@ -75,6 +75,11 @@ interface Case {
7575 section : string
7676 key : string
7777 initial : Record < string , unknown >
78+ /**
79+ * A value that another provider could give the setting, other than the edit and than what the rollback stored: a form
80+ * that took it would lose the edit. Absent when there is none (a switch has only two values).
81+ */
82+ other ?: unknown
7883 /** What the import answered with (the value that failed to be stored), and what the rollback stored later. */
7984 answered : unknown
8085 late : unknown
@@ -93,6 +98,7 @@ const cases: Case[] = [
9398 section : "about" ,
9499 key : "telemetrySetting" ,
95100 initial : { telemetrySetting : "enabled" } ,
101+ other : "unset" ,
96102 answered : "unset" ,
97103 late : "enabled" ,
98104 edit : "edit-telemetry" ,
@@ -119,6 +125,7 @@ const cases: Case[] = [
119125 section : "experimental" ,
120126 key : "experiments" ,
121127 initial : { experiments : { runSlashCommand : false } } ,
128+ other : { runSlashCommand : false , imageGeneration : true } , // another experiment, changed by another provider
122129 answered : { runSlashCommand : false } ,
123130 late : { runSlashCommand : false } ,
124131 edit : "edit-experiment" ,
@@ -132,6 +139,7 @@ const cases: Case[] = [
132139 section : "experimental" ,
133140 key : "imageGenerationProvider" ,
134141 initial : { imageGenerationProvider : providerIdentifiers . openrouter } ,
142+ other : "someone-elses" ,
135143 answered : "failed" ,
136144 late : providerIdentifiers . openrouter ,
137145 edit : "edit-image-provider" ,
@@ -145,6 +153,7 @@ const cases: Case[] = [
145153 section : "experimental" ,
146154 key : "openRouterImageGenerationSelectedModel" ,
147155 initial : { openRouterImageGenerationSelectedModel : "stored-model" } ,
156+ other : "someone-elses-model" ,
148157 answered : "failed-model" ,
149158 late : "stored-model" ,
150159 edit : "edit-image-model" ,
@@ -158,6 +167,7 @@ const cases: Case[] = [
158167 section : "prompts" ,
159168 key : "customSupportPrompts" ,
160169 initial : { customSupportPrompts : { ENHANCE : "stored" } } ,
170+ other : { ENHANCE : "someone-elses" } ,
161171 answered : { ENHANCE : "failed" } ,
162172 late : { ENHANCE : "stored" } ,
163173 edit : "edit-prompts" ,
@@ -203,8 +213,12 @@ describe("SettingsView – a late import refresh and the settings that have a se
203213 await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . lateText ) )
204214 } )
205215
206- it . each ( cases ) (
207- "keeps an unsaved edit of $name that the import did not store, though the value changed" ,
216+ // A switch has two values, so another provider's change to it is the edit or the value before it: the tracking cannot
217+ // make a difference there, and these tests would pass without it. Only the settings with a third value can fail.
218+ const withAThirdValue = cases . filter ( ( c ) => c . other !== undefined )
219+
220+ it . each ( withAThirdValue ) (
221+ "keeps an unsaved edit of $name that the import did not store, though another provider changed the value" ,
208222 async ( c ) => {
209223 render ( c . section , c . initial )
210224 await screen . findByTestId ( c . read )
@@ -213,7 +227,7 @@ describe("SettingsView – a late import refresh and the settings that have a se
213227 await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . edited ) )
214228 // Another provider changed it, and an import that stored something else is refreshed together with that change.
215229 hostPosts ( {
216- [ c . key ] : c . answered ,
230+ [ c . key ] : c . other ,
217231 settingsImportRefreshedAt : 1_000 ,
218232 settingsImportStoredKeys : [ "somethingElse" ] ,
219233 } )
@@ -223,21 +237,39 @@ describe("SettingsView – a late import refresh and the settings that have a se
223237 } ,
224238 )
225239
226- it . each ( cases ) (
240+ it . each ( withAThirdValue ) (
227241 "keeps an unsaved edit of $name through two partial refreshes and a change by another provider" ,
228242 async ( c ) => {
229243 render ( c . section , c . initial )
230244 await screen . findByTestId ( c . read )
231245 fireEvent . click ( screen . getByTestId ( c . edit ) )
232246 await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . edited ) )
233247
234- // A first import stored something else; then another provider changes the value; a second import stored something else .
248+ // A first import stored something else .. .
235249 hostPosts ( { settingsImportRefreshedAt : 1_000 , settingsImportStoredKeys : [ "somethingElse" ] } )
236- hostPosts ( { [ c . key ] : c . answered } )
237- hostPosts ( { [ c . key ] : c . late , settingsImportRefreshedAt : 2_000 , settingsImportStoredKeys : [ "another" ] } )
250+ expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . edited )
251+ // ... then another provider changes the value, which reaches the form with the refresh of a second import that
252+ // stored something else.
253+ hostPosts ( { [ c . key ] : c . other , settingsImportRefreshedAt : 2_000 , settingsImportStoredKeys : [ "another" ] } )
238254
239255 expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . edited ) // the edit is tracked across both
240256 expect ( screen . getByTestId ( "save-button" ) ) . toBeEnabled ( )
241257 } ,
242258 )
259+
260+ it . each ( cases ) ( "takes the stored value of $name from a late refresh after the edit was discarded" , async ( c ) => {
261+ render ( c . section , c . initial )
262+ const late = answerThenLate ( c )
263+ await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . answeredText ) )
264+ fireEvent . click ( screen . getByTestId ( c . edit ) )
265+ await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . edited ) )
266+
267+ // The user leaves the settings and discards the edit: the form is back to what is stored.
268+ fireEvent . click ( screen . getByRole ( "button" , { name : "settings:common.done" } ) )
269+ fireEvent . click ( await screen . findByText ( "settings:unsavedChangesDialog.discardButton" ) )
270+ late ( ) // and the rollback of the import then finishes
271+
272+ // An edit that is gone does not stop the late refresh from correcting the value.
273+ await waitFor ( ( ) => expect ( screen . getByTestId ( c . read ) . textContent ) . toBe ( c . lateText ) )
274+ } )
243275} )
0 commit comments