add unittests

This commit is contained in:
hjlarry
2026-01-19 21:11:44 +08:00
parent c17f564718
commit aaa3d2d74f
4 changed files with 385 additions and 0 deletions

View File

@ -0,0 +1,45 @@
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,
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
render(<CommentCursor />)
const icon = screen.getByTestId('comment-icon')
const container = icon.parentElement as HTMLElement
expect(container).toHaveStyle({ left: '10px', top: '20px' })
})
})