-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWelcome.test.tsx
More file actions
68 lines (54 loc) · 2.16 KB
/
Welcome.test.tsx
File metadata and controls
68 lines (54 loc) · 2.16 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
import { fireEvent, render } from '@testing-library/react'
import React from 'react'
import { describe, expect, it, vi } from 'vitest'
import Welcome from '../../src/components/Welcome.js'
describe('Welcome Component', () => {
it('renders welcome content', () => {
const onClose = vi.fn()
const { getByRole, getByText } = render(<Welcome onClose={onClose} />)
expect(getByText('npx hyperparam')).toBeDefined()
expect(getByText('Got it')).toBeDefined()
const button = getByRole('button')
expect(button).toBeDefined()
expect(button.textContent).toBe('Got it')
})
it('calls onClose when button is clicked', () => {
const onClose = vi.fn()
const { getByRole } = render(<Welcome onClose={onClose} />)
fireEvent.click(getByRole('button'))
expect(onClose).toHaveBeenCalledTimes(1)
})
it('calls onClose when clicking outside the popup', () => {
const onClose = vi.fn()
const { container } = render(<Welcome onClose={onClose} />)
// Find the backdrop element
const backdropElement = container.querySelector('.welcome')
expect(backdropElement).toBeDefined()
if (backdropElement) {
fireEvent.click(backdropElement)
expect(onClose).toHaveBeenCalledTimes(1)
}
})
it('does not call onClose when clicking inside the popup', () => {
const onClose = vi.fn()
const { getByText } = render(<Welcome onClose={onClose} />)
// Find and click on an element inside the popup content
const paragraphElement = getByText('Supported file types include Parquet, CSV, JSON, Markdown, and Text.')
fireEvent.click(paragraphElement)
expect(onClose).not.toHaveBeenCalled()
})
it('calls onClose when pressing Escape key', () => {
const onClose = vi.fn()
render(<Welcome onClose={onClose} />)
// Simulate pressing the Escape key
fireEvent.keyDown(window, { key: 'Escape' })
expect(onClose).toHaveBeenCalledTimes(1)
})
it('does not call onClose when pressing other keys', () => {
const onClose = vi.fn()
render(<Welcome onClose={onClose} />)
// Simulate pressing a different key
fireEvent.keyDown(window, { key: 'Enter' })
expect(onClose).not.toHaveBeenCalled()
})
})