Skip to content

Commit bd7b14f

Browse files
fix schema
1 parent 6884f9c commit bd7b14f

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/codegen/browser/convertEventsToActions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ActionLocator } from '@/main/runner/schema'
21
import { BrowserTestAction, LocatorOptions } from '@/schemas/browserTest/v1'
32
import {
43
BrowserEvent,
@@ -8,7 +7,7 @@ import {
87
import { exhaustive } from '@/utils/typescript'
98

109
function toLocatorOptions(selector: ElementSelector): LocatorOptions {
11-
const values: Partial<Record<ActionLocator['type'], ActionLocator>> = {}
10+
const values: LocatorOptions['values'] = {}
1211

1312
values.css = { type: 'css', selector: selector.css }
1413

@@ -50,7 +49,9 @@ function toLocatorOptions(selector: ElementSelector): LocatorOptions {
5049
return { current, values }
5150
}
5251

53-
function pickBestLocatorType(selector: ElementSelector): ActionLocator['type'] {
52+
function pickBestLocatorType(
53+
selector: ElementSelector
54+
): LocatorOptions['current'] {
5455
if (selector.role !== undefined) return 'role'
5556
if (selector.label !== undefined) return 'label'
5657
if (selector.alt !== undefined) return 'alt'

src/main/runner/schema.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ function safe<T>(schema: z.ZodType<T>) {
1313
// Generic options schema to allow any options object. Should be refined later.
1414
const GenericOptions = z.unknown()
1515

16-
const CssLocatorSchema = z.object({
16+
export const CssLocatorSchema = z.object({
1717
type: z.literal('css'),
1818
selector: z.string(),
1919
})
2020

21-
const GetByRoleLocatorSchema = z.object({
21+
export const GetByRoleLocatorSchema = z.object({
2222
type: z.literal('role'),
2323
role: z.string(),
2424
options: z
@@ -29,7 +29,7 @@ const GetByRoleLocatorSchema = z.object({
2929
.optional(),
3030
})
3131

32-
const GetByTestIdLocatorSchema = z.object({
32+
export const GetByTestIdLocatorSchema = z.object({
3333
type: z.literal('testid'),
3434
testId: z.string(),
3535
})
@@ -40,31 +40,31 @@ const TextLocatorOptions = z
4040
})
4141
.optional()
4242

43-
const GetByAltTextLocatorSchema = z.object({
43+
export const GetByAltTextLocatorSchema = z.object({
4444
type: z.literal('alt'),
4545
text: z.string(),
4646
options: TextLocatorOptions,
4747
})
4848

49-
const GetByLabelLocatorSchema = z.object({
49+
export const GetByLabelLocatorSchema = z.object({
5050
type: z.literal('label'),
5151
label: z.string(),
5252
options: TextLocatorOptions,
5353
})
5454

55-
const GetByPlaceholderLocatorSchema = z.object({
55+
export const GetByPlaceholderLocatorSchema = z.object({
5656
type: z.literal('placeholder'),
5757
placeholder: z.string(),
5858
options: TextLocatorOptions,
5959
})
6060

61-
const GetByTitleLocatorSchema = z.object({
61+
export const GetByTitleLocatorSchema = z.object({
6262
type: z.literal('title'),
6363
title: z.string(),
6464
options: TextLocatorOptions,
6565
})
6666

67-
const GetByTextLocatorSchema = z.object({
67+
export const GetByTextLocatorSchema = z.object({
6868
type: z.literal('text'),
6969
text: z.string(),
7070
options: TextLocatorOptions,

src/schemas/browserTest/v1/index.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { z } from 'zod'
22

33
import {
4-
ActionLocatorSchema,
4+
CssLocatorSchema,
55
GenericBrowserContextActionSchema,
66
GenericLocatorActionSchema,
77
GenericPageActionSchema,
8+
GetByAltTextLocatorSchema,
9+
GetByLabelLocatorSchema,
10+
GetByPlaceholderLocatorSchema,
11+
GetByRoleLocatorSchema,
12+
GetByTestIdLocatorSchema,
13+
GetByTextLocatorSchema,
14+
GetByTitleLocatorSchema,
815
LocatorCheckActionSchema,
916
LocatorClearActionSchema,
1017
LocatorClickActionSchema,
@@ -42,9 +49,20 @@ const ActionLocatorTypeSchema = z.enum([
4249
'text',
4350
])
4451

52+
const LocatorValuesSchema = z.object({
53+
css: CssLocatorSchema.optional(),
54+
role: GetByRoleLocatorSchema.optional(),
55+
testid: GetByTestIdLocatorSchema.optional(),
56+
alt: GetByAltTextLocatorSchema.optional(),
57+
label: GetByLabelLocatorSchema.optional(),
58+
placeholder: GetByPlaceholderLocatorSchema.optional(),
59+
title: GetByTitleLocatorSchema.optional(),
60+
text: GetByTextLocatorSchema.optional(),
61+
})
62+
4563
export const LocatorOptionsSchema = z.object({
4664
current: ActionLocatorTypeSchema,
47-
values: z.record(ActionLocatorTypeSchema, ActionLocatorSchema),
65+
values: LocatorValuesSchema,
4866
})
4967

5068
export type LocatorOptions = z.infer<typeof LocatorOptionsSchema>

0 commit comments

Comments
 (0)