Adding some test
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { SessionList } from '../../../../src/components/stats/SessionList';
|
||||
|
||||
vi.mock('../../../../src/hooks/useSleepSession', () => ({
|
||||
useSessions: () => ({
|
||||
sessions: [
|
||||
{
|
||||
id: 1,
|
||||
start_time: '2026-06-04T11:58:00',
|
||||
end_time: '2026-06-04T13:58:00',
|
||||
notes: null,
|
||||
created_at: '2026-06-04T11:58:00',
|
||||
updated_at: '2026-06-04T11:58:00',
|
||||
},
|
||||
],
|
||||
isLoading: false,
|
||||
updateSession: vi.fn(),
|
||||
deleteSession: vi.fn(),
|
||||
isDeleting: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../../../../src/hooks/useSettings', () => ({
|
||||
useSettings: () => ({ settings: { sessionsPerPage: 10 } }),
|
||||
}));
|
||||
|
||||
const originalTZ = process.env.TZ;
|
||||
|
||||
beforeAll(() => {
|
||||
process.env.TZ = 'Europe/Stockholm';
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env.TZ = originalTZ;
|
||||
});
|
||||
|
||||
describe('SessionList edit timezone', () => {
|
||||
it('pre-fills edit inputs with local Stockholm time, not UTC', () => {
|
||||
const { container } = render(<SessionList />);
|
||||
|
||||
const clickableRow = container.querySelector('.cursor-pointer') as HTMLElement;
|
||||
expect(clickableRow).not.toBeNull();
|
||||
fireEvent.click(clickableRow);
|
||||
|
||||
const inputs = container.querySelectorAll('input[type="datetime-local"]');
|
||||
expect(inputs).toHaveLength(2);
|
||||
|
||||
// Backend sends 11:58 UTC (no Z). Stockholm is UTC+2, so local time is 13:58.
|
||||
expect((inputs[0] as HTMLInputElement).value).toBe('2026-06-04T13:58');
|
||||
// Backend sends 13:58 UTC → Stockholm 15:58
|
||||
expect((inputs[1] as HTMLInputElement).value).toBe('2026-06-04T15:58');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user