Skip to content

feat(material/paginator): Add isNextPageEnabled and isPreviousPageEnabled to MatPaginatorHarness #24784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2022
Merged
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
12 changes: 12 additions & 0 deletions src/material/paginator/testing/paginator-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ export abstract class _MatPaginatorHarnessBase extends ComponentHarness {
return (await this._nextButton()).click();
}

/** Returns whether or not the next page button is disabled. */
async isNextPageDisabled(): Promise<boolean> {
const disabledValue = await (await this._nextButton()).getAttribute('disabled');
return disabledValue == 'true';
}

/* Returns whether or not the previous page button is disabled. */
async isPreviousPageDisabled(): Promise<boolean> {
const disabledValue = await (await this._previousButton()).getAttribute('disabled');
return disabledValue == 'true';
}

/** Goes to the previous page in the paginator. */
async goToPreviousPage(): Promise<void> {
return (await this._previousButton()).click();
Expand Down
11 changes: 11 additions & 0 deletions src/material/paginator/testing/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ export function runHarnessTests(
);
});

it('should return whether or not the previous page is disabled', async () => {
const paginator = await loader.getHarness(paginatorHarness);
expect(await paginator.isPreviousPageDisabled()).toBe(true);
});

it('should return whether or not the next page is disabled', async () => {
const paginator = await loader.getHarness(paginatorHarness);
await paginator.goToLastPage();
expect(await paginator.isNextPageDisabled()).toBe(true);
});

it('should throw an error if the last page button is not available', async () => {
const paginator = await loader.getHarness(paginatorHarness);

Expand Down
3 changes: 3 additions & 0 deletions tools/public_api_guard/material/paginator-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export abstract class _MatPaginatorHarnessBase extends ComponentHarness {
goToLastPage(): Promise<void>;
goToNextPage(): Promise<void>;
goToPreviousPage(): Promise<void>;
isNextPageDisabled(): Promise<boolean>;
// (undocumented)
isPreviousPageDisabled(): Promise<boolean>;
// (undocumented)
protected abstract _lastPageButton: AsyncFactoryFn<TestElement | null>;
// (undocumented)
Expand Down