Skip to content

Commit

Permalink
test(Ellipsis): 单测补充 (ant-design#6792)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang_cq committed Dec 13, 2024
1 parent 10cceed commit 13b2c06
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/components/ellipsis/tests/ellipsis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('Ellipsis', () => {
const that = this as HTMLElement
const charLen = (that.textContent || '').length || 1
const rows = Math.ceil(charLen / 30)
return rows * lineHeight
const styleLineHeight = parseFloat(that.style.lineHeight)
return Math.round(rows * (styleLineHeight || lineHeight))
},
},
})
Expand Down Expand Up @@ -132,4 +133,30 @@ describe('Ellipsis', () => {
fireEvent.click(getByText('expand'))
expect(getByText('collapse')).toBeInTheDocument()
})

test('non-integer line height', () => {
const rows = 2
const lineHeight = '16.4px'

const { getByTestId } = render(
<React.Fragment>
<Ellipsis
rows={rows}
style={{ lineHeight }}
content={content}
data-testid='ellipsis'
/>
<div style={{ lineHeight }} data-testid='maxheight'>
{content}
</div>
</React.Fragment>
)

const { offsetHeight } = getByTestId('ellipsis') || {}
const { offsetHeight: maxheight } = getByTestId('maxheight') || {}
const rowsHeight = Math.round(parseFloat(lineHeight) * rows)
const expectHeight = Math.min(rowsHeight, maxheight)

expect(offsetHeight).toBe(expectHeight)
})
})

0 comments on commit 13b2c06

Please sign in to comment.