-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use default values for componentValue properties
- Loading branch information
1 parent
c1e88fc
commit 53d9f79
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/visual-editor/src/components/Dropzone/useComponentProps.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { ASSEMBLY_NODE_TYPE } from '@contentful/experiences-core/constants'; | ||
import { useComponentProps } from './useComponentProps'; | ||
import { ComponentDefinition, ExperienceTreeNode } from '@contentful/experiences-core/types'; | ||
import { vi } from 'vitest'; | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
const definition: ComponentDefinition = { | ||
id: 'button', | ||
name: 'Button', | ||
variables: { | ||
label: { | ||
type: 'Text', | ||
defaultValue: 'Click here', | ||
}, | ||
}, | ||
}; | ||
const node: ExperienceTreeNode = { | ||
data: { | ||
id: 'id', | ||
props: {}, | ||
unboundValues: {}, | ||
dataSource: {}, | ||
breakpoints: [], | ||
}, | ||
children: [], | ||
type: 'block', | ||
}; | ||
const resolveDesignValue = vi.fn(); | ||
const renderDropzone = vi.fn(); | ||
const areEntitiesFetched = true; | ||
const userIsDragging = false; | ||
|
||
describe('useComponentProps', () => { | ||
it('should return empty object when node type is ASSEMBLY_NODE_TYPE', () => { | ||
const areEntitiesFetched = true; | ||
const userIsDragging = false; | ||
|
||
const { result } = renderHook(() => | ||
useComponentProps({ | ||
node: { ...node, type: ASSEMBLY_NODE_TYPE }, | ||
areEntitiesFetched, | ||
resolveDesignValue, | ||
renderDropzone, | ||
definition, | ||
userIsDragging, | ||
}), | ||
); | ||
|
||
expect(Object.keys(result.current.componentProps)).not.toContain('label'); | ||
}); | ||
|
||
it('should return props with default values when variableMapping is falsy', () => { | ||
const { result } = renderHook(() => | ||
useComponentProps({ | ||
node, | ||
areEntitiesFetched, | ||
resolveDesignValue, | ||
renderDropzone, | ||
definition, | ||
userIsDragging, | ||
}), | ||
); | ||
|
||
expect(result.current.componentProps.label).toEqual('Click here'); | ||
}); | ||
|
||
it('should return definition default value when type is ComponentValue', () => { | ||
const areEntitiesFetched = true; | ||
const userIsDragging = false; | ||
|
||
const { result } = renderHook(() => | ||
useComponentProps({ | ||
node: { | ||
...node, | ||
data: { | ||
...node.data, | ||
props: { | ||
label: { | ||
key: 'random-uuid', | ||
type: 'ComponentValue', | ||
}, | ||
}, | ||
}, | ||
}, | ||
areEntitiesFetched, | ||
resolveDesignValue, | ||
renderDropzone, | ||
definition, | ||
userIsDragging, | ||
}), | ||
); | ||
|
||
expect(result.current.componentProps.label).toEqual('Click here'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters