Skip to content

Commit

Permalink
fix(chat): every second video has not been displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
goooseman committed Jun 16, 2020
1 parent 0763403 commit 390f1fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,16 @@ describe("Youtube", () => {
);
expect(await findByLabelText("Youtube player")).toBeInTheDocument();
});

it("should show youtube video for two messages in a row", async () => {
const textWithYoutube =
"Watch it: https://www.youtube.com/watch?v=BMUiFMZr7vk!";
const { findAllByLabelText } = render(
<>
<ChatMessageContainer {...defaultMessage} text={textWithYoutube} />
<ChatMessageContainer {...defaultMessage} text={textWithYoutube} />
</>
);
expect(await findAllByLabelText("Youtube player")).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ChatMessageContainerState {
const linkRegexp = /(https?:\/\/[\w-\.\/\:\?\=\&]+)/gi;
const imageContentTypeRegexp = /^image\//;
// https://gist.github.com/afeld/1254889
const youtubeIdRegexp = /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/g;
const youtubeIdRegexp = /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/;

class ChatMessageContainer extends PureComponent<
ChatMessageContainerProps,
Expand Down Expand Up @@ -91,7 +91,7 @@ class ChatMessageContainer extends PureComponent<
};

private getYoutubeId = (link: string): string | undefined => {
const match = youtubeIdRegexp.exec(link);
const match = link.match(youtubeIdRegexp);
return match ? match[5] : undefined;
};

Expand Down

0 comments on commit 390f1fa

Please sign in to comment.