Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mwu2018 committed Aug 17, 2023
1 parent bf7181e commit 83cb81f
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions test/ReactViews/Story/StoryPanel/StoryBodySpec.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import React from "react";
import StoryBody from "../../../../lib/ReactViews/Story/StoryPanel/StoryBody";
import { act } from "react-dom/test-utils";
import TestRenderer, { ReactTestInstance, create } from "react-test-renderer";
import Box from "../../../../lib/Styled/Box";
import { exp } from "protomaps";
import {
ReactTestInstance,
ReactTestRenderer,
create
} from "react-test-renderer";

describe("StoryBody", function () {
let testRenderer: ReactTestRenderer;

it("should include embedded video using allowed tag and ignore unallowed attributes", function () {
const theStory = {
id: "some id",
title: "test",
text: 'Story with video. <iframe title="Special Title" width="560" height="315" src="https://some.video.link"></iframe>'
};

let testRenderer: ReturnType<typeof create> = TestRenderer.create(
<StoryBody isCollapsed={false} story={theStory} />
);

act(() => {
testRenderer = TestRenderer.create(
<StoryBody isCollapsed={false} story={theStory} />
);
testRenderer = create(<StoryBody isCollapsed={false} story={theStory} />);
});

const storyBody = testRenderer.root.findAllByType(StoryBody);
Expand All @@ -33,10 +31,11 @@ describe("StoryBody", function () {
).children[0] as ReactTestInstance
).children[0] as ReactTestInstance;

const theIframeInstance = theInstance.children[1] as ReactTestInstance;

expect(theInstance.children.length === 2);

expect(theInstance.children[0] as string).toEqual("Story with video. ");

const theIframeInstance = theInstance.children[1] as ReactTestInstance;
expect(theIframeInstance.type).toBe("iframe");
expect(theIframeInstance.props.title).toBe(undefined);
expect(theIframeInstance.props.src).toBe("https://some.video.link");
Expand All @@ -51,14 +50,8 @@ describe("StoryBody", function () {
text: 'Story with video. <iframe2 width="560" height="315" src="https://some.video.link"></iframe2>'
};

let testRenderer: ReturnType<typeof create> = TestRenderer.create(
<StoryBody isCollapsed={false} story={theStory} />
);

act(() => {
testRenderer = TestRenderer.create(
<StoryBody isCollapsed={false} story={theStory} />
);
testRenderer = create(<StoryBody isCollapsed={false} story={theStory} />);
});

const storyBody = testRenderer.root.findAllByType(StoryBody);
Expand Down

0 comments on commit 83cb81f

Please sign in to comment.