-
Notifications
You must be signed in to change notification settings - Fork 380
Expand file tree
/
Copy pathModelName.test.tsx
More file actions
72 lines (66 loc) · 2.18 KB
/
ModelName.test.tsx
File metadata and controls
72 lines (66 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { render, screen, within } from '@testing-library/react'
import { ModelName } from './ModelName'
describe('ModelName', () => {
it('renders full model name with catalog, schema, and model', () => {
render(<ModelName name="cat.sch.model" />)
expect(screen.getByText('cat')).toBeInTheDocument()
expect(screen.getByText('sch')).toBeInTheDocument()
expect(screen.getByText('model')).toBeInTheDocument()
})
it('hides catalog when hideCatalog is true', () => {
render(
<ModelName
name="cat.sch.model"
hideCatalog
/>,
)
expect(screen.queryByText('cat')).not.toBeInTheDocument()
expect(screen.getByText('sch')).toBeInTheDocument()
expect(screen.getByText('model')).toBeInTheDocument()
})
it('hides schema when hideSchema is true', () => {
render(
<ModelName
name="cat.sch.model"
hideSchema
/>,
)
expect(screen.getByText('cat')).toBeInTheDocument()
expect(screen.queryByText('sch')).not.toBeInTheDocument()
expect(screen.getByText('model')).toBeInTheDocument()
})
it('hides icon when hideIcon is true', () => {
const { container } = render(
<ModelName
name="cat.sch.model"
hideIcon
/>,
)
// Should not render the Box icon SVG
expect(container.querySelector('svg')).toBeNull()
})
it('shows tooltip when showTooltip is true and catalog or schema is hidden', async () => {
render(
<ModelName
name="cat.sch.model"
hideCatalog
showTooltip
/>,
)
// Tooltip trigger is present (icon)
const modelName = screen.getByTestId('model-name')
expect(modelName).toBeInTheDocument()
await userEvent.hover(modelName)
const tooltip = await screen.findByRole('tooltip')
expect(tooltip).toBeInTheDocument()
within(tooltip).getByText('cat.sch.model')
})
it('throws error if name is empty', () => {
// Suppress error output for this test
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
expect(() => render(<ModelName name="" />)).toThrow()
spy.mockRestore()
})
})