diff --git a/app/components/post_attachment_opengraph/__snapshots__/post_attachment_opengraph.test.js.snap b/app/components/post_attachment_opengraph/__snapshots__/post_attachment_opengraph.test.js.snap index 0ce4b92a8..d311f2d64 100644 --- a/app/components/post_attachment_opengraph/__snapshots__/post_attachment_opengraph.test.js.snap +++ b/app/components/post_attachment_opengraph/__snapshots__/post_attachment_opengraph.test.js.snap @@ -298,3 +298,77 @@ exports[`PostAttachmentOpenGraph should match state and snapshot, on renderImage `; + +exports[`PostAttachmentOpenGraph should match state and snapshot, on renderImage 3`] = ` + + + + Mattermost + + + + + + Title + + + + +`; diff --git a/app/components/post_attachment_opengraph/post_attachment_opengraph.js b/app/components/post_attachment_opengraph/post_attachment_opengraph.js index 27b71351b..244e8cdf2 100644 --- a/app/components/post_attachment_opengraph/post_attachment_opengraph.js +++ b/app/components/post_attachment_opengraph/post_attachment_opengraph.js @@ -15,7 +15,7 @@ import {generateId} from '@utils/file'; import {openGalleryAtIndex, calculateDimensions} from '@utils/images'; import {getNearestPoint} from '@utils/opengraph'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; -import {tryOpenURL} from '@utils/url'; +import {tryOpenURL, isValidUrl} from '@utils/url'; const MAX_IMAGE_HEIGHT = 150; const VIEWPORT_IMAGE_OFFSET = 93; @@ -93,7 +93,7 @@ export default class PostAttachmentOpenGraph extends PureComponent { } return { - hasImage: true, + hasImage: Boolean(isValidUrl(imageUrl) && (ogImage.width && ogImage.height)), ...dimensions, openGraphImageUrl: imageUrl, }; diff --git a/app/components/post_attachment_opengraph/post_attachment_opengraph.test.js b/app/components/post_attachment_opengraph/post_attachment_opengraph.test.js index 0c2c86f1e..1f3e9c2e2 100644 --- a/app/components/post_attachment_opengraph/post_attachment_opengraph.test.js +++ b/app/components/post_attachment_opengraph/post_attachment_opengraph.test.js @@ -104,6 +104,22 @@ describe('PostAttachmentOpenGraph', () => { expect(wrapper.find(TouchableWithFeedback).exists()).toEqual(true); }); + test('should match state and snapshot, on renderImage', () => { + const images = [{height: 440, width: 1200, url: '%REACT_APP_WEBSITE_BANNER%'}]; + const openGraphDataWithImage = {...openGraphData, images}; + const wrapper = shallow( + , + ); + + expect(wrapper.getElement()).toMatchSnapshot(); + expect(wrapper.state('hasImage')).toEqual(false); + expect(wrapper.find(FastImage).exists()).toEqual(false); + expect(wrapper.find(TouchableWithFeedback).exists()).toEqual(true); + }); + test('should match state and snapshot, on renderDescription', () => { const wrapper = shallow(