Skip to content

Commit 89cbbf6

Browse files
committed
test(web): verify comma decimal price entry
1 parent 8378e06 commit 89cbbf6

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎apps/web/src/components/usage/usagePriceForm.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("model price entry", () => {
3232
});
3333
});
3434

35-
it.each(["", " ", "-1", "Infinity", "NaN", "1e999", "$2", "0x10"])(
35+
it.each(["", " ", "-1", "Infinity", "NaN", "1e999", "$2", "0x10", "1,2,3", "1.2,3", "1,2.3"])(
3636
"rejects invalid required prices: %j",
3737
(inputCostPerMillionTokens) => {
3838
expect(
@@ -66,6 +66,12 @@ describe("model price entry", () => {
6666
expect(isUsagePriceEdit("", "2,5")).toBe(true);
6767
expect(isUsagePriceEdit("", ",5")).toBe(true);
6868
expect(isUsagePriceEdit("", "1,2,3")).toBe(false);
69+
expect(isUsagePriceEdit("1,2", "1,2.3")).toBe(false);
70+
for (const value of ["2,5", ",5", "0,075", "1,5e-7"]) {
71+
for (let end = 1; end <= value.length; end++) {
72+
expect(isUsagePriceEdit(value.slice(0, end - 1), value.slice(0, end))).toBe(true);
73+
}
74+
}
6975
});
7076

7177
it("never blocks deleting part of a price, but blocks replacing it with a non-number", () => {

‎apps/web/src/components/usage/usagePriceForm.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ export function isUsagePriceEdit(previous: string, next: string): boolean {
3232
return next.slice(start) === previous.slice(previous.length - (next.length - start));
3333
}
3434

35-
/** Blank cache prices use the input rate; explicit zero means free.
36-
* A comma is accepted as the decimal point. */
35+
/** Blank cache prices use the input rate; explicit zero means free. */
3736
export function parseUsagePriceForm(
3837
form: UsagePriceForm,
3938
): { model: string; price: UsageModelPriceOverride } | null {

0 commit comments

Comments
 (0)