|
1 | 1 | import React from 'react'
|
2 | 2 | import { render, waitFor } from '@testing-library/react'
|
3 | 3 | import { createForm } from '@formily/core'
|
4 |
| -import { FormProvider, ExpressionScope, createSchemaField, useField } from '..' |
| 4 | +import { |
| 5 | + FormProvider, |
| 6 | + ExpressionScope, |
| 7 | + createSchemaField, |
| 8 | + useField, |
| 9 | + Field, |
| 10 | +} from '..' |
5 | 11 |
|
6 | 12 | test('expression scope', async () => {
|
7 | 13 | const Container = (props) => {
|
@@ -73,3 +79,33 @@ test('x-compile-omitted', async () => {
|
73 | 79 | expect(queryByTestId('input')?.textContent).toBe('{{fake}}123321extra')
|
74 | 80 | })
|
75 | 81 | })
|
| 82 | + |
| 83 | +test('field hidden & visible', async () => { |
| 84 | + const form = createForm({ initialValues: { empty: null } }) |
| 85 | + const { findByTestId } = render( |
| 86 | + <FormProvider form={form}> |
| 87 | + <div data-testid="testid"> |
| 88 | + <Field name="empty" component={['input']} /> |
| 89 | + </div> |
| 90 | + </FormProvider> |
| 91 | + ) |
| 92 | + await findByTestId('testid') |
| 93 | + // |
| 94 | + expect(form.fields.empty.hidden).toBe(false) |
| 95 | + expect(form.fields.empty.value).toBe(null) |
| 96 | + form.fields.empty.hidden = true |
| 97 | + expect(form.fields.empty.hidden).toBe(true) |
| 98 | + expect(form.fields.empty.value).toBe(null) |
| 99 | + form.fields.empty.hidden = false |
| 100 | + expect(form.fields.empty.hidden).toBe(false) |
| 101 | + expect(form.fields.empty.value).toBe(null) |
| 102 | + // |
| 103 | + expect(form.fields.empty.visible).toBe(true) |
| 104 | + expect(form.fields.empty.value).toBe(null) |
| 105 | + form.fields.empty.visible = false |
| 106 | + expect(form.fields.empty.visible).toBe(false) |
| 107 | + expect(form.fields.empty.value).toBe(undefined) |
| 108 | + form.fields.empty.visible = true |
| 109 | + expect(form.fields.empty.visible).toBe(true) |
| 110 | + expect(form.fields.empty.value).toBe(null) |
| 111 | +}) |
0 commit comments