Files
novalon-manage-system/novalon-manage-web/src/__tests__/components/ChartContainer.test.tsx
T
张翔 3e8e14d662 feat: 新增监控页面、部门管理占位与单元测试
- 新增系统监控模块(在线用户、定时任务、数据监控、服务器监控、缓存监控)
- 新增部门管理占位页面
- 路由注册新增模块与懒加载
- DefaultLayout 侧边菜单与布局优化
- 新增前端单元测试与后端 RoleUpdateRequest 测试
2026-05-06 19:43:39 +08:00

45 lines
1.5 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import { render } from '@testing-library/react'
import ChartContainer from '@/components/ChartContainer'
describe('ChartContainer', () => {
it('should call onInit with container element on mount', () => {
const onInit = vi.fn()
render(<ChartContainer onInit={onInit} />)
expect(onInit).toHaveBeenCalledTimes(1)
expect(onInit).toHaveBeenCalledWith(expect.any(HTMLElement))
})
it('should call onDestroy on unmount', () => {
const onDestroy = vi.fn()
const onInit = vi.fn()
const { unmount } = render(<ChartContainer onInit={onInit} onDestroy={onDestroy} />)
expect(onDestroy).not.toHaveBeenCalled()
unmount()
expect(onDestroy).toHaveBeenCalledTimes(1)
})
it('should not crash when onDestroy is not provided', () => {
const onInit = vi.fn()
const { unmount } = render(<ChartContainer onInit={onInit} />)
expect(() => unmount()).not.toThrow()
})
it('should apply custom style', () => {
const onInit = vi.fn()
const { container } = render(
<ChartContainer onInit={onInit} style={{ backgroundColor: 'red' }} />
)
const div = container.firstChild as HTMLElement
expect(div.style.backgroundColor).toBe('red')
})
it('should have default width and height 100%', () => {
const onInit = vi.fn()
const { container } = render(<ChartContainer onInit={onInit} />)
const div = container.firstChild as HTMLElement
expect(div.style.width).toBe('100%')
expect(div.style.height).toBe('100%')
})
})