import { act, screen } from '@testing-library/react'
import { BaseBoxShapeUtil, Editor } from '@tldraw/editor'
import { useState } from 'react'
import { renderTldrawComponent } from '../test/testutils/renderTldrawComponent'
import { Tldraw } from './Tldraw'
describe('', () => {
it('Renders without crashing', async () => {
await renderTldrawComponent(
,
{ waitForPatterns: false }
)
await screen.findByTestId('canvas-1')
})
it('Doesnt cause re-render loops with unstable shape utils + tools', async () => {
function TestComponent() {
const [_, setEditor] = useState(null)
return (
)
}
await renderTldrawComponent(, { waitForPatterns: false })
await screen.findByTestId('canvas-1')
})
it('Doesnt cause re-render loops when shape utils change', async () => {
class FakeShapeUtil1 extends BaseBoxShapeUtil {
static override type = 'fake' as const
override getDefaultProps() {
throw new Error('Method not implemented.')
}
override component(_: any) {
throw new Error('Method not implemented.')
}
override indicator(_: any) {
throw new Error('Method not implemented.')
}
}
class FakeShapeUtil2 extends BaseBoxShapeUtil {
static override type = 'fake' as const
override getDefaultProps() {
throw new Error('Method not implemented.')
}
override component(_: any) {
throw new Error('Method not implemented.')
}
override indicator(_: any) {
throw new Error('Method not implemented.')
}
}
const rendered = await renderTldrawComponent(
,
{ waitForPatterns: false }
)
await screen.findByTestId('canvas-1')
await act(async () => {
rendered.rerender(
)
})
await screen.findByTestId('canvas-2')
})
})