Skip to content

Commit ce8584d

Browse files
authored
Merge pull request #1999 from fedspendingtransparency/FDG-8056
FDG-8056 Improve Code Coverage - page-buttons.jsx
2 parents ba3f973 + b660980 commit ce8584d

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/components/pagination/page-buttons.spec.js

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PageButtons from './page-buttons';
3-
import { render } from '@testing-library/react';
3+
import { fireEvent, render } from '@testing-library/react';
44
import { RecoilRoot } from 'recoil';
55

66
describe('PageButtons component', () => {
@@ -86,4 +86,53 @@ describe('PageButtons component', () => {
8686
const lastButton = getByRole('button', { name: `${tableName}-page10` });
8787
expect(lastButton).toBeInTheDocument();
8888
});
89+
90+
it('correctly changes to a new page when its button-number is clicked', () => {
91+
const { getByRole } = render(
92+
<RecoilRoot>
93+
<PageButtons pageButtonProps={pageButtonProps} />
94+
</RecoilRoot>
95+
);
96+
const secondButton = getByRole('button', { name: `${tableName}-page2` });
97+
expect(secondButton).toBeInTheDocument();
98+
fireEvent.click(secondButton);
99+
expect(secondButton).toHaveClass('active');
100+
});
101+
102+
it('correctly changes pages when clicking the next button', () => {
103+
pageButtonProps.currentPage = 1;
104+
const { getByRole } = render(
105+
<RecoilRoot>
106+
<PageButtons pageButtonProps={pageButtonProps} />
107+
</RecoilRoot>
108+
);
109+
const nextButton = getByRole('button', { name: 'Next page' });
110+
fireEvent.click(nextButton);
111+
const secondButton = getByRole('button', { name: `${tableName}-page2` });
112+
expect(secondButton).toHaveClass('active');
113+
});
114+
115+
it('correctly changes pages when clicking the previous button', () => {
116+
pageButtonProps.currentPage = 2;
117+
const { getByRole } = render(
118+
<RecoilRoot>
119+
<PageButtons pageButtonProps={pageButtonProps} />
120+
</RecoilRoot>
121+
);
122+
const prevButton = getByRole('button', { name: 'Previous page' });
123+
fireEvent.click(prevButton);
124+
const firstButton = getByRole('button', { name: `${tableName}-page1` });
125+
expect(firstButton).toHaveClass('active');
126+
});
127+
128+
it('renders the correct page range and ellipsis (when range > 7)', () => {
129+
pageButtonProps.maxPage = 8;
130+
const { getByRole } = render(
131+
<RecoilRoot>
132+
<PageButtons pageButtonProps={pageButtonProps} />
133+
</RecoilRoot>
134+
);
135+
const ellipsisButton = getByRole('button', { name: 'Page number overflow ellipsis' });
136+
expect(ellipsisButton).toBeInTheDocument();
137+
});
89138
});

0 commit comments

Comments
 (0)