diff --git a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap
index 318c4ae8d9..69bd3893b8 100644
--- a/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap
+++ b/src/__tests__/snapshot-tests/__snapshots__/documenter.test.ts.snap
@@ -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",
},
@@ -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",
},
diff --git a/src/pagination/__tests__/pagination.test.tsx b/src/pagination/__tests__/pagination.test.tsx
index 692a764b39..e06c20dc81 100644
--- a/src/pagination/__tests__/pagination.test.tsx
+++ b/src/pagination/__tests__/pagination.test.tsx
@@ -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();
- 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();
- 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();
- 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']);
});
@@ -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();
- 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');
});
@@ -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();
diff --git a/src/test-utils/dom/pagination/index.ts b/src/test-utils/dom/pagination/index.ts
index 58416472ae..eb5ff65ce4 100644
--- a/src/test-utils/dom/pagination/index.ts
+++ b/src/test-utils/dom/pagination/index.ts
@@ -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.
*/