Skip to content

Commit

Permalink
ref: add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fricoben committed Nov 11, 2024
1 parent d004160 commit b7f9491
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
5 changes: 1 addition & 4 deletions components/dashboard/PortfolioSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import cursorPointer from '../../public/icons/pointer-cursor.png';
import ClaimModal from "../discover/claimModal";
import SuccessModal from "../discover/successModal";
import { useHidePortfolio } from "@hooks/useHidePortfolio";
import { formatNumberWithCommas } from "@utils/numberService";

// Format the numbers with commas
const formatNumberWithCommas = (number: number): string => {
return number.toLocaleString(); // Default locale formatting
};

Chart.register(ArcElement, DoughnutController, Tooltip);

Expand Down
24 changes: 24 additions & 0 deletions tests/utils/numberService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
calculatePercentile,
numberWithCommas,
formatNumberThousandEqualsK,
formatNumberWithCommas,
} from "@utils/numberService";

describe("calculatePercentile function", () => {
Expand Down Expand Up @@ -64,3 +65,26 @@ describe("formatNumberThousandEqualsK function", () => {
expect(formatNumberThousandEqualsK(500)).toBe("500");
});
});

describe("formatNumberWithCommas function", () => {
it("should return a string representation of the number with commas", () => {
expect(formatNumberWithCommas(1000)).toBe("1,000");
expect(formatNumberWithCommas(1000000)).toBe("1,000,000");
expect(formatNumberWithCommas(123456789)).toBe("123,456,789");
});

it("should handle negative numbers", () => {
expect(formatNumberWithCommas(-1000)).toBe("-1,000");
expect(formatNumberWithCommas(-1000000)).toBe("-1,000,000");
expect(formatNumberWithCommas(-123456789)).toBe("-123,456,789");
});

it("should handle floating point numbers", () => {
expect(formatNumberWithCommas(1234.56)).toBe("1,234.56");
expect(formatNumberWithCommas(-1234.56)).toBe("-1,234.56");
});

it("should return '0' for input 0", () => {
expect(formatNumberWithCommas(0)).toBe("0");
});
});
6 changes: 5 additions & 1 deletion utils/numberService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export const formatNumberThousandEqualsK = (num: number) => {
} else {
return num.toString();
}
};
};

export const formatNumberWithCommas = (number: number): string => {
return number.toLocaleString();
};

0 comments on commit b7f9491

Please sign in to comment.