-
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.
- Loading branch information
1 parent
d4b9208
commit 9ff2169
Showing
13 changed files
with
2,213 additions
and
152 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
"extends": "next/core-web-vitals", | ||
"plugins": ["testing-library"], | ||
"overrides": [ | ||
// Only uses Testing Library lint rules in test files | ||
{ | ||
"files": [ | ||
"**/__tests__/**/*.[jt]s?(x)", | ||
"**/?(*.)+(spec|test).[jt]s?(x)" | ||
], | ||
"extends": ["plugin:testing-library/react"] | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// TODO: Setup integration with next so we can do snapshot testing | ||
|
||
/* | ||
const nextJest = require("next/jest"); | ||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: "./", | ||
}); | ||
// Add any custom config to be passed to Jest | ||
const customJestConfig = { | ||
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], | ||
moduleNameMapper: { | ||
// Handle module aliases (this will be automatically configured for you soon) | ||
"^@/components/(.*)$": "<rootDir>/components/$1", | ||
"^@/pages/(.*)$": "<rootDir>/pages/$1", | ||
}, | ||
testEnvironment: "jest-environment-jsdom", | ||
}; | ||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
module.exports = createJestConfig(customJestConfig); | ||
*/ |
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,6 @@ | ||
// Optional: configure or set up a testing framework before each test. | ||
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` | ||
|
||
// Used for __tests__/testing-library.js | ||
// Learn more: https://github.com/testing-library/jest-dom | ||
import "@testing-library/jest-dom/extend-expect"; |
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
File renamed without changes.
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,18 @@ | ||
import { parseCurrency } from "./currency"; | ||
|
||
test("parseCurrency", () => { | ||
expect(parseCurrency(0)).toBe(0); | ||
expect(parseCurrency(1)).toBe(100); | ||
expect(parseCurrency(1.25)).toBe(125); | ||
expect(parseCurrency(1.5)).toBe(150); | ||
expect(parseCurrency(1.75)).toBe(175); | ||
expect(parseCurrency(1.12345)).toBe(112); | ||
expect(parseCurrency(10000)).toBe(1000000); | ||
|
||
expect(parseCurrency(-1)).toBe(-100); | ||
expect(parseCurrency(-1.25)).toBe(-125); | ||
expect(parseCurrency(-1.5)).toBe(-150); | ||
expect(parseCurrency(-1.75)).toBe(-175); | ||
expect(parseCurrency(-1.12345)).toBe(-112); | ||
expect(parseCurrency(-10000)).toBe(-1000000); | ||
}); |
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,13 @@ | ||
export const parseCurrency = (value: number): number => { | ||
if (isNaN(value)) { | ||
return 0; | ||
} | ||
|
||
// Check if the value is a int | ||
if (Number.isInteger(value)) { | ||
return value * 100; | ||
} | ||
|
||
const fixed = parseFloat(value.toFixed(2)); | ||
return Math.round(fixed * 100); | ||
}; |
Oops, something went wrong.