Skip to content

Commit adea354

Browse files
committed
Added paginator test
1 parent 29a3025 commit adea354

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

lib/src/paginator/Paginator.test.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,39 @@ global.DOMRect = {
2222

2323
describe("Paginator component tests", () => {
2424
test("Paginator renders with default values", () => {
25-
const { getByText } = render(<DxcPaginator></DxcPaginator>);
25+
const { getByText } = render(<DxcPaginator />);
2626
expect(getByText("1 to 1 of 1")).toBeTruthy();
2727
expect(getByText("Page: 1 of 1")).toBeTruthy();
2828
});
2929

3030
test("Paginator renders with currentPage", () => {
31-
const { getByText } = render(<DxcPaginator currentPage={2}></DxcPaginator>);
31+
const { getByText } = render(<DxcPaginator currentPage={2} />);
3232
expect(getByText("Page: 2 of 1")).toBeTruthy();
3333
});
3434

3535
test("Paginator renders with itemsPerPageOptions", () => {
3636
const { getByText } = render(
37-
<DxcPaginator currentPage={1} itemsPerPage={10} itemsPerPageOptions={[10, 15]} totalItems={20}></DxcPaginator>
37+
<DxcPaginator currentPage={1} itemsPerPage={10} itemsPerPageOptions={[10, 15]} totalItems={20} />
3838
);
3939
expect(getByText("Items per page:")).toBeTruthy();
4040
expect(getByText("1 to 10 of 20")).toBeTruthy();
4141
expect(getByText("Page: 1 of 2")).toBeTruthy();
4242
});
4343

4444
test("Paginator renders with totalItems", () => {
45-
const { getByText } = render(<DxcPaginator totalItems={20}></DxcPaginator>);
45+
const { getByText } = render(<DxcPaginator totalItems={20} />);
4646
expect(getByText("1 to 5 of 20")).toBeTruthy();
4747
expect(getByText("Page: 1 of 4")).toBeTruthy();
4848
});
4949

5050
test("Paginator renders with correct text in second page", () => {
51-
const { getByText } = render(<DxcPaginator currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>);
51+
const { getByText } = render(<DxcPaginator currentPage={2} itemsPerPage={10} totalItems={20} />);
5252
expect(getByText("11 to 20 of 20")).toBeTruthy();
5353
expect(getByText("Page: 2 of 2")).toBeTruthy();
5454
});
5555

5656
test("Paginator renders goToPage select", () => {
57-
const { getByText } = render(
58-
<DxcPaginator currentPage={2} showGoToPage itemsPerPage={10} totalItems={20}></DxcPaginator>
59-
);
57+
const { getByText } = render(<DxcPaginator currentPage={2} showGoToPage itemsPerPage={10} totalItems={20} />);
6058
expect(getByText("Go to page:")).toBeTruthy();
6159
});
6260

@@ -81,7 +79,7 @@ describe("Paginator component tests", () => {
8179
test("Call correct goToPageFunction", () => {
8280
const onClick = jest.fn();
8381
const { getAllByRole } = render(
84-
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
82+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20} />
8583
);
8684
const nextButton = getAllByRole("button")[2];
8785
userEvent.click(nextButton);
@@ -115,7 +113,7 @@ describe("Paginator component tests", () => {
115113
test("Next button is disable in last page", () => {
116114
const onClick = jest.fn();
117115
const { getAllByRole } = render(
118-
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
116+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20} />
119117
);
120118
const nextButton = getAllByRole("button")[2];
121119
expect(nextButton.hasAttribute("disabled")).toBeTruthy();
@@ -126,7 +124,7 @@ describe("Paginator component tests", () => {
126124
test("Last button is disable in last page", () => {
127125
const onClick = jest.fn();
128126
const { getAllByRole } = render(
129-
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
127+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20} />
130128
);
131129
const lastButton = getAllByRole("button")[3];
132130
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
@@ -137,7 +135,7 @@ describe("Paginator component tests", () => {
137135
test("First button is disable in first page", () => {
138136
const onClick = jest.fn();
139137
const { getAllByRole } = render(
140-
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
138+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20} />
141139
);
142140
const lastButton = getAllByRole("button")[0];
143141
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
@@ -148,7 +146,7 @@ describe("Paginator component tests", () => {
148146
test("Previous button is disable in first page", () => {
149147
const onClick = jest.fn();
150148
const { getAllByRole } = render(
151-
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
149+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20} />
152150
);
153151
const lastButton = getAllByRole("button")[1];
154152
expect(lastButton.hasAttribute("disabled")).toBeTruthy();
@@ -159,7 +157,7 @@ describe("Paginator component tests", () => {
159157
test("Last and next buttons are disable in last page", () => {
160158
const onClick = jest.fn();
161159
const { getAllByRole } = render(
162-
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20}></DxcPaginator>
160+
<DxcPaginator onPageChange={onClick} currentPage={2} itemsPerPage={10} totalItems={20} />
163161
);
164162
const firstButton = getAllByRole("button")[0];
165163
const prevButton = getAllByRole("button")[1];
@@ -174,7 +172,7 @@ describe("Paginator component tests", () => {
174172
test("First and previous buttons are disable in first page", () => {
175173
const onClick = jest.fn();
176174
const { getAllByRole } = render(
177-
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20}></DxcPaginator>
175+
<DxcPaginator onPageChange={onClick} currentPage={1} itemsPerPage={10} totalItems={20} />
178176
);
179177
const firstButton = getAllByRole("button")[0];
180178
const prevButton = getAllByRole("button")[1];
@@ -185,4 +183,12 @@ describe("Paginator component tests", () => {
185183
expect(nextButton.hasAttribute("disabled")).toBeFalsy();
186184
expect(lastButton.hasAttribute("disabled")).toBeFalsy();
187185
});
186+
187+
test("itemsPerPage is 0 and showGoToPage is true", () => {
188+
const { getByText, getAllByRole } = render(
189+
<DxcPaginator itemsPerPage={0} itemsPerPageOptions={[5, 10, 15]} totalItems={27} showGoToPage />
190+
);
191+
expect(getByText("Items per page:")).toBeTruthy();
192+
expect(getAllByRole("combobox")).toBeTruthy();
193+
});
188194
});

0 commit comments

Comments
 (0)