-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
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
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,35 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { SwapSettings } from './SwapSettings'; | ||
|
||
describe('SwapSettings', () => { | ||
it('renders with default title', () => { | ||
render(<SwapSettings />); | ||
expect(screen.getByText('Auto')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders with custom title', () => { | ||
render(<SwapSettings title="Custom" />); | ||
expect(screen.getByText('Custom')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders custom icon when provided', () => { | ||
const CustomIcon = () => ( | ||
<svg data-testid="custom-icon" aria-hidden="true" focusable="false"> | ||
<title>Custom Icon</title> | ||
</svg> | ||
); | ||
render(<SwapSettings icon={<CustomIcon />} />); | ||
expect(screen.getByTestId('custom-icon')).toBeInTheDocument(); | ||
}); | ||
|
||
it('applies correct classes to the button', () => { | ||
render(<SwapSettings />); | ||
const button = screen.getByRole('button', { | ||
name: /toggle swap settings/i, | ||
}); | ||
expect(button).toHaveClass( | ||
'rounded-full p-2 opacity-50 transition-opacity hover:opacity-100', | ||
); | ||
}); | ||
}); |
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,32 @@ | ||
import { isValidElement, useMemo } from 'react'; | ||
import { SwapSettingsSvg } from '../../internal/svg/swapSettings'; | ||
import type { SwapSettingsReact } from '../types'; | ||
|
||
export function SwapSettings({ icon, title = 'Auto' }: SwapSettingsReact) { | ||
const iconSvg = useMemo(() => { | ||
if (icon === undefined) { | ||
return SwapSettingsSvg; | ||
} | ||
if (isValidElement(icon)) { | ||
return icon; | ||
} | ||
}, [icon]); | ||
|
||
return ( | ||
<div | ||
className="flex w-full items-center justify-between" | ||
data-testid="ockSwapSettings_Settings" | ||
> | ||
<div className="flex items-center space-x-1"> | ||
<h4 className="font-medium text-base">{title}</h4> | ||
<button | ||
type="button" | ||
aria-label="Toggle swap settings" | ||
className="rounded-full p-2 opacity-50 transition-opacity hover:opacity-100" | ||
> | ||
{iconSvg} | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} |
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
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