import { render, screen } from "@testing-library/react"; import StoryBody from "../../../../lib/ReactViews/Story/StoryPanel/StoryBody"; describe("StoryBody", function () { it("should include embedded media using iframe tag with allowed sources and without interfering others", function () { const theStory = { id: "some id", title: "test", text: 'Story with video. external-20' }; render(); expect(screen.getByText("Story with video.")).toBeVisible(); const iframes = screen.getAllByTitle("Testing me"); expect(iframes.length).toBe(3); const videos = [ "https://www.youtube.com/embed/1234", "https://www.youtube-nocookie.com/embed/1234", "https://player.vimeo.com/video/1234" ]; videos.forEach((videoSrc, index) => { expect(iframes[index]).toHaveAttribute("src", videoSrc); expect(iframes[index]).toHaveAttribute("width", "560"); expect(iframes[index]).toHaveAttribute("height", "315"); }); expect(screen.getByTitle("external-20")).toBeInTheDocument(); }); it("should exclude embedded media using iframe tag with any forbidden sources", function () { const theStory = { id: "some id", title: "test", text: 'Story with video. ' }; const { container } = render( ); expect(container.querySelector("iframe")).toBeNull(); expect(screen.getByText("Story with video.")).toBeVisible(); }); it("should not add iframe tag if there is no iframe in the story text", function () { const theStory = { id: "some id", title: "test", text: 'Story with video. ' }; const { container } = render( ); const iframes = container.querySelectorAll("iframe"); expect(iframes.length).toBe(0); expect(screen.getByText("Story with video.")).toBeVisible(); }); });