|
| 1 | +import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; |
| 2 | +import pagesBadges from "../index.js"; |
| 3 | + |
| 4 | +Deno.test("Should work with just 1 page", async () => { |
| 5 | + const input = { currentPage: 1, pages: 1 }; |
| 6 | + const output = pagesBadges(input); |
| 7 | + const expected = [1]; |
| 8 | + assertEquals(output, expected); |
| 9 | +}); |
| 10 | + |
| 11 | +Deno.test("Should work with just 5 pages", async () => { |
| 12 | + const input = { currentPage: 2, pages: 5 }; |
| 13 | + const output = pagesBadges(input); |
| 14 | + const expected = [1, 2, 3, 4, 5]; |
| 15 | + assertEquals(output, expected); |
| 16 | +}); |
| 17 | + |
| 18 | +Deno.test("Should work with pages bigger than 5", async () => { |
| 19 | + const input = { currentPage: 14, pages: 20 }; |
| 20 | + const output = pagesBadges(input); |
| 21 | + const expected = [1, null, 13, 14, 15, null, 20]; |
| 22 | + assertEquals(output, expected); |
| 23 | +}); |
| 24 | + |
| 25 | +Deno.test("Should work with pages bigger than 5 and current page as first | second | third", async () => { |
| 26 | + const input = { currentPage: 1, pages: 20 }; |
| 27 | + const input2 = { currentPage: 2, pages: 20 }; |
| 28 | + const input3 = { currentPage: 3, pages: 20 }; |
| 29 | + |
| 30 | + const output = pagesBadges(input); |
| 31 | + const output2 = pagesBadges(input2); |
| 32 | + const output3 = pagesBadges(input3); |
| 33 | + |
| 34 | + const expected = [1, 2, 3, 4, null, 20]; |
| 35 | + assertEquals(output, expected); |
| 36 | + assertEquals(output2, expected); |
| 37 | + assertEquals(output3, expected); |
| 38 | +}); |
| 39 | + |
| 40 | +Deno.test("Should work with pages bigger than 5 and current page as 4", async () => { |
| 41 | + const input = { currentPage: 4, pages: 7 }; |
| 42 | + const input2 = { currentPage: 4, pages: 6 }; |
| 43 | + |
| 44 | + const output = pagesBadges(input); |
| 45 | + const output2 = pagesBadges(input2); |
| 46 | + |
| 47 | + const expected = [1, null, 3, 4, 5, null, 7]; |
| 48 | + const expected2 = [1, null, 3, 4, 5, 6]; |
| 49 | + |
| 50 | + assertEquals(output, expected); |
| 51 | + assertEquals(output2, expected2); |
| 52 | +}); |
| 53 | + |
| 54 | +Deno.test("Should work with pages bigger than 5 and current page as one of the 3 last ones", async () => { |
| 55 | + const input = { currentPage: 20, pages: 20 }; |
| 56 | + const input2 = { currentPage: 19, pages: 20 }; |
| 57 | + const input3 = { currentPage: 18, pages: 20 }; |
| 58 | + |
| 59 | + const output = pagesBadges(input); |
| 60 | + const output2 = pagesBadges(input2); |
| 61 | + const output3 = pagesBadges(input3); |
| 62 | + |
| 63 | + const expected = [1, null, 17, 18, 19, 20]; |
| 64 | + |
| 65 | + assertEquals(output, expected); |
| 66 | + assertEquals(output2, expected); |
| 67 | + assertEquals(output3, expected); |
| 68 | +}); |
| 69 | + |
| 70 | +Deno.test("Should work with page 17/20", async () => { |
| 71 | + const input = { currentPage: 17, pages: 20 }; |
| 72 | + const output = pagesBadges(input); |
| 73 | + const expected = [1, null, 16, 17, 18, null, 20]; |
| 74 | + |
| 75 | + assertEquals(output, expected); |
| 76 | +}); |
| 77 | + |
| 78 | +Deno.test("Should work with page 3/6", async () => { |
| 79 | + const input = { currentPage: 3, pages: 6 }; |
| 80 | + const output = pagesBadges(input); |
| 81 | + const expected = [1, 2, 3, 4, null, 6]; |
| 82 | + |
| 83 | + assertEquals(output, expected); |
| 84 | +}); |
0 commit comments