Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37744,6 +37744,42 @@ Returns the current value of the input.",
"name": "boolean",
},
},
{
"description": "Returns whether the "next page" button is disabled.",
"name": "isNextPageButtonDisabled",
"parameters": [],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
{
"description": "Returns whether the page number for a given index is disabled.",
"name": "isPageNumberByIndexDisabled",
"parameters": [
{
"description": "1-based index of the page number to check.",
"flags": {
"isOptional": false,
},
"name": "index",
"typeName": "number",
},
],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
{
"description": "Returns whether the "previous page" button is disabled.",
"name": "isPreviousPageButtonDisabled",
"parameters": [],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
],
"name": "PaginationWrapper",
},
Expand Down Expand Up @@ -48880,6 +48916,42 @@ To find a specific item use the \`findBreadcrumbLink(n)\` function as chaining \
"name": "ElementWrapper",
},
},
{
"description": "Returns whether the "next page" button is disabled.",
"name": "isNextPageButtonDisabled",
"parameters": [],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
{
"description": "Returns whether the page number for a given index is disabled.",
"name": "isPageNumberByIndexDisabled",
"parameters": [
{
"description": "1-based index of the page number to check.",
"flags": {
"isOptional": false,
},
"name": "index",
"typeName": "number",
},
],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
{
"description": "Returns whether the "previous page" button is disabled.",
"name": "isPreviousPageButtonDisabled",
"parameters": [],
"returnType": {
"isNullable": false,
"name": "boolean",
},
},
],
"name": "PaginationWrapper",
},
Expand Down
22 changes: 12 additions & 10 deletions src/pagination/__tests__/pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,25 @@ test('should re-render component correctly after current page state change', ()

test('should have both arrows disabled when there is only one page', () => {
const { wrapper } = renderPagination(<Pagination currentPageIndex={1} pagesCount={1} />);
expect(wrapper.findPreviousPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.findNextPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.isPreviousPageButtonDisabled()).toBe(true);
expect(wrapper.isNextPageButtonDisabled()).toBe(true);
expect(wrapper.findPageNumberByIndex(1)!.getElement()).toHaveTextContent('1');
expect(getItemsContent(wrapper)).toEqual(['1']);
});

test('should have both arrows disabled when there are no pages', () => {
const { wrapper } = renderPagination(<Pagination currentPageIndex={1} pagesCount={0} />);
expect(wrapper.findPreviousPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.findNextPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.isPreviousPageButtonDisabled()).toBe(true);
expect(wrapper.isNextPageButtonDisabled()).toBe(true);
expect(wrapper.findPageNumberByIndex(1)!.getElement()).toHaveTextContent('1');
expect(getItemsContent(wrapper)).toEqual(['1']);
});

test('should show all buttons when middle page selected', () => {
const { wrapper } = renderPagination(<Pagination currentPageIndex={5} pagesCount={9} />);
expect(wrapper.findPreviousPageButton().getElement()).not.toHaveAttribute('aria-disabled');
expect(wrapper.findNextPageButton().getElement()).not.toHaveAttribute('aria-disabled');
expect(wrapper.isPreviousPageButtonDisabled()).toBe(false);
expect(wrapper.isNextPageButtonDisabled()).toBe(false);
expect(wrapper.isPageNumberByIndexDisabled(3)).toBe(false);
expect(wrapper.findCurrentPage().getElement()).toHaveTextContent('5');
expect(getItemsContent(wrapper)).toEqual(['1', '2', '3', '4', '5', '6', '7', '8', '9']);
});
Expand All @@ -86,8 +87,8 @@ test('should not fire nextPageClick event when clicking next page with the last
test('should disable `previous` button when first page selected', () => {
const { wrapper } = renderPagination(<Pagination currentPageIndex={1} pagesCount={10} openEnd={openEnd} />);

expect(wrapper.findPreviousPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.findNextPageButton().getElement()).not.toHaveAttribute('aria-disabled');
expect(wrapper.isPreviousPageButtonDisabled()).toBe(true);
expect(wrapper.isNextPageButtonDisabled()).toBe(false);
expect(wrapper.findCurrentPage().getElement()).toHaveTextContent('1');
});

Expand Down Expand Up @@ -189,8 +190,9 @@ test('should not fire nextPageClick event when clicking next page with the last
);

expect(wrapper.isDisabled()).toBe(true);
expect(wrapper.findPreviousPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.findNextPageButton().getElement()).toHaveAttribute('aria-disabled', 'true');
expect(wrapper.isPreviousPageButtonDisabled()).toBe(true);
expect(wrapper.isNextPageButtonDisabled()).toBe(true);
expect(wrapper.isPageNumberByIndexDisabled(3)).toBe(true);

wrapper.findPreviousPageButton().click();
expect(onChange).not.toHaveBeenCalled();
Expand Down
25 changes: 25 additions & 0 deletions src/test-utils/dom/pagination/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,31 @@ export default class PaginationWrapper extends ComponentWrapper {
return this.find(`li:last-child .${styles.button}`)!;
}

/**
* Returns whether the "previous page" button is disabled.
*/
isPreviousPageButtonDisabled(): boolean {
return this.find(`li:first-child .${styles.button}[aria-disabled="true"]`) !== null;
}

/**
* Returns whether the "next page" button is disabled.
*/
isNextPageButtonDisabled(): boolean {
return this.find(`li:last-child .${styles.button}[aria-disabled="true"]`) !== null;
}

/**
* Returns whether the page number for a given index is disabled.
*
* @param index 1-based index of the page number to check.
*/
isPageNumberByIndexDisabled(index: number): boolean {
// we need to skip the "previous page" button
const pageIndex = index + 1;
return this.find(`li:nth-child(${pageIndex}) .${styles.button}[aria-disabled="true"]`) !== null;
}

/**
* Returns the jump to page input field.
*/
Expand Down
Loading