Files
dify/web/app/components/workflow/comment/cursor.spec.tsx
非法操作 53a22aa41b feat: collaboration (#30781)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-04-16 02:21:04 +00:00

57 lines
1.5 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ControlMode } from '../types'
import { CommentCursor } from './cursor'
const mockState = {
controlMode: ControlMode.Pointer,
isCommentPlacing: false,
mousePosition: {
elementX: 10,
elementY: 20,
},
}
vi.mock('@/app/components/base/icons/src/public/other', () => ({
Comment: (props: { className?: string }) => <svg data-testid="comment-icon" {...props} />,
}))
vi.mock('../store', () => ({
useStore: (selector: (state: typeof mockState) => unknown) => selector(mockState),
}))
describe('CommentCursor', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('renders nothing when not in comment mode', () => {
mockState.controlMode = ControlMode.Pointer
render(<CommentCursor />)
expect(screen.queryByTestId('comment-icon')).not.toBeInTheDocument()
})
it('renders at current mouse position when in comment mode', () => {
mockState.controlMode = ControlMode.Comment
mockState.isCommentPlacing = false
render(<CommentCursor />)
const icon = screen.getByTestId('comment-icon')
const container = icon.parentElement as HTMLElement
expect(container).toHaveStyle({ left: '10px', top: '20px' })
})
it('renders nothing when comment is in placing mode', () => {
mockState.controlMode = ControlMode.Comment
mockState.isCommentPlacing = true
render(<CommentCursor />)
expect(screen.queryByTestId('comment-icon')).not.toBeInTheDocument()
})
})