UNPKG

4.11 kBJavaScriptView Raw
1import React from 'react';
2import { render, screen } from '@testing-library/react';
3import { PaginationLink } from '..';
4import {
5 testForCustomTag,
6 testForDefaultClass,
7 testForDefaultTag,
8} from '../testUtils';
9
10describe('PaginationLink', () => {
11 it('should render default `a` tag when `href` is present', () => {
12 render(<PaginationLink href="#" data-testid="endless" />);
13 expect(screen.getByTestId('endless').tagName).toBe('A');
14 });
15
16 it('should render default `button` tag when no `href` is present', () => {
17 testForDefaultTag(PaginationLink, 'button');
18 });
19
20 it('should render custom tag', () => {
21 testForCustomTag(PaginationLink, {}, 'span');
22 });
23
24 it('should render with "page-link" class', () => {
25 testForDefaultClass(PaginationLink, 'page-link');
26 });
27
28 it('should render previous', () => {
29 render(<PaginationLink previous />);
30
31 expect(screen.getByLabelText('Previous')).toBeInTheDocument();
32 expect(screen.getByText('Previous')).toHaveClass('visually-hidden');
33 expect(screen.getByText('\u2039')).toHaveAttribute('aria-hidden', 'true');
34 });
35
36 it('should render next', () => {
37 render(<PaginationLink next />);
38
39 expect(screen.getByLabelText('Next')).toBeInTheDocument();
40 expect(screen.getByText('Next')).toHaveClass('visually-hidden');
41 expect(screen.getByText('\u203A')).toHaveAttribute('aria-hidden', 'true');
42 });
43
44 it('should render default previous caret with children as an empty array', () => {
45 render(<PaginationLink previous children={[]} />);
46
47 expect(screen.getByLabelText('Previous')).toBeInTheDocument();
48 expect(screen.getByText('Previous')).toHaveClass('visually-hidden');
49 expect(screen.getByText('\u2039')).toHaveAttribute('aria-hidden', 'true');
50 });
51
52 it('should render default next caret with children as an empty array', () => {
53 render(<PaginationLink next children={[]} />);
54
55 expect(screen.getByLabelText('Next')).toBeInTheDocument();
56 expect(screen.getByText('Next')).toHaveClass('visually-hidden');
57 expect(screen.getByText('\u203A')).toHaveAttribute('aria-hidden', 'true');
58 });
59
60 it('should render custom aria label', () => {
61 render(<PaginationLink next aria-label="Yo" />);
62 expect(screen.getByLabelText('Yo')).toBeInTheDocument();
63 expect(screen.getByText('Yo')).toHaveClass('visually-hidden');
64 });
65
66 it('should render custom caret specified as a string', () => {
67 render(<PaginationLink next>Yo</PaginationLink>);
68
69 expect(screen.getByText('Yo')).toBeInTheDocument();
70 });
71
72 it('should render custom caret specified as a component', () => {
73 render(
74 <PaginationLink next>
75 <span>Yo</span>
76 </PaginationLink>,
77 );
78
79 expect(screen.getByText('Yo')).toBeInTheDocument();
80 expect(screen.getByText('Yo').tagName).toBe('SPAN');
81 });
82
83 it('should render first', () => {
84 render(<PaginationLink first />);
85
86 expect(screen.getByLabelText('First')).toBeInTheDocument();
87 expect(screen.getByText('First')).toHaveClass('visually-hidden');
88 expect(screen.getByText('\u00ab')).toHaveAttribute('aria-hidden', 'true');
89 });
90
91 it('should render last', () => {
92 render(<PaginationLink last />);
93
94 expect(screen.getByLabelText('Last')).toBeInTheDocument();
95 expect(screen.getByText('Last')).toHaveClass('visually-hidden');
96 expect(screen.getByText('\u00bb')).toHaveAttribute('aria-hidden', 'true');
97 });
98
99 it('should render default first caret with children as an empty array', () => {
100 render(<PaginationLink first children={[]} />);
101
102 expect(screen.getByLabelText('First')).toBeInTheDocument();
103 expect(screen.getByText('First')).toHaveClass('visually-hidden');
104 expect(screen.getByText('\u00ab')).toHaveAttribute('aria-hidden', 'true');
105 });
106
107 it('should render default last caret with children as an empty array', () => {
108 render(<PaginationLink last children={[]} />);
109
110 expect(screen.getByLabelText('Last')).toBeInTheDocument();
111 expect(screen.getByText('Last')).toHaveClass('visually-hidden');
112 expect(screen.getByText('\u00bb')).toHaveAttribute('aria-hidden', 'true');
113 });
114});