-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpage.test.tsx
More file actions
148 lines (120 loc) · 4.29 KB
/
page.test.tsx
File metadata and controls
148 lines (120 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.
import { render, screen } from '@testing-library/react';
import CreateGroupPage from './page';
import { Calendar } from '@/components/Calendar/calendar';
import userEvent from '@testing-library/user-event';
import { BUDGET_OPTIONS } from '@/constants/exchangeGroupOptions';
jest.mock('next/navigation', () => ({
useRouter: () => {},
}));
class MockResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
global.ResizeObserver = MockResizeObserver;
describe('Create Group Page', () => {
it('has the first group image selected by default', () => {
render(<CreateGroupPage />);
const [firstTile, ...otherTiles] = screen.getAllByRole('figure');
expect(firstTile).toHaveAttribute('data-state', 'checked');
otherTiles.forEach((imageTile) => {
expect(imageTile).toHaveAttribute('data-state', 'unchecked');
});
});
describe('Close (X) button', () => {
it('renders the X button with the correct href', () => {
render(<CreateGroupPage />);
expect(screen.getByTestId('x-button')).toHaveAttribute(
'href',
'/dashboard',
);
});
describe('Cancel button', () => {
it('renders the Cancel button with the correct href', () => {
render(<CreateGroupPage />);
expect(screen.getByRole('link', { name: /cancel/i })).toHaveAttribute(
'href',
'/dashboard',
);
});
});
});
describe('Calendar component in create group page', () => {
const currentDate = new Date('2025-10-15T00:00:00Z');
beforeEach(() => {
jest.useFakeTimers();
jest.setSystemTime(currentDate);
});
afterEach(() => {
jest.useRealTimers();
});
it('disables past dates correctly', () => {
render(
<Calendar
mode="single"
selected={currentDate}
onSelect={() => {}}
disabled={[{ before: currentDate }]}
initialFocus
/>,
);
const pastDate = screen.getByText('13');
expect(pastDate).toBeDisabled();
const today = screen.getByText('15');
expect(today).not.toBeDisabled();
const tomorrow = screen.getByText('16');
expect(tomorrow).not.toBeDisabled();
});
});
describe('Budget input', () => {
beforeEach(() => {
Element.prototype.scrollIntoView = jest.fn();
});
afterEach(() => {
jest.restoreAllMocks();
});
it('closes the popover when a selection is made', async () => {
render(<CreateGroupPage />);
const user = userEvent.setup();
const budgetOptionsTriggerButton = screen.getByTestId('budget-button');
await user.click(budgetOptionsTriggerButton);
const budgetOptions = screen.getAllByRole('option');
expect(budgetOptions).toHaveLength(BUDGET_OPTIONS.length);
const firstBudgetOption = budgetOptions[0];
await user.click(firstBudgetOption);
expect(screen.queryByRole('option')).not.toBeInTheDocument();
});
});
describe('Drawing date calendar input', () => {
it('closes the popover when a selection is made', async () => {
render(<CreateGroupPage />);
const user = userEvent.setup();
const drawingDateTriggerButton = screen.getByTestId(
'drawing-date-button',
);
expect(screen.queryByRole('gridcell')).not.toBeInTheDocument();
await user.click(drawingDateTriggerButton);
const calendarDays = screen.getAllByRole('gridcell');
const firstCalendarDay = calendarDays[calendarDays.length - 1];
await user.click(firstCalendarDay);
expect(screen.queryByRole('gridcell')).not.toBeInTheDocument();
});
});
describe('Exchange date calendar input', () => {
it('closes the popover when a selection is made', async () => {
render(<CreateGroupPage />);
const user = userEvent.setup();
const drawingDateTriggerButton = screen.getByTestId(
'exchange-date-button',
);
expect(screen.queryByRole('gridcell')).not.toBeInTheDocument();
await user.click(drawingDateTriggerButton);
const calendarDays = screen.getAllByRole('gridcell');
const firstCalendarDay = calendarDays[calendarDays.length - 1];
await user.click(firstCalendarDay);
expect(screen.queryByRole('gridcell')).not.toBeInTheDocument();
});
});
});