Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,36 @@ describe("calcite-pagination", () => {
expect(toggleSpy).toHaveReceivedEventTimes(2);
});
});

describe("start-item", () => {
it("checks page defaults to 1 when start-item is negative", async () => {
const testCases = [
{
name: "page defaults to 1 when page-size equals total-items",
html: `<calcite-pagination page-size="25" start-item="1" total-items="10"></calcite-pagination>`,
},
{
name: "page defaults to 1 when page-size is less than total-items",
html: `<calcite-pagination page-size="25" start-item="1" total-items="10"></calcite-pagination>`,
},
{
name: "page defaults to 1 when page-size is greater than total-items",
html: `<calcite-pagination page-size="25" start-item="1" total-items="10"></calcite-pagination>`,
},
{
name: "page defaults to 1 when start-item is negative",
html: `<calcite-pagination start-item="-2" page-size="3"></calcite-pagination>`,
},
];

it.each(testCases)("$name", async ({ html }) => {
const page = await newE2EPage();
await page.setContent(`<calcite-pagination start-item="-2" page-size="3"></calcite-pagination>`);
await page.setContent(html);
const links = await findAll(page, `calcite-pagination >>> .${CSS.page}`);
expect(links.length).toBe(1);
expect(links).toHaveLength(1);
expect(await links[0].getProperty("value")).toBe("1");
});
});

describe("showing one item at a time", () => {
let page: E2EPage;
let pagination: E2EElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,8 @@ export class Pagination extends LitElement {
}

private handleLastStartItemChange(): void {
const { totalItems, pageSize, totalPages } = this;

const isStartNegative = totalItems - pageSize < 0;

this.lastStartItem =
(totalItems % pageSize === 0
? isStartNegative
? 0
: totalItems - pageSize
: Math.floor(totalPages) * pageSize) + 1;
const { totalItems, pageSize } = this;
this.lastStartItem = Math.max(1, Math.floor((totalItems - 1) / pageSize) * pageSize + 1);
}

private handleIsXXSmall(): void {
Expand Down
Loading