-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not autolock root element when it is a leaf (#4230)
* Do not autolock root element when it is a leaf * Add tests * Remove unnecessary code from test * Making it more readable
- Loading branch information
Showing
3 changed files
with
81 additions
and
8 deletions.
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
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,61 @@ | ||
import { renderTestEditorWithCode } from '../../components/canvas/ui-jsx.test-utils' | ||
import * as EP from './element-path' | ||
|
||
function testCode(snippet: string) { | ||
return ` | ||
import * as React from 'react' | ||
import { Scene, Storyboard } from 'utopia-api' | ||
export var storyboard = ( | ||
<Storyboard data-uid='sb'> | ||
<Scene | ||
style={{ | ||
width: 700, | ||
height: 759, | ||
position: 'absolute', | ||
left: 10, | ||
top: 10, | ||
}} | ||
data-uid='sc' | ||
> | ||
<App data-uid='app' /> | ||
</Scene> | ||
</Storyboard> | ||
) | ||
export var App = (props) => { | ||
return ( | ||
<div | ||
style={{ | ||
height: '100%', | ||
width: '100%', | ||
contain: 'layout', | ||
}} | ||
data-uid='app-root' | ||
> | ||
${snippet} | ||
</div> | ||
) | ||
}` | ||
} | ||
|
||
describe('Auto-locking elements', () => { | ||
it('Root element of component locked when it is not a leaf element', async () => { | ||
const renderResult = await renderTestEditorWithCode( | ||
testCode('<div>Hello</div>'), | ||
'await-first-dom-report', | ||
) | ||
|
||
expect(renderResult.getEditorState().editor.lockedElements.simpleLock.map(EP.toString)).toEqual( | ||
['sb/sc/app:app-root'], | ||
) | ||
}) | ||
|
||
it('Root element of component is not locked when it is a leaf element', async () => { | ||
const renderResult = await renderTestEditorWithCode(testCode('Hello'), 'await-first-dom-report') | ||
|
||
expect(renderResult.getEditorState().editor.lockedElements.simpleLock.map(EP.toString)).toEqual( | ||
[], | ||
) | ||
}) | ||
}) |
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