Skip to content

Commit

Permalink
test(spindle-ui): add test of Pagination about rel attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Dai7Igarashi committed Oct 13, 2023
1 parent 4e88aaf commit 7175c09
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions packages/spindle-ui/src/Pagination/Pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('<Pagination />', () => {
<Pagination
total={20}
current={8}
linkFollowType="all"
showTotal={true}
createUrl={(pageNumber) => `/detail/${pageNumber}.html`}
onPageChange={onClick}
Expand All @@ -24,4 +25,63 @@ describe('<Pagination />', () => {
fireEvent.click(screen.getByText(1));
expect(onClick).toBeCalled();
});

test('should render all anchors without rel attribute when linkFollowType is all', () => {
render(
<Pagination
total={20}
current={8}
linkFollowType="all"
showTotal={true}
createUrl={(pageNumber) => `/detail/${pageNumber}.html`}
onPageChange={() => {}}
/>,
);

const anchors = screen.getAllByRole('link');
anchors.forEach((anchor) => {
expect(anchor).not.toHaveAttribute('rel');
});
});

test('should render all anchors with rel="nofollow" when linkFollowType is none', () => {
render(
<Pagination
total={20}
current={8}
linkFollowType="none"
showTotal={true}
createUrl={(pageNumber) => `/detail/${pageNumber}.html`}
onPageChange={() => {}}
/>,
);

const anchors = screen.getAllByRole('link');
anchors.forEach((anchor) => {
expect(anchor).toHaveAttribute('rel', 'nofollow');
});
});

test('should render anchors for first page without rel attribute and others with rel="nofollow" when linkFollowType is firstPage', () => {
render(
<Pagination
total={20}
current={8}
linkFollowType="firstPage"
showTotal={true}
createUrl={(pageNumber) => `/detail/${pageNumber}.html`}
onPageChange={() => {}}
/>,
);

const anchors = screen.getAllByRole('link');
anchors.forEach((anchor) => {
const isFirstPage = anchor.getAttribute('href') === '/detail/1.html';
if (isFirstPage) {
expect(anchor).not.toHaveAttribute('rel');
} else {
expect(anchor).toHaveAttribute('rel', 'nofollow');
}
});
});
});

0 comments on commit 7175c09

Please sign in to comment.