-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Html control with preview #4908
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { within } from '@testing-library/react' | ||
import * as EP from '../../../../core/shared/element-path' | ||
import { selectComponentsForTest } from '../../../../utils/utils.test-utils' | ||
import { selectComponentsForTest, wait } from '../../../../utils/utils.test-utils' | ||
import { mouseClickAtPoint, pressKey } from '../../../canvas/event-helpers.test-utils' | ||
import { renderTestEditorWithCode } from '../../../canvas/ui-jsx.test-utils' | ||
import { | ||
|
@@ -53,31 +53,31 @@ describe('Set element prop via the data picker', () => { | |
let currentOption = editor.renderedDOM.getByTestId(VariableFromScopeOptionTestId(0)) | ||
await mouseClickAtPoint(currentOption, { x: 2, y: 2 }) | ||
expect(within(theScene).queryByText('Title too')).not.toBeNull() | ||
expect(within(theInspector).queryAllByText('Title too')).toHaveLength(2) | ||
expect(within(theInspector).queryByText('Title too')).not.toBeNull() | ||
|
||
// choose another string-valued variable | ||
currentOption = editor.renderedDOM.getByTestId(VariableFromScopeOptionTestId(1)) | ||
await mouseClickAtPoint(currentOption, { x: 2, y: 2 }) | ||
expect(within(theScene).queryByText('Alternate title')).not.toBeNull() | ||
expect(within(theInspector).queryAllByText('Alternate title')).toHaveLength(2) | ||
expect(within(theInspector).queryByText('Alternate title')).not.toBeNull() | ||
|
||
// choose an object prop | ||
currentOption = editor.renderedDOM.getByTestId(VariableFromScopeOptionTestId(13)) | ||
await mouseClickAtPoint(currentOption, { x: 2, y: 2 }) | ||
expect(within(theScene).queryByText('The First Title')).not.toBeNull() | ||
expect(within(theInspector).queryAllByText('The First Title')).toHaveLength(2) | ||
expect(within(theInspector).queryByText('The First Title')).not.toBeNull() | ||
|
||
// choose an object prop | ||
currentOption = editor.renderedDOM.getByTestId(VariableFromScopeOptionTestId(14)) | ||
await mouseClickAtPoint(currentOption, { x: 2, y: 2 }) | ||
expect(within(theScene).queryByText('Sweet')).not.toBeNull() | ||
expect(within(theInspector).queryAllByText('Sweet')).toHaveLength(2) | ||
expect(within(theInspector).queryByText('Sweet')).not.toBeNull() | ||
|
||
// choose an array element | ||
currentOption = editor.renderedDOM.getByTestId(VariableFromScopeOptionTestId(16)) | ||
await mouseClickAtPoint(currentOption, { x: 2, y: 2 }) | ||
expect(within(theScene).queryByText('Chapter One')).not.toBeNull() | ||
expect(within(theInspector).queryAllByText('Chapter One')).toHaveLength(2) | ||
expect(within(theInspector).queryByText('Chapter One')).not.toBeNull() | ||
}) | ||
|
||
it('with number input control descriptor present', async () => { | ||
|
@@ -345,6 +345,17 @@ describe('Controls from registering components', () => { | |
expect(within(theScene).queryByText('New title')).not.toBeNull() | ||
}) | ||
|
||
it('registering internal component with html prop shows preview', async () => { | ||
const editor = await renderTestEditorWithCode( | ||
registerInternalComponentProjectWithHtmlProp, | ||
'await-first-dom-report', | ||
) | ||
await selectComponentsForTest(editor, [EP.fromString('sb/scene/pg:root/title')]) | ||
|
||
const theInspector = editor.renderedDOM.getByTestId('inspector-sections-container') | ||
expect(within(theInspector).queryByText('Hello Utopia')).not.toBeNull() | ||
}) | ||
|
||
it('registering external component', async () => { | ||
const editor = await renderTestEditorWithCode( | ||
registerExternalComponentProject, | ||
|
@@ -673,6 +684,144 @@ export var storyboard = ( | |
)` | ||
} | ||
|
||
const projectWithHtmlProp = (imageUrl: string) => `import * as React from 'react' | ||
import { | ||
Storyboard, | ||
Scene, | ||
registerInternalComponent, | ||
} from 'utopia-api' | ||
|
||
function Image({ url }) { | ||
return <img src={url} /> | ||
} | ||
|
||
var Playground = ({ style }) => { | ||
return ( | ||
<div style={style} data-uid='root'> | ||
<Image url='${imageUrl}' data-uid='image' /> | ||
</div> | ||
) | ||
} | ||
|
||
export var storyboard = ( | ||
<Storyboard data-uid='sb'> | ||
<Scene | ||
style={{ | ||
width: 521, | ||
height: 266, | ||
position: 'absolute', | ||
left: 554, | ||
top: 247, | ||
backgroundColor: 'white', | ||
}} | ||
data-uid='scene' | ||
data-testid='scene' | ||
commentId='120' | ||
> | ||
<Playground | ||
style={{ | ||
width: 454, | ||
height: 177, | ||
position: 'absolute', | ||
left: 34, | ||
top: 44, | ||
backgroundColor: 'white', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}} | ||
title='Hello Utopia' | ||
data-uid='pg' | ||
/> | ||
</Scene> | ||
</Storyboard> | ||
) | ||
|
||
registerInternalComponent(Image, { | ||
supportsChildren: false, | ||
properties: { | ||
url: { | ||
control: 'string-input', | ||
}, | ||
}, | ||
variants: [ | ||
{ | ||
code: '<Image />', | ||
}, | ||
], | ||
}) | ||
|
||
` | ||
|
||
const registerInternalComponentProjectWithHtmlProp = `import * as React from 'react' | ||
import { | ||
Storyboard, | ||
Scene, | ||
registerInternalComponent, | ||
} from 'utopia-api' | ||
|
||
function Title({ text }) { | ||
return <h2 data-uid='0cd'>{text}</h2> | ||
} | ||
|
||
var Playground = ({ style }) => { | ||
return ( | ||
<div style={style} data-uid='root'> | ||
<Title text='<p>Hello Utopia</p>' data-uid='title' /> | ||
</div> | ||
) | ||
} | ||
|
||
export var storyboard = ( | ||
<Storyboard data-uid='sb'> | ||
<Scene | ||
style={{ | ||
width: 521, | ||
height: 266, | ||
position: 'absolute', | ||
left: 554, | ||
top: 247, | ||
backgroundColor: 'white', | ||
}} | ||
data-uid='scene' | ||
data-testid='scene' | ||
commentId='120' | ||
> | ||
<Playground | ||
style={{ | ||
width: 454, | ||
height: 177, | ||
position: 'absolute', | ||
left: 34, | ||
top: 44, | ||
backgroundColor: 'white', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}} | ||
title='Hello Utopia' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't name this Hello Utopia, just to avoid the test text matcher being confused in the future |
||
data-uid='pg' | ||
/> | ||
</Scene> | ||
</Storyboard> | ||
) | ||
|
||
registerInternalComponent(Title, { | ||
supportsChildren: false, | ||
properties: { | ||
text: { | ||
control: 'html-input', | ||
}, | ||
}, | ||
variants: [ | ||
{ | ||
code: '<Title />', | ||
}, | ||
], | ||
}) | ||
|
||
` | ||
|
||
// const projectWithImage = (imageUrl: string) => `import * as React from 'react' | ||
// import { | ||
// Storyboard, | ||
|
@@ -739,5 +888,3 @@ export var storyboard = ( | |
// }, | ||
// ], | ||
// }) | ||
|
||
// ` |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's slowly getting worse, this test :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as if to prove my point that testing what is in the UI is not the way to go