
This PR replaces our webdriver end to end tests with playwright tests. It: - replaces our webdriver workflow with a new e2e workflow based on playwright - removes the webdriver project - adds e2e tests to our examples app - replaces all `data-wd` attributes with `data-testid` ### Coverage Most of the tests from our previous e2e tests are reproduced here, though there are some related to our gestures that will need to be done in a different way—or not at all. I've also added a handful of new tests, too. ### Where are they The tests are now part of our examples app rather than being in its own different app. This should help us test our different examples too. As far as I can tell there are no downsides here in terms of the regular developer experience, though they might complicate any CodeSandbox projects that are hooked into the examples app. ### Change Type - [x] `tests` — Changes to any testing-related code only (will not publish a new version)
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { ANIMATION_MEDIUM_MS, useApp } from '@tldraw/editor'
|
|
import * as React from 'react'
|
|
import { track } from 'signia-react'
|
|
import { useActions } from '../../hooks/useActions'
|
|
import { useBreakpoint } from '../../hooks/useBreakpoint'
|
|
import { useTranslation } from '../../hooks/useTranslation/useTranslation'
|
|
import { Button } from '../primitives/Button'
|
|
import * as M from '../primitives/DropdownMenu'
|
|
|
|
export const ZoomMenu = track(function ZoomMenu() {
|
|
const app = useApp()
|
|
const msg = useTranslation()
|
|
const breakpoint = useBreakpoint()
|
|
|
|
const zoom = app.zoomLevel
|
|
const hasShapes = app.shapeIds.size > 0
|
|
const hasSelected = app.selectedIds.length > 0
|
|
const isZoomedTo100 = app.zoomLevel === 1
|
|
|
|
const handleDoubleClick = React.useCallback(() => {
|
|
app.resetZoom(app.viewportScreenCenter, { duration: ANIMATION_MEDIUM_MS })
|
|
}, [app])
|
|
|
|
return (
|
|
<M.Root id="zoom">
|
|
<M.Trigger>
|
|
<Button
|
|
title={`${msg('navigation-zone.zoom')}`}
|
|
data-testid="minimap.zoom-menu"
|
|
className={breakpoint < 5 ? 'tlui-zoom-menu__button' : 'tlui-zoom-menu__button__pct'}
|
|
onDoubleClick={handleDoubleClick}
|
|
icon={breakpoint < 4 ? 'zoom-in' : undefined}
|
|
>
|
|
{breakpoint < 4 ? null : (
|
|
<span style={{ flexGrow: 0, textAlign: 'center' }}>{Math.floor(zoom * 100)}%</span>
|
|
)}
|
|
</Button>
|
|
</M.Trigger>
|
|
<M.Content side="top" align="start" alignOffset={0}>
|
|
<M.Group>
|
|
<ZoomMenuItem action="zoom-in" data-testid="minimap.zoom-menu.zoom-in" noClose />
|
|
<ZoomMenuItem action="zoom-out" data-testid="minimap.zoom-menu.zoom-out" noClose />
|
|
<ZoomMenuItem
|
|
action="zoom-to-100"
|
|
data-testid="minimap.zoom-menu.zoom-to-100"
|
|
noClose
|
|
disabled={isZoomedTo100}
|
|
/>
|
|
<ZoomMenuItem
|
|
action="zoom-to-fit"
|
|
disabled={!hasShapes}
|
|
data-testid="minimap.zoom-menu.zoom-to-fit"
|
|
noClose
|
|
/>
|
|
<ZoomMenuItem
|
|
action="zoom-to-selection"
|
|
disabled={!hasSelected}
|
|
data-testid="minimap.zoom-menu.zoom-to-selection"
|
|
noClose
|
|
/>
|
|
</M.Group>
|
|
</M.Content>
|
|
</M.Root>
|
|
)
|
|
})
|
|
|
|
function ZoomMenuItem(props: {
|
|
action: string
|
|
disabled?: boolean
|
|
noClose?: boolean
|
|
'data-testid'?: string
|
|
}) {
|
|
const { action, disabled = false, noClose = false } = props
|
|
const actions = useActions()
|
|
|
|
return (
|
|
<M.Item
|
|
label={actions[action].label}
|
|
kbd={actions[action].kbd}
|
|
data-testid={props['data-testid']}
|
|
onClick={() => actions[action].onSelect('zoom-menu')}
|
|
noClose={noClose}
|
|
disabled={disabled}
|
|
/>
|
|
)
|
|
}
|