/[sudobot]/trunk/tests/framework/pagination/Pagination.test.ts
ViewVC logotype

Diff of /trunk/tests/framework/pagination/Pagination.test.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 630 by rakinar2, Mon Jul 29 17:59:26 2024 UTC revision 631 by rakinar2, Tue Sep 10 15:53:22 2024 UTC
# Line 5  import { createApplication } from "../.. Line 5  import { createApplication } from "../..
5  describe("Pagination", () => {  describe("Pagination", () => {
6      createApplication();      createApplication();
7    
8        const emojiResolver = (_name: string) => {
9            return undefined;
10        };
11    
12      it("should initialize with default values", () => {      it("should initialize with default values", () => {
13          const pagination = new Pagination();          const pagination = new Pagination(undefined, emojiResolver);
14    
15          expect(pagination.state).toEqual({ page: 1 });          expect(pagination.state).toEqual({ page: 1 });
16          expect(pagination.limit).toBe(10);          expect(pagination.limit).toBe(10);
# Line 14  describe("Pagination", () => { Line 18  describe("Pagination", () => {
18    
19      it("should set fetcher correctly", () => {      it("should set fetcher correctly", () => {
20          const fetcher = vi.fn();          const fetcher = vi.fn();
21          const pagination = new Pagination().setFetcher(fetcher);          const pagination = new Pagination(undefined, emojiResolver).setFetcher(fetcher);
22    
23          expect(pagination["_fetcher"]).toBe(fetcher);          expect(pagination["_fetcher"]).toBe(fetcher);
24      });      });
25    
26      it("should set count getter correctly", () => {      it("should set count getter correctly", () => {
27          const getCount = vi.fn();          const getCount = vi.fn();
28          const pagination = new Pagination().setCountGetter(getCount);          const pagination = new Pagination(undefined, emojiResolver).setCountGetter(getCount);
29    
30          expect(pagination["_getCount"]).toBe(getCount);          expect(pagination["_getCount"]).toBe(getCount);
31      });      });
32    
33      it("should set initial message correctly", () => {      it("should set initial message correctly", () => {
34          const message = {} as any;          const message = {} as any;
35          const pagination = new Pagination().setInitialMessage(message);          const pagination = new Pagination(undefined, emojiResolver).setInitialMessage(message);
36    
37          expect(pagination["_initialMessage"]).toBe(message);          expect(pagination["_initialMessage"]).toBe(message);
38      });      });
39    
40      it("should set data correctly", () => {      it("should set data correctly", () => {
41          const data = [1, 2, 3];          const data = [1, 2, 3];
42          const pagination = new Pagination().setData(data);          const pagination = new Pagination(undefined, emojiResolver).setData(data);
43    
44          expect(pagination["_cachedData"]).toBe(data);          expect(pagination["_cachedData"]).toBe(data);
45      });      });
46    
47      it("should set limit correctly", () => {      it("should set limit correctly", () => {
48          const limit = 20;          const limit = 20;
49          const pagination = new Pagination().setLimit(limit);          const pagination = new Pagination(undefined, emojiResolver).setLimit(limit);
50    
51          expect(pagination["_limit"]).toBe(limit);          expect(pagination["_limit"]).toBe(limit);
52      });      });
53    
54      it("should set message options builder correctly", () => {      it("should set message options builder correctly", () => {
55          const builder = vi.fn();          const builder = vi.fn();
56          const pagination = new Pagination().setMessageOptionsBuilder(builder);          const pagination = new Pagination(undefined, emojiResolver).setMessageOptionsBuilder(
57                builder
58            );
59    
60          expect(pagination["_builder"]).toBe(builder);          expect(pagination["_builder"]).toBe(builder);
61      });      });
62    
63      it("should set action row builder correctly", () => {      it("should set action row builder correctly", () => {
64          const builder = vi.fn();          const builder = vi.fn();
65          const pagination = new Pagination().setActionRowBuilder(builder);          const pagination = new Pagination(undefined, emojiResolver).setActionRowBuilder(builder);
66    
67          expect(pagination["_actionRowBuilder"]).toBe(builder);          expect(pagination["_actionRowBuilder"]).toBe(builder);
68      });      });
69    
70      it("should calculate offset correctly", () => {      it("should calculate offset correctly", () => {
71          const pagination = new Pagination().setLimit(10);          const pagination = new Pagination(undefined, emojiResolver).setLimit(10);
72    
73          expect(pagination["calculateOffset"].call(pagination, 1)).toBe(0);          expect(pagination["calculateOffset"].call(pagination, 1)).toBe(0);
74          expect(pagination["calculateOffset"].call(pagination, 2)).toBe(10);          expect(pagination["calculateOffset"].call(pagination, 2)).toBe(10);
# Line 71  describe("Pagination", () => { Line 77  describe("Pagination", () => {
77    
78      it("should get slice correctly", async () => {      it("should get slice correctly", async () => {
79          const data = [1, 2, 3, 4, 5];          const data = [1, 2, 3, 4, 5];
80          const pagination = new Pagination().setData(data).setLimit(2);          const pagination = new Pagination(undefined, emojiResolver).setData(data).setLimit(2);
81    
82          expect(await pagination["getSlice"].call(pagination, 1)).toEqual([1, 2]);          expect(await pagination["getSlice"].call(pagination, 1)).toEqual([1, 2]);
83          expect(await pagination["getSlice"].call(pagination, 2)).toEqual([3, 4]);          expect(await pagination["getSlice"].call(pagination, 2)).toEqual([3, 4]);
# Line 81  describe("Pagination", () => { Line 87  describe("Pagination", () => {
87      it("should get message options correctly", async () => {      it("should get message options correctly", async () => {
88          const data = [1, 2, 3];          const data = [1, 2, 3];
89          const builder = vi.fn().mockResolvedValue({});          const builder = vi.fn().mockResolvedValue({});
90          const pagination = new Pagination().setData(data).setMessageOptionsBuilder(builder);          const pagination = new Pagination(undefined, emojiResolver)
91                .setData(data)
92                .setMessageOptionsBuilder(builder);
93    
94          await pagination["getMessageOptions"].call(pagination);          await pagination["getMessageOptions"].call(pagination);
95    
# Line 98  describe("Pagination", () => { Line 106  describe("Pagination", () => {
106          const message = {          const message = {
107              edit: vi.fn()              edit: vi.fn()
108          } as any;          } as any;
109          const pagination = new Pagination().setInitialMessage(message);          const pagination = new Pagination(undefined, emojiResolver).setInitialMessage(message);
110          pagination["getMessageOptions"] = vi.fn().mockResolvedValue({});          pagination["getMessageOptions"] = vi.fn().mockResolvedValue({});
111    
112          await pagination.destroy();          await pagination.destroy();
# Line 110  describe("Pagination", () => { Line 118  describe("Pagination", () => {
118    
119      it("should calculate max pages correctly", async () => {      it("should calculate max pages correctly", async () => {
120          const getCount = vi.fn().mockResolvedValue(15);          const getCount = vi.fn().mockResolvedValue(15);
121          const pagination = new Pagination().setCountGetter(getCount).setLimit(5);          const pagination = new Pagination(undefined, emojiResolver).setCountGetter(getCount).setLimit(5);
122    
123          expect(await pagination["calculateMaxPages"].call(pagination)).toBe(3);          expect(await pagination["calculateMaxPages"].call(pagination)).toBe(3);
124      });      });
125    
126      it("should get action row correctly", async () => {      it("should get action row correctly", async () => {
127          const pagination = new Pagination().setLimit(10);          const pagination = new Pagination(undefined, emojiResolver).setLimit(10);
128          pagination["calculateMaxPages"] = vi.fn().mockResolvedValue(3);          pagination["calculateMaxPages"] = vi.fn().mockResolvedValue(3);
129    
130          const actionRow = await pagination["getActionRow"].call(pagination);          const actionRow = await pagination["getActionRow"].call(pagination);

Legend:
Removed from v.630  
changed lines
  Added in v.631

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26