-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
19 changed files
with
157 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function countListingsToSkip(currentPage: number, countPerPage: number) { | ||
return (currentPage - 1) * countPerPage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
export interface ButtonsSegmentedProps { | ||
values: string[] | ||
/** | ||
* Valid value is between 0-`n` | ||
* Where `n` is the number of entries in `values` minus one (1). | ||
*/ | ||
activeIndex: number | ||
} | ||
|
||
// TODO: Correct hover style on currently active segment | ||
export default function ButtonsSegmented(props: ButtonsSegmentedProps) { | ||
return ( | ||
<div className="flex w-full"> | ||
{props.values.map((value, index, arrayValue) => | ||
<div key={`button-segmented-${index}`} | ||
className="w-12 cursor-pointer border-y-[1px] border-l-[1px] border-gray-400 py-2 text-center | ||
first:bg-amber-400 last:border-r-[1px] hover:bg-amber-200 | ||
first:rounded-l-md last:rounded-r-md" | ||
onClick={(e) => { }}> | ||
{value} | ||
</div>)} | ||
{props.values.map((value, index, arrayValue) => { | ||
const indexIsActive = props.activeIndex === index; | ||
return ( | ||
<div key={`button-segmented-${index}`} | ||
className={`w-12 cursor-pointer border-y-[1px] border-l-[1px] border-gray-400 py-2 text-center last:border-r-[1px] | ||
first:rounded-l-md last:rounded-r-md | ||
// Current active index should have background color amber-400 and no change in background color when hovered upon | ||
${indexIsActive && 'bg-amber-400'} | ||
// Other segments must have no background color should change its background color when hovered upon | ||
${!indexIsActive && 'hover:bg-amber-200'} `} | ||
onClick={(e) => { }}> | ||
{value} | ||
</div> | ||
) | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* | ||
* Show the previous button only if the current page is not the first page | ||
* | ||
* @param currentPage Current page | ||
* @returns `true` if the previous button should be shown, otherwise false. | ||
*/ | ||
export function checkShowPreviousButton(currentPage?: number) { | ||
return currentPage !== undefined && currentPage > 1; | ||
} | ||
|
||
/** | ||
* Show the next button only if the current page is not the last page | ||
* | ||
* @param pages Total number of pages | ||
* @param currentPage Current page | ||
* @returns `true` if the next button should be shown, otherwise false. | ||
*/ | ||
export function checkShowNextButton(pages: number, currentPage?: number) { | ||
if (currentPage === undefined) { | ||
if (pages !== 1) { | ||
return true; | ||
} | ||
} else { | ||
return currentPage < pages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ export const SinglePage: Story = { | |
export const ManyPages: Story = { | ||
args: { | ||
pages: 101, | ||
currentPage: 55, | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { countListingsToSkip } from "../../app/listings/function"; | ||
|
||
describe("Listings", () => { | ||
test.each([ | ||
{ currentPage: 1, countPerPage: 20, expected: 0 }, | ||
{ currentPage: 2, countPerPage: 30, expected: 30 }, | ||
{ currentPage: 3, countPerPage: 40, expected: 80 }, | ||
{ currentPage: 4, countPerPage: 50, expected: 150 }, | ||
{ currentPage: 5, countPerPage: 60, expected: 240 }, | ||
{ currentPage: 12, countPerPage: 55, expected: 605 }, | ||
{ currentPage: 22, countPerPage: 25, expected: 525 }, | ||
{ currentPage: 29, countPerPage: 32, expected: 896 }, | ||
{ currentPage: 99, countPerPage: 44, expected: 4312 }, | ||
])( | ||
"countListingsToSkip($currentPage, $countPerPage)", | ||
({ currentPage, countPerPage, expected }) => { | ||
const output = countListingsToSkip(currentPage, countPerPage); | ||
expect(output).toBe(expected); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
checkShowNextButton, | ||
checkShowPreviousButton, | ||
} from "../../components/pagination/function"; | ||
|
||
describe("Pagination", () => { | ||
test.each([ | ||
{ currentPage: -1, expected: false }, | ||
{ currentPage: 0, expected: false }, | ||
{ currentPage: 1, expected: false }, | ||
{ currentPage: 99, expected: true }, | ||
{ currentPage: NaN, expected: false }, | ||
{ currentPage: undefined, expected: false }, | ||
])("checkShowPreviousButton($currentPage)", ({ currentPage, expected }) => { | ||
const output = checkShowPreviousButton(currentPage); | ||
expect(output).toBe(expected); | ||
}); | ||
|
||
test.each([ | ||
{ pages: 100, currentPage: -1, expected: true }, | ||
{ pages: 100, currentPage: 0, expected: true }, | ||
{ pages: 100, currentPage: 1, expected: true }, | ||
{ pages: 100, currentPage: 99, expected: true }, | ||
{ pages: 100, currentPage: 100, expected: false }, | ||
{ pages: 100, currentPage: 101, expected: false }, | ||
{ pages: 100, currentPage: 201, expected: false }, | ||
{ pages: 100, currentPage: NaN, expected: false }, | ||
{ pages: 100, currentPage: undefined, expected: true }, | ||
])( | ||
"checkShowNextButton($pages, $currentPage)", | ||
({ pages, currentPage, expected }) => { | ||
const output = checkShowNextButton(pages, currentPage); | ||
expect(output).toBe(expected); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CURRENCY_FORMATTER } from "../../../lib/formatter/currency"; | ||
|
||
describe("Currency formatter", () => { | ||
test.each([ | ||
{ value: 12.39, expected: "₱12" }, | ||
{ value: 2_592.912, expected: "₱2,593" }, | ||
{ value: 42_622_884.2837, expected: "₱42,622,884" }, | ||
])("format($value)", ({ value, expected }) => { | ||
const output = CURRENCY_FORMATTER.format(value); | ||
expect(output).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { formatAppend } from "../../../lib/formatter/number"; | ||
|
||
describe("Number formatter", () => { | ||
test.each([ | ||
{ value: 15, append: "apples", expected: "15 apples" }, | ||
{ value: 1_302, append: "MB", expected: "1,302 MB" }, | ||
{ value: 1_250_390, append: "units", expected: "1,250,390 units" }, | ||
])("formatAppend($value, $append)", ({ value, append, expected }) => { | ||
const output = formatAppend(value, append); | ||
expect(output).toBe(expected); | ||
}); | ||
}); |