Skip to content

Commit 2681675

Browse files
committed
fix restart notice issue and test regression
1 parent 867a59e commit 2681675

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/client/settings/store/restart-notice.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const pendingReasons = async (
116116
return null;
117117
}
118118

119-
const key = state.reasons.join("|");
119+
const key = JSON.stringify(state.reasons);
120120
if (!state.pending || key === lastShownReasons) return null;
121121
lastShownReasons = key;
122122
return state.reasons;

‎tests/unit/restart-notice.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const loadNotice = async () => {
3636
return import("../../src/client/settings/store/restart-notice");
3737
};
3838

39+
const loadFresh = async (tag: string) => {
40+
stubWindow();
41+
return import(`../../src/client/settings/store/restart-notice?${tag}`);
42+
};
43+
3944
describe("restart notice state check", () => {
4045
beforeEach(() => {
4146
calls = [];
@@ -64,6 +69,26 @@ describe("restart notice state check", () => {
6469
expect(await pendingReasons(() => null)).toBeNull();
6570
});
6671

72+
test("keeps split reasons distinct from one reason holding a separator", async () => {
73+
const { pendingReasons } = await loadNotice();
74+
stubFetch(jsonOnce({ pending: true, reasons: ['plugin "a|b" was added'] }));
75+
expect(await pendingReasons(() => null)).toEqual(['plugin "a|b" was added']);
76+
77+
stubFetch(jsonOnce({ pending: true, reasons: ['plugin "a', 'b" was added'] }));
78+
expect(await pendingReasons(() => null)).toEqual([
79+
'plugin "a',
80+
'b" was added',
81+
]);
82+
});
83+
84+
test("still notifies when a pending restart carries no reasons", async () => {
85+
const { pendingReasons } = await loadFresh("empty-reasons");
86+
stubFetch(jsonOnce({ pending: true, reasons: [] }));
87+
88+
expect(await pendingReasons(() => null)).toEqual([]);
89+
expect(await pendingReasons(() => null)).toBeNull();
90+
});
91+
6792
test("returns nothing when the restart is not pending", async () => {
6893
const { pendingReasons } = await loadNotice();
6994
stubFetch(jsonOnce({ pending: false, reasons: ['engine "gamma" was added'] }));

0 commit comments

Comments
 (0)