Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed May 24, 2021
1 parent 6d58e40 commit 20f9921
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@flyerhq/react-native-keyboard-accessory-view": "^2.2.0",
"@flyerhq/react-native-link-preview": "^1.3.0",
"@flyerhq/react-native-link-preview": "^1.3.1",
"dayjs": "^1.10.4",
"react-native-image-viewing": "^0.2.0",
"react-native-parsed-text": "^0.0.22"
Expand Down
8 changes: 6 additions & 2 deletions src/components/TextMessage/TextMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export const TextMessage = ({
onPreviewDataFetched?.({ message, previewData: data })
}

const handleUrlPress = (url: string) => Linking.openURL(url)
const handleUrlPress = (url: string) => {
const uri = url.toLowerCase().startsWith('http') ? url : `https://${url}`

Linking.openURL(uri)
}

const renderPreviewDescription = (description: string) => {
return (
Expand All @@ -62,11 +66,11 @@ export const TextMessage = ({
parse={[
{
onPress: handleUrlPress,
pattern: REGEX_LINK,
style: StyleSheet.flatten([
text,
{ textDecorationLine: 'underline' },
]),
type: 'url',
},
]}
style={text}
Expand Down
32 changes: 32 additions & 0 deletions src/components/TextMessage/__tests__/TextMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,36 @@ describe('text message', () => {
getPreviewDataMock.mockRestore()
openUrlMock.mockRestore()
})

it('renders preview image without https and handles link press', async () => {
expect.assertions(2)
const link = 'github.com/flyerhq/'
const getPreviewDataMock = jest
.spyOn(utils, 'getPreviewData')
.mockResolvedValue({
description: 'description',
image: {
height: 460,
url: 'https://avatars2.githubusercontent.com/u/59206044',
width: 460,
},
link,
title: 'title',
})
const openUrlMock = jest.spyOn(Linking, 'openURL')
const { getByRole, getByText } = render(
<TextMessage
message={{ ...textMessage, text: link }}
messageWidth={440}
/>
)
await waitFor(() => getByRole('image'))
const image = getByRole('image')
expect(image).toBeDefined()
const text = getByText(link)
fireEvent.press(text)
expect(openUrlMock).toHaveBeenCalledWith('https://' + link)
getPreviewDataMock.mockRestore()
openUrlMock.mockRestore()
})
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,10 @@
resolved "https://registry.yarnpkg.com/@flyerhq/react-native-keyboard-accessory-view/-/react-native-keyboard-accessory-view-2.2.0.tgz#b9aa613d10541ff0a8a4984ee16ddb5627b75496"
integrity sha512-6tBsrLXJ6u2ChjVAmbMMiSJmLOQJ7aneroS8HTUzPhefBbZXKKODQjmZ+pVF2tXmwuZr+CjZSzOQrfKXeXd68A==

"@flyerhq/react-native-link-preview@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@flyerhq/react-native-link-preview/-/react-native-link-preview-1.3.0.tgz#c54dd41861a07ef8e5c69d5dcd9b3ccfd77178ca"
integrity sha512-nQgmYbfyfFkD2pJMe3EqtYiHMcDYA8gZ9pevhXZ16Stn1EwWvd7s14bd9h2B63g67TFoyVr/fiQrbH0rm8dryA==
"@flyerhq/react-native-link-preview@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@flyerhq/react-native-link-preview/-/react-native-link-preview-1.3.1.tgz#620c5405ce3b51084673b963125e65db8fb92c0b"
integrity sha512-b6kExHnWt4Shwbgtv11MClVFl1v46RDciS/fAv3+Aw8RVbk12HgMkCDLGbXCcYpXAzp3iiTqtAyUHQOj70/Qag==
dependencies:
html-entities "^2.3.2"

Expand Down

0 comments on commit 20f9921

Please sign in to comment.