Skip to content

Commit d9f0155

Browse files
committed
test(settings): add parameterized rehydrate tests for random-custom normalization
Pins the merge() guard that downgrades completionSound from random-custom to none when the custom-sounds library is empty or absent on rehydrate. Generated-By: PostHog Code Task-Id: 2e7e511c-6b31-4480-8ac1-37863ddd7c3b
1 parent fca242c commit d9f0155

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

packages/ui/src/features/settings/settingsStore.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,42 @@ describe("feature settingsStore custom sounds", () => {
230230
const persisted = JSON.parse(lastCall[1]);
231231
expect(persisted.state.customSounds).toEqual([sound]);
232232
});
233+
234+
it.each([
235+
{
236+
label: "random-custom with empty customSounds array",
237+
persistedState: { completionSound: "random-custom", customSounds: [] },
238+
expectedCompletionSound: "none",
239+
},
240+
{
241+
label: "random-custom with absent customSounds key",
242+
persistedState: { completionSound: "random-custom" },
243+
expectedCompletionSound: "none",
244+
},
245+
{
246+
label: "random-custom with non-empty library",
247+
persistedState: {
248+
completionSound: "random-custom",
249+
customSounds: [sound],
250+
},
251+
expectedCompletionSound: "random-custom",
252+
},
253+
])(
254+
"rehydrate merge normalizes $label",
255+
async ({ persistedState, expectedCompletionSound }) => {
256+
getItem.mockResolvedValue(
257+
JSON.stringify({ state: persistedState, version: 0 }),
258+
);
259+
260+
useSettingsStore.setState({ completionSound: "none", customSounds: [] });
261+
262+
await useSettingsStore.persist.rehydrate();
263+
264+
expect(useSettingsStore.getState().completionSound).toBe(
265+
expectedCompletionSound,
266+
);
267+
},
268+
);
233269
});
234270

235271
describe("feature settingsStore terminal font", () => {

0 commit comments

Comments
 (0)