-
Notifications
You must be signed in to change notification settings - Fork 17
test(ui): add test coverage for ui components #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08a56d1
test(ui): add test coverage for ui components
Aarya1402 5846beb
test(ui): add test coverage for Input component
Aarya1402 551ca41
test(ui): add test coverage for Panel component
Aarya1402 0c59bd4
test(ui): add test coverage for ProgressBar component
Aarya1402 770be7f
test(ui): add test coverage for ScrollArea component
Aarya1402 07ddfe5
test(ui): add test coverage for MarkdownRenderer component
Aarya1402 fdfd964
fix(ui): fix failing ScrollArea test
Aarya1402 bbe3244
test(terminal): add test coverage for TerminalInput component
Aarya1402 08d57fd
fix(types): add jest-dom type reference
Aarya1402 ac8b7d8
Update package.json
Aarya1402 83f0e9c
Update package.json
Aarya1402 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import { TerminalInput } from './TerminalInput'; | ||
| import { describe, it, expect, vi } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('TerminalInput component', () => { | ||
| it('renders correctly', () => { | ||
| const onChange = vi.fn(); | ||
| const onSubmit = vi.fn(); | ||
| render(<TerminalInput value="" onChange={onChange} onSubmit={onSubmit} />); | ||
| expect(screen.getByPlaceholderText('Type here...')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onChange when typing', () => { | ||
| const onChange = vi.fn(); | ||
| const onSubmit = vi.fn(); | ||
| render(<TerminalInput value="" onChange={onChange} onSubmit={onSubmit} />); | ||
| const input = screen.getByPlaceholderText('Type here...'); | ||
| fireEvent.change(input, { target: { value: 'hello' } }); | ||
| expect(onChange).toHaveBeenCalledWith('hello'); | ||
| }); | ||
|
|
||
| it('calls onSubmit when Enter is pressed', () => { | ||
| const onChange = vi.fn(); | ||
| const onSubmit = vi.fn(); | ||
| render(<TerminalInput value="test" onChange={onChange} onSubmit={onSubmit} />); | ||
| const input = screen.getByPlaceholderText('Type here...'); | ||
| fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' }); | ||
| expect(onSubmit).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('clears input when Escape is pressed', () => { | ||
| const onChange = vi.fn(); | ||
| const onSubmit = vi.fn(); | ||
| render(<TerminalInput value="test" onChange={onChange} onSubmit={onSubmit} />); | ||
| const input = screen.getByPlaceholderText('Type here...'); | ||
| fireEvent.keyDown(input, { key: 'Escape', code: 'Escape' }); | ||
| expect(onChange).toHaveBeenCalledWith(''); | ||
| }); | ||
|
Aarya1402 marked this conversation as resolved.
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Button } from './Button'; | ||
| import { describe, it, expect } from 'vitest'; | ||
|
|
||
| describe('Button component', () => { | ||
| it('renders children correctly', () => { | ||
| render(<Button>Click Me</Button>); | ||
| expect(screen.getByText('Click Me')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows loading state when loading prop is true', () => { | ||
| render(<Button loading>Submit</Button>); | ||
| expect(screen.getByText('⏳')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button')).toBeDisabled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Input } from './Input'; | ||
| import { describe, it, expect } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('Input component', () => { | ||
| it('renders correctly', () => { | ||
| render(<Input placeholder="Enter text" />); | ||
| expect(screen.getByPlaceholderText('Enter text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('passes ref correctly', () => { | ||
| const ref = React.createRef<HTMLInputElement>(); | ||
| render(<Input ref={ref} />); | ||
| expect(ref.current).toBeInstanceOf(HTMLInputElement); | ||
| }); | ||
|
|
||
| it('applies error styles when hasError is true', () => { | ||
| render(<Input hasError data-testid="error-input" />); | ||
| const input = screen.getByTestId('error-input'); | ||
| expect(input.style.border).toContain('var(--status-error)'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { MarkdownRenderer } from './MarkdownRenderer'; | ||
| import { describe, it, expect } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('MarkdownRenderer component', () => { | ||
| it('renders markdown content correctly', () => { | ||
| render(<MarkdownRenderer content="# Hello World" />); | ||
| // Testing specific output depends on react-markdown, we just test if the component renders the text | ||
| expect(screen.getByText('Hello World')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders code blocks correctly', () => { | ||
| render(<MarkdownRenderer content="`inline code`" />); | ||
| expect(screen.getByText('inline code')).toBeInTheDocument(); | ||
| expect(screen.getByText('inline code').tagName).toBe('CODE'); | ||
| }); | ||
|
|
||
| it('renders links correctly', () => { | ||
| render(<MarkdownRenderer content="[GitHub](https://github.com)" />); | ||
| const link = screen.getByRole('link', { name: 'GitHub' }); | ||
| expect(link).toBeInTheDocument(); | ||
| expect(link).toHaveAttribute('href', 'https://github.com'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { Panel } from './Panel'; | ||
| import { describe, it, expect } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('Panel component', () => { | ||
| it('renders children correctly', () => { | ||
| render(<Panel>Panel Content</Panel>); | ||
| expect(screen.getByText('Panel Content')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders title when provided', () => { | ||
| render(<Panel title="Test Title">Content</Panel>); | ||
| expect(screen.getByText('[ Test Title ]')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders headerRight when provided', () => { | ||
| render( | ||
| <Panel title="Title" headerRight={<button>Action</button>}> | ||
| Content | ||
| </Panel>, | ||
| ); | ||
| expect(screen.getByRole('button', { name: 'Action' })).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ProgressBar } from './ProgressBar'; | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('ProgressBar component', () => { | ||
| beforeEach(() => { | ||
| vi.useFakeTimers(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it('renders correctly with current and total', () => { | ||
| render(<ProgressBar current={5} total={10} />); | ||
| expect(screen.getByText(/5\/10 \(50%\)/)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders label when provided', () => { | ||
| render(<ProgressBar current={5} total={10} label="Processing" />); | ||
| expect(screen.getByText('Processing')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('hides count when showCount is false', () => { | ||
| render(<ProgressBar current={5} total={10} showCount={false} />); | ||
| expect(screen.queryByText(/5\/10 \(50%\)/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows ETA when startTime is provided', () => { | ||
| const startTime = Date.now(); | ||
| render(<ProgressBar current={5} total={10} startTime={startTime} />); | ||
| expect(screen.getByText(/ETA:/)).toBeInTheDocument(); | ||
| }); | ||
|
Aarya1402 marked this conversation as resolved.
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ScrollArea } from './ScrollArea'; | ||
| import { describe, it, expect } from 'vitest'; | ||
| import React from 'react'; | ||
|
|
||
| describe('ScrollArea component', () => { | ||
| it('renders children correctly', () => { | ||
| render(<ScrollArea>Scrollable Content</ScrollArea>); | ||
| expect(screen.getByText('Scrollable Content')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('applies maxHeight when provided', () => { | ||
| render(<ScrollArea maxHeight="200px">Scroll Area Content</ScrollArea>); | ||
| const element = screen.getByText('Scroll Area Content'); | ||
| expect(element.style.maxHeight).toBe('200px'); | ||
| }); | ||
|
|
||
| it('passes innerRef correctly', () => { | ||
| const ref = React.createRef<HTMLDivElement>(); | ||
| render(<ScrollArea innerRef={ref}>Content</ScrollArea>); | ||
| expect(ref.current).toBeInstanceOf(HTMLDivElement); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import '@testing-library/jest-dom'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.