-
Notifications
You must be signed in to change notification settings - Fork 230
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
1 parent
975abad
commit 514515d
Showing
5 changed files
with
199 additions
and
36 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,97 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { useDotsPath } from './useDotsPath'; | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
describe('useDotsPath', () => { | ||
const defaultProps = { | ||
matrix: [ | ||
[1, 0, 1], | ||
[0, 1, 0], | ||
[1, 0, 1], | ||
], | ||
size: 300, | ||
logoSize: 60, | ||
logoMargin: 5, | ||
logoBorderRadius: 0, | ||
hasLogo: false, | ||
}; | ||
|
||
it('should generate path for simple matrix without logo', () => { | ||
const { result } = renderHook(() => useDotsPath(defaultProps)); | ||
|
||
expect(result.current).toContain('M'); | ||
expect(result.current).toContain('A'); | ||
}); | ||
|
||
it('should skip logo area when hasLogo is true', () => { | ||
const withLogo = { | ||
...defaultProps, | ||
hasLogo: true, | ||
matrix: [ | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1], | ||
], | ||
}; | ||
|
||
const { result: withLogoResult } = renderHook(() => useDotsPath(withLogo)); | ||
const { result: withoutLogoResult } = renderHook(() => | ||
useDotsPath({ ...withLogo, hasLogo: false }), | ||
); | ||
|
||
expect(withLogoResult.current.length).toBeLessThan( | ||
withoutLogoResult.current.length, | ||
); | ||
}); | ||
|
||
it('should handle round logos', () => { | ||
const withRoundLogo = { | ||
...defaultProps, | ||
size: 300, | ||
hasLogo: true, | ||
logoBorderRadius: 40, | ||
logoSize: 60, | ||
logoMargin: 5, | ||
// Using a larger matrix that's more typical for QR codes | ||
matrix: Array(25).fill(Array(25).fill(1)), | ||
}; | ||
|
||
const { result: roundLogoResult } = renderHook(() => | ||
useDotsPath(withRoundLogo), | ||
); | ||
const { result: squareLogoResult } = renderHook(() => | ||
useDotsPath({ ...withRoundLogo, logoBorderRadius: 0 }), | ||
); | ||
|
||
expect(roundLogoResult.current).not.toBe(squareLogoResult.current); | ||
// expect(roundLogoResult.current).not.toBe(''); | ||
// expect(squareLogoResult.current).not.toBe(''); | ||
}); | ||
|
||
it('should skip masked cells in corners', () => { | ||
const largeMatrix = Array(21).fill(Array(21).fill(1)); | ||
const { result } = renderHook(() => | ||
useDotsPath({ | ||
...defaultProps, | ||
matrix: largeMatrix, | ||
}), | ||
); | ||
|
||
const points = result.current.split('M').filter(Boolean); | ||
|
||
expect(points.length).toBeLessThan(21 * 21); | ||
}); | ||
|
||
it('should handle empty matrix', () => { | ||
const { result } = renderHook(() => | ||
useDotsPath({ | ||
...defaultProps, | ||
matrix: [], | ||
}), | ||
); | ||
|
||
expect(result.current).toBe(''); | ||
}); | ||
}); |
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,86 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useLogo } from './useLogo'; | ||
|
||
describe('useLogo', () => { | ||
const defaultProps = { | ||
size: 300, | ||
logo: undefined, | ||
logoSize: 60, | ||
logoBackgroundColor: 'white', | ||
logoMargin: 5, | ||
logoBorderRadius: 0, | ||
}; | ||
|
||
it('should render default logo when no logo provided', () => { | ||
const { result } = renderHook(() => useLogo(defaultProps)); | ||
|
||
expect(result.current.props.transform).toContain('translate'); | ||
expect(result.current.type).toBe('g'); | ||
|
||
const imageElement = result.current.props.children[2].props.children; | ||
expect(imageElement.props.href).toContain('data:image/svg+xml'); | ||
expect(imageElement.props.href).toContain(encodeURIComponent('<')); | ||
}); | ||
|
||
it('should handle custom React SVG element', () => { | ||
const customLogo = ( | ||
<svg> | ||
<circle cx="50" cy="50" r="40" /> | ||
</svg> | ||
); | ||
const { result } = renderHook(() => | ||
useLogo({ ...defaultProps, logo: customLogo }), | ||
); | ||
|
||
const imageElement = result.current.props.children[2].props.children; | ||
expect(imageElement.props.href).toContain('data:image/svg+xml'); | ||
expect(imageElement.props.href).toContain(encodeURIComponent('circle')); | ||
}); | ||
|
||
it('should apply correct positioning and sizing', () => { | ||
const { result } = renderHook(() => useLogo(defaultProps)); | ||
|
||
const expectedPosition = (300 - 60 - 5 * 2) / 2; | ||
expect(result.current.props.transform).toBe( | ||
`translate(${expectedPosition}, ${expectedPosition})`, | ||
); | ||
|
||
const backgroundRect = result.current.props.children[1].props.children; | ||
expect(backgroundRect.props.width).toBe(70); | ||
expect(backgroundRect.props.height).toBe(70); | ||
}); | ||
|
||
it('should apply border radius correctly', () => { | ||
const borderRadius = 10; | ||
const { result } = renderHook(() => | ||
useLogo({ ...defaultProps, logoBorderRadius: borderRadius }), | ||
); | ||
|
||
const clipPathRect = | ||
result.current.props.children[0].props.children.props.children; | ||
expect(clipPathRect.props.rx).toBe(borderRadius); | ||
expect(clipPathRect.props.ry).toBe(borderRadius); | ||
|
||
const backgroundRect = result.current.props.children[1].props.children; | ||
expect(backgroundRect.props.rx).toBe(borderRadius); | ||
expect(backgroundRect.props.ry).toBe(borderRadius); | ||
}); | ||
|
||
it('should apply correct background color', () => { | ||
const backgroundColor = '#ff0000'; | ||
const { result } = renderHook(() => | ||
useLogo({ ...defaultProps, logoBackgroundColor: backgroundColor }), | ||
); | ||
|
||
const backgroundRect = result.current.props.children[1].props.children; | ||
expect(backgroundRect.props.fill).toBe(backgroundColor); | ||
}); | ||
|
||
it('should preserve aspect ratio in image', () => { | ||
const { result } = renderHook(() => useLogo(defaultProps)); | ||
|
||
const imageElement = result.current.props.children[2].props.children; | ||
expect(imageElement.props.preserveAspectRatio).toBe('xMidYMid slice'); | ||
}); | ||
}); |
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,14 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { getAddressTokenBalances } from './getAddressTokenBalances'; | ||
|
||
describe('getAddressTokenBalances', () => { | ||
it('should return an empty array for an invalid address', async () => { | ||
const result = await getAddressTokenBalances('invalid-address'); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return an empty array for a null address', async () => { | ||
const result = await getAddressTokenBalances(null); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
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