Skip to content

Commit 06ea770

Browse files
author
Chris Hasson
committed
'chore: WIP'
1 parent 1627ebf commit 06ea770

File tree

3 files changed

+10
-160
lines changed

3 files changed

+10
-160
lines changed

webview-ui/src/components/common/CostInput.tsx

Lines changed: 0 additions & 74 deletions
This file was deleted.

webview-ui/src/components/common/FormattedTextField.tsx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,6 @@ export const FormattedTextField = forwardRef(FormattedTextFieldInner as any) as
5353
) => React.ReactElement
5454

5555
// Common formatters for reuse
56-
export const integerFormatter: InputFormatter<number> = {
57-
parse: (input: string) => {
58-
const value = parseInt(input)
59-
return !isNaN(value) && value > 0 ? value : undefined
60-
},
61-
format: (value: number | undefined) => {
62-
return value?.toString() || ""
63-
},
64-
filter: (input: string) => input.replace(/[^0-9]/g, ""),
65-
}
66-
67-
export const currencyFormatter: InputFormatter<number> = {
68-
parse: (input: string) => {
69-
const cleanInput = input.replace(/[$,]/g, "")
70-
const value = parseFloat(cleanInput)
71-
return !isNaN(value) && value >= 0 ? value : undefined
72-
},
73-
format: (value: number | undefined) => {
74-
if (value === undefined) return ""
75-
return value.toFixed(2)
76-
},
77-
filter: (input: string) => {
78-
return input.replace(/[^0-9.$,]/g, "")
79-
},
80-
}
81-
8256
export const unlimitedIntegerFormatter: InputFormatter<number> = {
8357
parse: (input: string) => {
8458
if (input.trim() === "") return undefined

webview-ui/src/components/common/__tests__/FormattedTextField.spec.tsx

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
import React from "react"
33
import { describe, it, expect, vi } from "vitest"
44
import { render, screen, fireEvent } from "@testing-library/react"
5-
import {
6-
FormattedTextField,
7-
integerFormatter,
8-
currencyFormatter,
9-
unlimitedIntegerFormatter,
10-
} from "../FormattedTextField"
5+
import { FormattedTextField, unlimitedIntegerFormatter } from "../FormattedTextField"
116

127
// Mock VSCodeTextField to render as regular HTML input for testing
138
vi.mock("@vscode/webview-ui-toolkit/react", () => ({
@@ -23,56 +18,6 @@ vi.mock("@vscode/webview-ui-toolkit/react", () => ({
2318
}))
2419

2520
describe("FormattedTextField", () => {
26-
describe("integerFormatter", () => {
27-
it("should parse valid integers", () => {
28-
expect(integerFormatter.parse("123")).toBe(123)
29-
expect(integerFormatter.parse("1")).toBe(1)
30-
})
31-
32-
it("should return undefined for invalid inputs", () => {
33-
expect(integerFormatter.parse("")).toBeUndefined()
34-
expect(integerFormatter.parse("0")).toBeUndefined()
35-
expect(integerFormatter.parse("-5")).toBeUndefined()
36-
expect(integerFormatter.parse("abc")).toBeUndefined()
37-
})
38-
39-
it("should format numbers correctly", () => {
40-
expect(integerFormatter.format(123)).toBe("123")
41-
expect(integerFormatter.format(undefined)).toBe("")
42-
})
43-
44-
it("should filter non-numeric characters", () => {
45-
expect(integerFormatter.filter?.("123abc")).toBe("123")
46-
expect(integerFormatter.filter?.("a1b2c3")).toBe("123")
47-
})
48-
})
49-
50-
describe("currencyFormatter", () => {
51-
it("should parse valid currency values", () => {
52-
expect(currencyFormatter.parse("123.45")).toBe(123.45)
53-
expect(currencyFormatter.parse("$123.45")).toBe(123.45)
54-
expect(currencyFormatter.parse("1,234.56")).toBe(1234.56)
55-
expect(currencyFormatter.parse("0")).toBe(0)
56-
})
57-
58-
it("should return undefined for invalid inputs", () => {
59-
expect(currencyFormatter.parse("")).toBeUndefined()
60-
expect(currencyFormatter.parse("abc")).toBeUndefined()
61-
expect(currencyFormatter.parse("-5")).toBeUndefined()
62-
})
63-
64-
it("should format currency correctly", () => {
65-
expect(currencyFormatter.format(123.45)).toBe("123.45")
66-
expect(currencyFormatter.format(123)).toBe("123.00")
67-
expect(currencyFormatter.format(undefined)).toBe("")
68-
})
69-
70-
it("should filter invalid currency characters", () => {
71-
expect(currencyFormatter.filter?.("$123.45abc")).toBe("$123.45")
72-
expect(currencyFormatter.filter?.("1,234.56xyz")).toBe("1,234.56")
73-
})
74-
})
75-
7621
describe("unlimitedIntegerFormatter", () => {
7722
it("should parse valid integers", () => {
7823
expect(unlimitedIntegerFormatter.parse("123")).toBe(123)
@@ -95,6 +40,11 @@ describe("FormattedTextField", () => {
9540
expect(unlimitedIntegerFormatter.format(undefined)).toBe("")
9641
expect(unlimitedIntegerFormatter.format(Infinity)).toBe("")
9742
})
43+
44+
it("should filter non-numeric characters", () => {
45+
expect(unlimitedIntegerFormatter.filter?.("123abc")).toBe("123")
46+
expect(unlimitedIntegerFormatter.filter?.("a1b2c3")).toBe("123")
47+
})
9848
})
9949

10050
describe("FormattedTextField component", () => {
@@ -104,7 +54,7 @@ describe("FormattedTextField", () => {
10454
<FormattedTextField
10555
value={123}
10656
onValueChange={mockOnChange}
107-
formatter={integerFormatter}
57+
formatter={unlimitedIntegerFormatter}
10858
data-testid="test-input"
10959
/>,
11060
)
@@ -119,7 +69,7 @@ describe("FormattedTextField", () => {
11969
<FormattedTextField
12070
value={123}
12171
onValueChange={mockOnChange}
122-
formatter={integerFormatter}
72+
formatter={unlimitedIntegerFormatter}
12373
data-testid="test-input"
12474
/>,
12575
)
@@ -136,7 +86,7 @@ describe("FormattedTextField", () => {
13686
<FormattedTextField
13787
value={undefined}
13888
onValueChange={mockOnChange}
139-
formatter={integerFormatter}
89+
formatter={unlimitedIntegerFormatter}
14090
data-testid="test-input"
14191
/>,
14292
)
@@ -155,7 +105,7 @@ describe("FormattedTextField", () => {
155105
<FormattedTextField
156106
value={undefined}
157107
onValueChange={mockOnChange}
158-
formatter={integerFormatter}
108+
formatter={unlimitedIntegerFormatter}
159109
data-testid="test-input"
160110
/>,
161111
)

0 commit comments

Comments
 (0)