125 | {(loading || isFirstLoad) && (
126 |
127 | )}
128 |
129 | {!loading && (
130 |
131 | {children.map((child, index) => {
132 | const key = `glideItem-${index}`;
133 | return (
134 | goToSelectedDot(index)}
144 | >
145 | {child}
146 |
147 | );
148 | })}
149 |
150 | )}
151 |
152 | {(infinite || currentIndex !== 0) && (
153 |
162 | )}
163 |
164 | {(infinite || currentIndex !== children.length - 1) && (
165 |
174 | )}
175 |
176 | {dots && (
177 |
178 | {children.map((_child, index) => {
179 | const className = currentIndex === index ? 'active' : '';
180 | const key = `${className}--${index}`;
181 | return (
182 |
193 | )}
194 |
195 | );
196 | }
197 |
198 | export default Glide;
199 |
--------------------------------------------------------------------------------
/src/components/Glide.test.tsx:
--------------------------------------------------------------------------------
1 | import { act, render, screen, within } from '@testing-library/react';
2 | import userEvent from '@testing-library/user-event';
3 | import { Glide } from '~/components/Glide';
4 | import type { GlideProps } from '~/types';
5 |
6 | const user = userEvent.setup();
7 |
8 | HTMLElement.prototype.scrollIntoView = vi.fn();
9 |
10 | describe.each(['animated', 'swipeable'])('Glide %s', (variant) => {
11 | const props: GlideProps = {
12 | autoPlay: false,
13 | infinite: true,
14 | dots: true,
15 | swipeable: variant === 'swipeable',
16 | onSlideChange: vi.fn(),
17 | };
18 |
19 | beforeEach(() => {
20 | vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
21 | vi.resetAllMocks();
22 | });
23 |
24 | it('renders without crashing', () => {
25 | const baseProps = {
26 | width: 500 as number,
27 | autoPlay: false,
28 | onSlideChange: vi.fn(),
29 | };
30 | render(
31 |