Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed Aug 30, 2021
1 parent f1a9c0d commit 667ed3e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/LinkPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export const LinkPreview = React.memo(
}

const renderImageNode = (image: PreviewDataImage) => {
// aspectRatio shouldn't be undefined, just an additional check
/* istanbul ignore next */
const ar = aspectRatio ?? 1

return oneOf(
renderImage,
<Image
Expand All @@ -130,14 +134,14 @@ export const LinkPreview = React.memo(
source={{ uri: image.url }}
style={StyleSheet.flatten([
styles.image,
(aspectRatio ?? 1) < 1
ar < 1
? {
height: containerWidth,
minWidth: 170,
width: containerWidth * (aspectRatio ?? 1),
width: containerWidth * ar,
}
: {
height: containerWidth / (aspectRatio ?? 1),
height: containerWidth / ar,
maxHeight: containerWidth,
width: containerWidth,
},
Expand Down
21 changes: 21 additions & 0 deletions src/__tests__/LinkPreview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ describe('link preview', () => {
expect(headerNode).toBeDefined()
})

it('renders vertical image node', async () => {
expect.assertions(1)
const link = 'https://dummyimage.com/300x800/000/fff'
const { getByRole, getByText } = render(
<LinkPreview
previewData={{
image: {
height: 800,
url: link,
width: 300,
},
link,
}}
text={link}
/>
)
await waitFor(() => getByText(link))
const image = getByRole('image')
expect(image.props).toHaveProperty('style.height', 0)
})

it('responses to the layout event change', async () => {
expect.assertions(1)
const link = 'https://github.com/flyerhq/'
Expand Down

0 comments on commit 667ed3e

Please sign in to comment.