Skip to content

Commit

Permalink
test(sanity): pass noop renderDefault to form input tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Oct 6, 2022
1 parent 60aa893 commit 279ce8d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/sanity/test/form/renderArrayOfObjectsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'

const noopRenderDefault = () => <></>

export type TestRenderArrayOfObjectInputCallback = (
inputProps: ArrayOfObjectsInputProps
) => React.ReactElement
Expand Down Expand Up @@ -76,6 +78,7 @@ export async function renderArrayOfObjectsInput(options: {
resolveInitialValue,
schemaType: schemaType as ArraySchemaType,
value: value as any[],
renderDefault: noopRenderDefault,
}
}

Expand Down
10 changes: 7 additions & 3 deletions packages/sanity/test/form/renderBooleanInput.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react'
import {BooleanSchemaType, FieldDefinition} from '@sanity/types'
import {BooleanInputProps, PrimitiveInputElementProps} from '../../src/core'
import {renderInput, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'

const noopRenderDefault = () => <></>

export type TestRenderBooleanInputCallback = (inputProps: BooleanInputProps) => React.ReactElement

export async function renderBooleanInput(options: {
Expand All @@ -12,7 +15,7 @@ export async function renderBooleanInput(options: {
}) {
const {fieldDefinition, props, render: initialRender} = options

function tranformProps(
function transformProps(
inputProps: TestRenderInputProps<PrimitiveInputElementProps>
): BooleanInputProps {
const {schemaType, value, ...restProps} = inputProps
Expand All @@ -22,17 +25,18 @@ export async function renderBooleanInput(options: {
changed: false,
schemaType: schemaType as BooleanSchemaType,
value: value as boolean,
renderDefault: noopRenderDefault,
}
}

const result = await renderInput({
fieldDefinition,
props,
render: (inputProps) => initialRender(tranformProps(inputProps)),
render: (inputProps) => initialRender(transformProps(inputProps)),
})

function rerender(subsequentRender: TestRenderBooleanInputCallback) {
return result.rerender((inputProps) => subsequentRender(tranformProps(inputProps)))
return result.rerender((inputProps) => subsequentRender(transformProps(inputProps)))
}

return {...result, rerender}
Expand Down
7 changes: 5 additions & 2 deletions packages/sanity/test/form/renderNumberInput.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {FieldDefinition, NumberSchemaType} from '@sanity/types'
import {ReactElement} from 'react'
import React, {ReactElement} from 'react'
import {NumberSchemaType, FieldDefinition} from '@sanity/types'
import {NumberInputProps, PrimitiveInputElementProps} from '../../src/core'
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'

const noopRenderDefault = () => <></>

export type TestRenderNumberInputCallback = (
inputProps: NumberInputProps,
context: TestRenderInputContext
Expand All @@ -26,6 +28,7 @@ export async function renderNumberInput(options: {
changed: false,
schemaType: schemaType as NumberSchemaType,
value: value as number,
renderDefault: noopRenderDefault,
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/sanity/test/form/renderObjectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'

const noopRenderDefault = () => <></>

export type TestRenderObjectInputCallback = (
inputProps: ObjectInputProps,
context: TestRenderInputContext
Expand Down Expand Up @@ -64,6 +66,7 @@ export async function renderObjectInput(options: {
renderPreview: defaultRenderPreview,
schemaType: schemaType as ObjectSchemaType,
value: value as Record<string, any>,
renderDefault: noopRenderDefault,
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/sanity/test/form/renderStringInput.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React from 'react'
import {FieldDefinition, StringSchemaType} from '@sanity/types'
import {PrimitiveInputElementProps, StringInputProps} from '../../src/core'
import {renderInput, TestRenderInputContext, TestRenderInputProps} from './renderInput'
import {TestRenderProps} from './types'

const noopRenderDefault = () => <></>

export type TestRenderStringInputCallback = (
inputProps: StringInputProps,
context: TestRenderInputContext
Expand All @@ -29,6 +32,7 @@ export async function renderStringInput(options: {
changed: false,
schemaType: schemaType as StringSchemaType,
value: value as string,
renderDefault: noopRenderDefault,
}
}

Expand Down

0 comments on commit 279ce8d

Please sign in to comment.