Skip to content

Commit 1c872a2

Browse files
committed
Use it.each
1 parent c0e1fb6 commit 1c872a2

1 file changed

Lines changed: 47 additions & 107 deletions

File tree

plugins/airtable/src/data.test.ts

Lines changed: 47 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -7,129 +7,69 @@ describe("getFieldDataEntryForFieldSchema", () => {
77
vi.clearAllMocks()
88
})
99

10-
const createEmailField = (): PossibleField => ({
11-
id: "email_field",
12-
name: "Email",
13-
type: "link",
14-
userEditable: true,
15-
airtableType: "email",
16-
})
17-
18-
const createPhoneField = (): PossibleField => ({
19-
id: "phone_field",
20-
name: "Phone",
21-
type: "link",
22-
userEditable: true,
23-
airtableType: "phoneNumber",
24-
})
10+
const createEmailField = () =>
11+
({
12+
id: "email_field",
13+
name: "Email",
14+
type: "link",
15+
airtableType: "email",
16+
}) as const satisfies PossibleField
17+
18+
const createPhoneField = () =>
19+
({
20+
id: "phone_field",
21+
name: "Phone",
22+
type: "link",
23+
airtableType: "phoneNumber",
24+
}) as const satisfies PossibleField
2525

2626
describe("Email field processing", () => {
27-
it("should add mailto: prefix to email without prefix", () => {
28-
const result = getFieldDataEntryForFieldSchema(createEmailField(), "user@example.com")
29-
30-
expect(result).toEqual({
31-
value: "mailto:user@example.com",
32-
type: "link",
33-
})
34-
})
35-
36-
it("should preserve single mailto: prefix", () => {
37-
const result = getFieldDataEntryForFieldSchema(createEmailField(), "mailto:user@example.com")
27+
it.each<[PossibleField, string]>([
28+
[createEmailField(), "user@example.com"],
29+
[createEmailField(), "mailto:user@example.com"],
30+
[createEmailField(), "mailto:mailto:user@example.com"],
31+
[createEmailField(), "MAILTO:user@example.com"],
32+
[
33+
{
34+
id: "link_field",
35+
name: "Link",
36+
type: "link",
37+
airtableType: "url", // Not an email field type
38+
},
39+
"user@example.com",
40+
],
41+
])("%s -> %s", (field, input) => {
42+
const result = getFieldDataEntryForFieldSchema(field, input)
3843

3944
expect(result).toEqual({
4045
value: "mailto:user@example.com",
4146
type: "link",
4247
})
4348
})
44-
45-
it("should normalize multiple mailto: prefixes to one", () => {
46-
const result = getFieldDataEntryForFieldSchema(createEmailField(), "mailto:mailto:user@example.com")
47-
48-
expect(result).toEqual({
49-
value: "mailto:user@example.com",
50-
type: "link",
51-
})
52-
})
53-
54-
it("should handle case insensitive mailto: prefix", () => {
55-
const result = getFieldDataEntryForFieldSchema(createEmailField(), "MAILTO:user@example.com")
56-
57-
expect(result).toEqual({
58-
value: "mailto:user@example.com",
59-
type: "link",
60-
})
61-
})
62-
63-
it("should detect email by regex when field type is not email", () => {
64-
const linkField: PossibleField = {
65-
id: "link_field",
66-
name: "Link",
67-
type: "link",
68-
userEditable: true,
69-
airtableType: "url", // Not an email field type
70-
}
71-
72-
const result = getFieldDataEntryForFieldSchema(linkField, "test@domain.co.uk")
73-
74-
expect(result).toEqual({
75-
value: "mailto:test@domain.co.uk",
76-
type: "link",
77-
})
78-
})
7949
})
8050

8151
describe("Phone field processing", () => {
82-
it("should add tel: prefix to phone without prefix", () => {
83-
const result = getFieldDataEntryForFieldSchema(createPhoneField(), "+1234567890")
84-
85-
expect(result).toEqual({
86-
value: "tel:+1234567890",
87-
type: "link",
88-
})
89-
})
90-
91-
it("should preserve single tel: prefix", () => {
92-
const result = getFieldDataEntryForFieldSchema(createPhoneField(), "tel:+1234567890")
93-
94-
expect(result).toEqual({
95-
value: "tel:+1234567890",
96-
type: "link",
97-
})
98-
})
99-
100-
it("should normalize multiple tel: prefixes to one", () => {
101-
const result = getFieldDataEntryForFieldSchema(createPhoneField(), "tel:tel:+1234567890")
52+
it.each<[PossibleField, string]>([
53+
[createPhoneField(), "+1234567890"],
54+
[createPhoneField(), "tel:+1234567890"],
55+
[createPhoneField(), "tel:tel:+1234567890"],
56+
[createPhoneField(), "TEL:+1234567890"],
57+
[
58+
{
59+
id: "link_field",
60+
name: "Link",
61+
type: "link",
62+
airtableType: "url", // Not a phone field type
63+
},
64+
"+1234567890",
65+
],
66+
])("%s -> %s", (field, input) => {
67+
const result = getFieldDataEntryForFieldSchema(field, input)
10268

10369
expect(result).toEqual({
10470
value: "tel:+1234567890",
10571
type: "link",
10672
})
10773
})
108-
109-
it("should handle case insensitive tel: prefix", () => {
110-
const result = getFieldDataEntryForFieldSchema(createPhoneField(), "TEL:+1234567890")
111-
112-
expect(result).toEqual({
113-
value: "tel:+1234567890",
114-
type: "link",
115-
})
116-
})
117-
118-
it("should detect phone by regex when field type is not phoneNumber", () => {
119-
const linkField: PossibleField = {
120-
id: "link_field",
121-
name: "Link",
122-
type: "link",
123-
userEditable: true,
124-
airtableType: "url", // Not a phone field type
125-
}
126-
127-
const result = getFieldDataEntryForFieldSchema(linkField, "1234567890")
128-
129-
expect(result).toEqual({
130-
value: "tel:1234567890",
131-
type: "link",
132-
})
133-
})
13474
})
13575
})

0 commit comments

Comments
 (0)