Skip to content

Commit

Permalink
test(core): tree editing with fieldset array
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanwikner committed Jul 1, 2024
1 parent 8714221 commit 68d4fe2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ const DOCUMENT_VALUE: SanityDocument = {
title: 'My object 3',
},
],

myFieldsetArray: [
{
_type: 'myObject',
_key: 'key-1',
title: 'My object 1',
},
{
_type: 'myObject',
_key: 'key-2',
title: 'My object 2',
},
],
}

test.describe('Tree editing', () => {
Expand Down Expand Up @@ -169,6 +182,21 @@ test.describe('Tree editing', () => {
await expect(stringInput).toHaveValue('My object 2')
})

test('should open dialog with correct form view based on the openPath when the array is in a fieldset', async ({
mount,
page,
}) => {
await mount(
<TreeEditingStory value={DOCUMENT_VALUE} openPath={['myFieldsetArray', {_key: 'key-2'}]} />,
)

const dialog = page.getByTestId('tree-editing-dialog')
await expect(dialog).toBeVisible()

const stringInput = dialog.getByTestId('string-input')
await expect(stringInput).toHaveValue('My object 2')
})

test('should not open dialog when the openPath does not match any item', async ({
mount,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,44 @@ function getSchemaTypes(opts: GetSchemaTypesOpts) {
type: 'document',
name: 'test',
title: 'Test',

fieldsets: [
{
name: 'fieldset',
},
],

fields: [
defineField({
type: 'array',
name: 'myArrayOfObjects',
title: 'My array of objects',

options: {
treeEditing: treeEditingEnabled,
},

of: [
{
type: 'object',
name: 'myObject',
fields: [
{
type: 'string',
name: 'title',
title: 'Title',
},
],
},
],
}),

defineField({
type: 'array',
name: 'myFieldsetArray',
title: 'My fieldset array',
fieldset: 'fieldset',

of: [
{
type: 'object',
Expand Down

0 comments on commit 68d4fe2

Please sign in to comment.