-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1126 from Amsterdam-Music-Lab/ts/convert-button-ts
Refactor: Convert Button component & audio utility to TypeScript
- Loading branch information
Showing
4 changed files
with
65 additions
and
51 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,48 @@ | ||
import React from 'react'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import Button from './Button'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
describe('Button component', () => { | ||
|
||
it('renders correctly', () => { | ||
const mockOnClick = vi.fn(); | ||
const { getByText } = render(<Button title="Test Button" onClick={mockOnClick} />); | ||
const buttonElement = getByText('Test Button'); | ||
|
||
expect(document.body.contains(buttonElement)).toBe(true); | ||
}); | ||
|
||
it('calls onClick handler only once', () => { | ||
const mockOnClick = vi.fn(); | ||
const { getByText } = render(<Button title="Test Button" onClick={mockOnClick} />); | ||
|
||
const button = getByText('Test Button'); | ||
fireEvent.click(button); | ||
fireEvent.click(button); // second click | ||
|
||
expect(mockOnClick).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('does not call onClick when disabled is true', () => { | ||
const mockOnClick = vi.fn(); | ||
const { getByText } = render(<Button title="Test Button" onClick={mockOnClick} disabled={true} />); | ||
|
||
const button = getByText('Test Button'); | ||
fireEvent.click(button); | ||
|
||
expect(mockOnClick).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('applies custom class and style', () => { | ||
const mockOnClick = vi.fn(); | ||
const style = { backgroundColor: 'blue' }; | ||
const { getByText } = render(<Button title="Test Button" className="custom-class" style={style} onClick={mockOnClick} />); | ||
|
||
const button = getByText('Test Button'); | ||
|
||
expect(button.classList.contains('custom-class')).toBe(true); | ||
expect(button.style.backgroundColor).toBe('blue'); | ||
}); | ||
|
||
}); |
This file contains 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
File renamed without changes.