Skip to content

Commit c81f664

Browse files
committed
feat(material/paginator/testing): Add isNextPageEnabled and isPreviousPageEnabled methods to MatPaginatorHarness
1 parent 87e0dc7 commit c81f664

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/material/paginator/testing/paginator-harness.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ export abstract class _MatPaginatorHarnessBase extends ComponentHarness {
3636
return (await this._nextButton()).click();
3737
}
3838

39+
/** Returns whether or not the next page button is enabled. */
40+
async isNextPageEnabled(): Promise<boolean> {
41+
const disabledValue = await (await this._nextButton()).getAttribute('disabled');
42+
return disabledValue != 'disabled';
43+
}
44+
45+
/* Returns whether or not the previous page button is enabled. */
46+
async isPreviousPageEnabled(): Promise<boolean> {
47+
const disabledValue = await (await this._nextButton()).getAttribute('disabled');
48+
return disabledValue != 'disabled';
49+
}
50+
3951
/** Goes to the previous page in the paginator. */
4052
async goToPreviousPage(): Promise<void> {
4153
return (await this._previousButton()).click();

src/material/paginator/testing/shared.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ export function runHarnessTests(
9797
);
9898
});
9999

100+
it('should return whether or not the previous page is disabled', async () => {
101+
const paginator = await loader.getHarness(paginatorHarness);
102+
expect(await paginator.isPreviousPageEnabled()).toBe(true);
103+
});
104+
105+
it('should return whether or not the next page is disabled', async () => {
106+
const paginator = await loader.getHarness(paginatorHarness);
107+
await paginator.goToLastPage();
108+
expect(await paginator.isNextPageEnabled()).toBe(true);
109+
});
110+
100111
it('should throw an error if the last page button is not available', async () => {
101112
const paginator = await loader.getHarness(paginatorHarness);
102113

tools/public_api_guard/material/paginator-testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ export abstract class _MatPaginatorHarnessBase extends ComponentHarness {
4141
goToLastPage(): Promise<void>;
4242
goToNextPage(): Promise<void>;
4343
goToPreviousPage(): Promise<void>;
44+
isNextPageEnabled(): Promise<boolean>;
45+
// (undocumented)
46+
isPreviousPageEnabled(): Promise<boolean>;
4447
// (undocumented)
4548
protected abstract _lastPageButton: AsyncFactoryFn<TestElement | null>;
4649
// (undocumented)

0 commit comments

Comments
 (0)