Skip to content

Commit

Permalink
test: update testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Apr 16, 2024
1 parent bb866f1 commit ac64c95
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import React, {
} from 'react'
import { NativeProps, withNativeProps } from '../../utils/native-props'
import { usePropsValue } from '../../utils/use-props-value'
import { mergeProps } from '../../utils/with-default-props'
import { mergeProp, mergeProps } from '../../utils/with-default-props'
import Popup, { PopupProps } from '../popup'
import { defaultPopupBaseProps } from '../popup/popup-base-props'
import Item, { ItemChildrenWrap } from './item'
Expand Down Expand Up @@ -100,11 +100,12 @@ const Dropdown = forwardRef<DropdownRef, PropsWithChildren<DropdownProps>>(
child.props.onClick?.(event)
},
active: child.key === value,
arrow:
child.props.arrow ||
child.props.arrowIcon ||
props.arrow ||
arrowIcon: mergeProp(
child.props.arrowIcon,
child.props.arrow,
props.arrowIcon,
props.arrow
),
}
items.push(child)
if (child.props.forceRender) popupForceRender = true
Expand Down
4 changes: 2 additions & 2 deletions src/components/dropdown/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const defaultProps = {

const Item: FC<DropdownItemProps> = props => {
const { dropdown: componentConfig = {} } = useConfig()
const { active, arrowIcon, arrow, highlight, onClick, title } = mergeProps(
const { active, arrowIcon, highlight, onClick, title } = mergeProps(
defaultProps,
componentConfig,
props
Expand All @@ -51,7 +51,7 @@ const Item: FC<DropdownItemProps> = props => {
[`${classPrefix}-title-arrow-active`]: active,
})}
>
{arrow || arrowIcon}
{arrowIcon}
</span>
</div>
</div>
Expand Down
43 changes: 43 additions & 0 deletions src/components/dropdown/tests/dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,47 @@ describe('Dropdown', () => {
fireEvent.click(screen.getByText('sorter'))
expect(screen.getByText('click2'))
})

describe('arrow', () => {
it('Dropdown - arrow', () => {
render(
<Dropdown arrow='little'>
<Dropdown.Item title='sorter' key='sorter' />
</Dropdown>
)
expect(screen.getByText('little')).toBeVisible()
})

it('Dropdown - arrowIcon', () => {
render(
<Dropdown arrowIcon='bamboo' arrow='little'>
<Dropdown.Item title='sorter' key='sorter' />
</Dropdown>
)
expect(screen.getByText('bamboo')).toBeVisible()
})

it('Dropdown.Item - arrow', () => {
render(
<Dropdown arrowIcon='ignore' arrow='ignore'>
<Dropdown.Item title='sorter' key='sorter' arrow='little' />
</Dropdown>
)
expect(screen.getByText('little')).toBeVisible()
})

it('Dropdown.Item - arrowIcon', () => {
render(
<Dropdown arrowIcon='ignore' arrow='ignore'>
<Dropdown.Item
title='sorter'
key='sorter'
arrow='little'
arrowIcon='bamboo'
/>
</Dropdown>
)
expect(screen.getByText('bamboo')).toBeVisible()
})
})
})

0 comments on commit ac64c95

Please sign in to comment.