|
| 1 | +import { MainGateProps } from "typings/MainGateProps"; |
| 2 | +import { |
| 3 | + dynamicPageEnabled, |
| 4 | + dynamicPageSizeEnabled, |
| 5 | + requestTotalCount, |
| 6 | + resolveInitPageSize |
| 7 | +} from "../pagination.config"; |
| 8 | + |
| 9 | +function makeProps(overrides = {}): Partial<MainGateProps> { |
| 10 | + return { |
| 11 | + pagination: "buttons", |
| 12 | + showNumberOfRows: false, |
| 13 | + pageSize: 10, |
| 14 | + pagingPosition: "bottom", |
| 15 | + useCustomPagination: false, |
| 16 | + showPagingButtons: "always", |
| 17 | + refreshIndicator: false, |
| 18 | + refreshInterval: 0, |
| 19 | + datasource: undefined, |
| 20 | + columns: [], |
| 21 | + filtersPlaceholder: undefined, |
| 22 | + ...overrides |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +describe("pagination.config helpers", () => { |
| 27 | + describe("requestTotalCount", () => { |
| 28 | + it("returns true when totalCountValue attribute is mapped regardless of pagination mode", () => { |
| 29 | + const props = makeProps({ totalCountValue: {}, pagination: "virtualScrolling" }); |
| 30 | + expect(requestTotalCount(props as MainGateProps)).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it("returns true for buttons pagination even without attribute", () => { |
| 34 | + const props = makeProps({ pagination: "buttons" }); |
| 35 | + expect(requestTotalCount(props as MainGateProps)).toBe(true); |
| 36 | + }); |
| 37 | + |
| 38 | + it("returns true when showNumberOfRows is true", () => { |
| 39 | + const props = makeProps({ pagination: "virtualScrolling", showNumberOfRows: true }); |
| 40 | + expect(requestTotalCount(props as MainGateProps)).toBe(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it("returns false for virtual scrolling without totalCountValue or showNumberOfRows", () => { |
| 44 | + const props = makeProps({ pagination: "virtualScrolling", showNumberOfRows: false }); |
| 45 | + expect(requestTotalCount(props as MainGateProps)).toBe(false); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + describe("dynamicPageEnabled", () => { |
| 50 | + it("is true when dynamicPage attribute is mapped for buttons mode", () => { |
| 51 | + const props = makeProps({ dynamicPage: {}, pagination: "buttons" }); |
| 52 | + expect(dynamicPageEnabled(props as MainGateProps)).toBe(true); |
| 53 | + }); |
| 54 | + |
| 55 | + it("is true when dynamicPage attribute is mapped for virtualScrolling mode", () => { |
| 56 | + const props = makeProps({ dynamicPage: {}, pagination: "virtualScrolling" }); |
| 57 | + expect(dynamicPageEnabled(props as MainGateProps)).toBe(true); |
| 58 | + }); |
| 59 | + |
| 60 | + it("is true when dynamicPage attribute is mapped for loadMore mode", () => { |
| 61 | + const props = makeProps({ dynamicPage: {}, pagination: "loadMore" }); |
| 62 | + expect(dynamicPageEnabled(props as MainGateProps)).toBe(true); |
| 63 | + }); |
| 64 | + |
| 65 | + it("is false when no dynamicPage attribute is provided", () => { |
| 66 | + const props = makeProps({ pagination: "virtualScrolling" }); |
| 67 | + expect(dynamicPageEnabled(props as MainGateProps)).toBe(false); |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + describe("dynamicPageSizeEnabled", () => { |
| 72 | + it("is true when dynamicPageSize attribute is mapped for buttons mode", () => { |
| 73 | + const props = makeProps({ dynamicPageSize: {}, pagination: "buttons" }); |
| 74 | + expect(dynamicPageSizeEnabled(props as MainGateProps)).toBe(true); |
| 75 | + }); |
| 76 | + |
| 77 | + it("is true when dynamicPageSize attribute is mapped for virtualScrolling mode", () => { |
| 78 | + const props = makeProps({ dynamicPageSize: {}, pagination: "virtualScrolling" }); |
| 79 | + expect(dynamicPageSizeEnabled(props as MainGateProps)).toBe(true); |
| 80 | + }); |
| 81 | + |
| 82 | + it("is true when dynamicPageSize attribute is mapped for loadMore mode", () => { |
| 83 | + const props = makeProps({ dynamicPageSize: {}, pagination: "loadMore" }); |
| 84 | + expect(dynamicPageSizeEnabled(props as MainGateProps)).toBe(true); |
| 85 | + }); |
| 86 | + |
| 87 | + it("is false when no dynamicPageSize attribute is provided", () => { |
| 88 | + const props = makeProps({ pagination: "loadMore" }); |
| 89 | + expect(dynamicPageSizeEnabled(props as MainGateProps)).toBe(false); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + describe("resolveInitPageSize", () => { |
| 94 | + it("returns 0 when dynamicPageSize attribute is set", () => { |
| 95 | + const props = makeProps({ dynamicPageSize: {} }); |
| 96 | + expect(resolveInitPageSize(props as MainGateProps)).toBe(0); |
| 97 | + }); |
| 98 | + |
| 99 | + it("falls back to constPageSize when dynamicPageSize is not set", () => { |
| 100 | + const props = makeProps({ pageSize: 10 }); |
| 101 | + expect(resolveInitPageSize(props as MainGateProps)).toBe(10); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments