Skip to content

Commit

Permalink
Factor out wrapInElement calls from tests (#4438)
Browse files Browse the repository at this point in the history
* remove the WRAP_ELEMENT_DEFAULT_SHORTCUT

* refactor tests
  • Loading branch information
bkrmendy authored Oct 27, 2023
1 parent f24edf2 commit b1fa262
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 268 deletions.
37 changes: 13 additions & 24 deletions editor/src/components/canvas/canvas-context-menu.spec.browser2.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { fireEvent } from '@testing-library/react'
import { forElementChildOptic } from '../../core/model/common-optics'
import {
conditionalWhenFalseOptic,
jsxConditionalExpressionOptic,
} from '../../core/model/conditionals'
import { JSXElementChild } from '../../core/shared/element-template'
import { unsafeGet } from '../../core/shared/optics/optic-utilities'
import { Optic } from '../../core/shared/optics/optics'
import { BakedInStoryboardUID } from '../../core/model/scene-utils'
import * as EP from '../../core/shared/element-path'
import { altCmdModifier, cmdModifier } from '../../utils/modifiers'
import { selectComponents } from '../editor/actions/meta-actions'
import { EditorState, navigatorEntryToKey } from '../editor/store/editor-state'
import { navigatorEntryToKey } from '../editor/store/editor-state'
import { CanvasControlsContainerID } from './controls/new-canvas-controls'
import {
mouseClickAtPoint,
Expand All @@ -28,14 +25,14 @@ import {
TestAppUID,
TestSceneUID,
} from './ui-jsx.test-utils'
import { expectNoAction, selectComponentsForTest, wait } from '../../utils/utils.test-utils'
import {
expectNoAction,
searchInFloatingMenu,
selectComponentsForTest,
} from '../../utils/utils.test-utils'
import { MetadataUtils } from '../../core/model/element-metadata-utils'
import type { ElementPath } from '../../core/shared/project-file-types'
import { getDomRectCenter } from '../../core/shared/dom-utils'
import { wrapInElement } from '../editor/actions/action-creators'
import { generateUidWithExistingComponents } from '../../core/model/element-template-utils'
import { defaultTransparentViewElement } from '../editor/defaults'
import { FOR_TESTS_setNextGeneratedUid } from '../../core/model/element-template-utils.test-utils'

function expectAllSelectedViewsToHaveMetadata(editor: EditorRenderResult) {
const selectedViews = editor.getEditorState().editor.selectedViews
Expand Down Expand Up @@ -883,7 +880,7 @@ describe('canvas context menu', () => {
})

describe('wrap in from contextmenu', () => {
it('wrap in div works inside a conditional on an expression', async () => {
xit('wrap in div works inside a conditional on an expression', async () => {
const renderResult = await renderTestEditorWithCode(
makeTestProjectCodeWithSnippet(
`<div style={{ ...props.style }} data-uid='aaa'>
Expand Down Expand Up @@ -920,20 +917,7 @@ describe('canvas context menu', () => {

await renderResult.dispatch(selectComponents([testValuePath], false), true)

// Wrap it in a div.
await renderResult.dispatch(
[
wrapInElement([testValuePath], {
element: defaultTransparentViewElement(
generateUidWithExistingComponents(
renderResult.getEditorState().editor.projectContents,
),
),
importsToAdd: {},
}),
],
true,
)
await wrapInElement(renderResult, 'div')
await renderResult.getDispatchFollowUpActionsFinished()

expect(getPrintedUiJsCodeWithoutUIDs(renderResult.getEditorState())).toEqual(
Expand Down Expand Up @@ -965,3 +949,8 @@ describe('canvas context menu', () => {
})
})
})

async function wrapInElement(renderResult: EditorRenderResult, query: string) {
await pressKey('w') // open the wrap menu
await searchInFloatingMenu(renderResult, query)
}
Loading

0 comments on commit b1fa262

Please sign in to comment.