mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 14:59:27 +08:00
fix: test
This commit is contained in:
parent
f3a279d8de
commit
3e9d9f16d6
@ -1,5 +1,5 @@
|
|||||||
import { Button } from '@cherrystudio/ui'
|
import { Button } from '@cherrystudio/ui'
|
||||||
import { memo, useCallback, useMemo, useState } from 'react'
|
import { useCallback, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
@ -20,18 +20,12 @@ const ExpandableText = ({
|
|||||||
setIsExpanded((prev) => !prev)
|
setIsExpanded((prev) => !prev)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const button = useMemo(() => {
|
|
||||||
return (
|
|
||||||
<Button variant="ghost" onClick={toggleExpand} className="self-end">
|
|
||||||
{isExpanded ? t('common.collapse') : t('common.expand')}
|
|
||||||
</Button>
|
|
||||||
)
|
|
||||||
}, [isExpanded, t, toggleExpand])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container ref={ref} style={style} $expanded={isExpanded}>
|
<Container ref={ref} style={style} $expanded={isExpanded}>
|
||||||
<TextContainer $expanded={isExpanded}>{text}</TextContainer>
|
<TextContainer $expanded={isExpanded}>{text}</TextContainer>
|
||||||
{button}
|
<Button variant="ghost" onClick={toggleExpand} className="self-end">
|
||||||
|
{isExpanded ? t('common.collapse') : t('common.expand')}
|
||||||
|
</Button>
|
||||||
</Container>
|
</Container>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -48,4 +42,4 @@ const TextContainer = styled.div<{ $expanded?: boolean }>`
|
|||||||
line-height: ${(props) => (props.$expanded ? 'unset' : '30px')};
|
line-height: ${(props) => (props.$expanded ? 'unset' : '30px')};
|
||||||
`
|
`
|
||||||
|
|
||||||
export default memo(ExpandableText)
|
export default ExpandableText
|
||||||
|
|||||||
@ -12,8 +12,8 @@ vi.mock('react-i18next', () => ({
|
|||||||
|
|
||||||
// Mock ImageToolButton
|
// Mock ImageToolButton
|
||||||
vi.mock('../ImageToolButton', () => ({
|
vi.mock('../ImageToolButton', () => ({
|
||||||
default: vi.fn(({ tooltip, onPress, icon }) => (
|
default: vi.fn(({ tooltip, onClick, icon }) => (
|
||||||
<button type="button" onClick={onPress} role="button" aria-label={tooltip}>
|
<button type="button" onClick={onClick} role="button" aria-label={tooltip}>
|
||||||
{icon}
|
{icon}
|
||||||
</button>
|
</button>
|
||||||
))
|
))
|
||||||
|
|||||||
@ -9,6 +9,15 @@ vi.mock('react-i18next', () => ({
|
|||||||
useTranslation: () => ({ t: (k: string) => k })
|
useTranslation: () => ({ t: (k: string) => k })
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// mock @cherrystudio/ui Button component
|
||||||
|
vi.mock('@cherrystudio/ui', () => ({
|
||||||
|
Button: ({ children, onPress, ...props }: any) => (
|
||||||
|
<button type="button" onClick={onPress} {...props}>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
|
||||||
describe('ExpandableText', () => {
|
describe('ExpandableText', () => {
|
||||||
const TEXT = 'This is a long text for testing.'
|
const TEXT = 'This is a long text for testing.'
|
||||||
|
|
||||||
|
|||||||
@ -120,7 +120,7 @@ const WebviewSearch: FC<WebviewSearchProps> = ({ webviewRef, isWebviewReady, app
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
target.findInPage(text, options)
|
target.findInPage(text, options || {})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('findInPage failed', { error })
|
logger.error('findInPage failed', { error })
|
||||||
window.toast?.error(t('common.error'))
|
window.toast?.error(t('common.error'))
|
||||||
|
|||||||
@ -19,6 +19,15 @@ vi.mock('react-i18next', () => ({
|
|||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// mock @cherrystudio/ui Button component to handle onClick
|
||||||
|
vi.mock('@cherrystudio/ui', () => ({
|
||||||
|
Button: ({ children, onClick, disabled, ...props }: any) => (
|
||||||
|
<button type="button" onClick={onClick} disabled={disabled} {...props}>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
|
||||||
const createWebviewMock = () => {
|
const createWebviewMock = () => {
|
||||||
const listeners = new Map<string, Set<(event: Event & { result?: Electron.FoundInPageResult }) => void>>()
|
const listeners = new Map<string, Set<(event: Event & { result?: Electron.FoundInPageResult }) => void>>()
|
||||||
const findInPageMock = vi.fn()
|
const findInPageMock = vi.fn()
|
||||||
@ -255,7 +264,7 @@ describe('WebviewSearch', () => {
|
|||||||
await user.type(input, 'Cherry')
|
await user.type(input, 'Cherry')
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(findInPageMock).toHaveBeenCalledWith('Cherry', undefined)
|
expect(findInPageMock).toHaveBeenCalledWith('Cherry', {})
|
||||||
})
|
})
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
@ -307,7 +316,7 @@ describe('WebviewSearch', () => {
|
|||||||
await user.type(input, 'Cherry')
|
await user.type(input, 'Cherry')
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(findInPageMock).toHaveBeenCalledWith('Cherry', undefined)
|
expect(findInPageMock).toHaveBeenCalledWith('Cherry', {})
|
||||||
})
|
})
|
||||||
findInPageMock.mockClear()
|
findInPageMock.mockClear()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user