fix: update support wizard to show the correct offline status

The logic for isSupportOnline() was incorrect so support was marked as offline when we were supposed to be online.
This commit is contained in:
Copilot authored and GitHub committed 2025-09-29 20:57:04 -07:00
1 parent 963b3da44c
commit ffddd54145
2 files changed
+112 -4

No files matched your search

@@ -0,0 +1,105 @@
import { describe, expect, it, beforeEach, vi } from 'vitest';
import { isSupportOnline } from './store';
describe('isSupportOnline', () => {
beforeEach(() => {
vi.restoreAllMocks();
});
// Helper function to create a mock date
const mockDate = (hour: number, day: number) => {
const mockDate = new Date();
vi.spyOn(mockDate, 'getUTCDay').mockReturnValue(day);
vi.spyOn(mockDate, 'getUTCHours').mockReturnValue(hour);
vi.spyOn(global, 'Date').mockImplementation(() => mockDate);
return mockDate;
};
describe('weekday support hours (Monday-Friday)', () => {
it('should be online at 16:00 UTC (Monday)', () => {
mockDate(16, 1); // Monday, 16:00 UTC
expect(isSupportOnline()).toBe(true);
});
it('should be online at 20:00 UTC (Tuesday)', () => {
mockDate(20, 2); // Tuesday, 20:00 UTC
expect(isSupportOnline()).toBe(true);
});
it('should be online at 23:59 UTC (Wednesday)', () => {
mockDate(23, 3); // Wednesday, 23:59 UTC
expect(isSupportOnline()).toBe(true);
});
it('should be online at 23:00 UTC (Thursday)', () => {
mockDate(23, 4); // Thursday, 23:00 UTC
expect(isSupportOnline()).toBe(true);
});
it('should be online at 22:00 UTC (Friday)', () => {
mockDate(22, 5); // Friday, 22:00 UTC
expect(isSupportOnline()).toBe(true);
});
});
describe('outside support hours on weekdays', () => {
it('should be offline at 15:59 UTC (Monday)', () => {
mockDate(15, 1); // Monday, 15:59 UTC
expect(isSupportOnline()).toBe(false);
});
it('should be offline at 00:00 UTC (Tuesday)', () => {
mockDate(0, 2); // Tuesday, 00:00 UTC
expect(isSupportOnline()).toBe(false);
});
it('should be offline at 10:00 UTC (Wednesday)', () => {
mockDate(10, 3); // Wednesday, 10:00 UTC
expect(isSupportOnline()).toBe(false);
});
it('should be offline at 14:00 UTC (Friday)', () => {
mockDate(14, 5); // Friday, 14:00 UTC
expect(isSupportOnline()).toBe(false);
});
});
describe('weekends', () => {
it('should be offline on Saturday regardless of hour', () => {
mockDate(18, 6); // Saturday, 18:00 UTC (in support hours for weekdays)
expect(isSupportOnline()).toBe(false);
});
it('should be offline on Sunday regardless of hour', () => {
mockDate(0, 0); // Sunday, 00:00 UTC
expect(isSupportOnline()).toBe(false);
});
it('should be offline on Saturday at midnight', () => {
mockDate(0, 6); // Saturday, 00:00 UTC
expect(isSupportOnline()).toBe(false);
});
it('should be offline on Sunday at 16:00', () => {
mockDate(16, 0); // Sunday, 16:00 UTC
expect(isSupportOnline()).toBe(false);
});
});
describe('edge cases', () => {
it('should handle boundary at 15:59 (just before support hours)', () => {
mockDate(15, 1); // Monday, 15:59 UTC
expect(isSupportOnline()).toBe(false);
});
it('should handle boundary at 16:00 (start of support hours)', () => {
mockDate(16, 1); // Monday, 16:00 UTC
expect(isSupportOnline()).toBe(true);
});
it('should handle late night hours on Friday', () => {
mockDate(23, 5); // Friday, 23:00 UTC
expect(isSupportOnline()).toBe(true);
});
});
});
+7 -4
View File
@@ -20,15 +20,18 @@ export function isSupportOnline() {
const day = currentDate.getUTCDay();
const hour = currentDate.getUTCHours();
if (day === 1 || day === 6) {
// Support is offline on weekends (Sunday = 0, Saturday = 6)
if (day === 0 || day === 6) {
return false;
}
if (hour < 14) {
return false;
// Support hours are 16:00 UTC to 23:59 UTC on weekdays
// This roughly covers 09:00 PT to 17:00 PT (depending on PST/PDT)
if (hour >= 16) {
return true;
}
return true;
return false;
}
export const showSupportModal = writable(false);