Skip to content

Commit 549b924

Browse files
author
Akshita-2307
committed
fix(validations): hide_background=1 now works correctly via toBooleanFlag
Fixes JhaSourav07#1631 - Changed hide_background transform from toRefreshFlag to toBooleanFlag so '1' is accepted as truthy alongside 'true', matching hide_title and hide_stats behavior. - Updated test to expect hide_background='1' to return true. - Fixed upstream tracking.test.ts test that incorrectly expected sendBeacon to be called for empty usernames (the function returns early for falsy usernames).
1 parent 4538996 commit 549b924

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/validations.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,16 +552,15 @@ describe('streakParamsSchema — boolean transform fields', () => {
552552
});
553553

554554
// ── hide_background ────────────────────────────────────────────────────────
555-
// Stricter than hide_title/hide_stats — only exact 'true' is accepted,
556-
// '1' does NOT enable it.
555+
// Same dual-value rule as hide_title/hide_stats: 'true' and '1' are both truthy.
557556

558557
describe('hide_background', () => {
559558
it('returns true when hide_background="true"', () => {
560559
expect(parse({ hide_background: 'true' }).hide_background).toBe(true);
561560
});
562561

563-
it('returns false when hide_background="1" (only exact "true" accepted)', () => {
564-
expect(parse({ hide_background: '1' }).hide_background).toBe(false);
562+
it('returns true when hide_background="1" (both "true" and "1" accepted)', () => {
563+
expect(parse({ hide_background: '1' }).hide_background).toBe(true);
565564
});
566565

567566
it('returns false when hide_background="false"', () => {

lib/validations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const streakParamsSchema = z.object({
171171
),
172172
refresh: z.string().optional().transform(toRefreshFlag),
173173
hide_title: z.string().optional().transform(toBooleanFlag),
174-
hide_background: z.string().optional().transform(toRefreshFlag),
174+
hide_background: z.string().optional().transform(toBooleanFlag),
175175
hide_stats: z.string().optional().transform(toBooleanFlag),
176176
lang: z.string().optional().default('en'),
177177
// Unknown view values fall back to the default dashboard view.

utils/tracking.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,18 @@ describe('trackUser', () => {
8989

9090
it('handles empty username without crashing', () => {
9191
const sendBeaconMock = vi.fn().mockReturnValue(true);
92+
const fetchMock = vi.fn();
9293

9394
Object.defineProperty(navigator, 'sendBeacon', {
9495
value: sendBeaconMock,
9596
configurable: true,
9697
});
9798

99+
vi.stubGlobal('fetch', fetchMock);
100+
98101
expect(() => trackUser('')).not.toThrow();
99102
expect(sendBeaconMock).not.toHaveBeenCalled();
103+
expect(fetchMock).not.toHaveBeenCalled();
100104
});
101105

102106
it('falls back to fetch when sendBeacon returns false', () => {

0 commit comments

Comments
 (0)