Skip to content

Commit 868f703

Browse files
committed
Fix integration tests
1 parent 3c9fe7e commit 868f703

File tree

5 files changed

+62
-22
lines changed

5 files changed

+62
-22
lines changed

examples/tests.story.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { storiesOf } from "@storybook/react";
22
import React, { Component, useState } from "react";
33

4+
import { BlockToolbar, InlineToolbar, MetaToolbar } from "../src";
5+
46
import {
57
INLINE_CONTROL,
68
BLOCK_CONTROL,
@@ -10,6 +12,7 @@ import {
1012
} from "./constants/ui";
1113

1214
import EditorWrapper from "./components/EditorWrapper";
15+
import CharCount from "./components/CharCount";
1316

1417
storiesOf("Tests", module)
1518
// Add a decorator rendering story as a component for hooks support.
@@ -180,4 +183,48 @@ storiesOf("Tests", module)
180183
</button>
181184
</>
182185
);
183-
});
186+
})
187+
.add("Integration", () => (
188+
<main>
189+
<p id="integration-editor">Integration tests</p>
190+
<EditorWrapper
191+
id="integration"
192+
ariaDescribedBy="integration-editor"
193+
placeholder="Write here…"
194+
// Makes it easier to write automated tests retrieving the content.
195+
stateSaveInterval={50}
196+
enableHorizontalRule
197+
enableLineBreak
198+
stripPastedStyles={false}
199+
maxListNesting={6}
200+
spellCheck
201+
entityTypes={[
202+
ENTITY_CONTROL.IMAGE,
203+
ENTITY_CONTROL.EMBED,
204+
ENTITY_CONTROL.LINK,
205+
ENTITY_CONTROL.DOCUMENT,
206+
]}
207+
blockTypes={[
208+
BLOCK_CONTROL.HEADER_TWO,
209+
BLOCK_CONTROL.HEADER_THREE,
210+
BLOCK_CONTROL.HEADER_FOUR,
211+
BLOCK_CONTROL.HEADER_FIVE,
212+
BLOCK_CONTROL.UNORDERED_LIST_ITEM,
213+
BLOCK_CONTROL.ORDERED_LIST_ITEM,
214+
]}
215+
inlineStyles={[INLINE_CONTROL.BOLD, INLINE_CONTROL.ITALIC]}
216+
controls={[
217+
{
218+
meta: CharCount,
219+
},
220+
]}
221+
topToolbar={(props) => (
222+
<>
223+
<InlineToolbar defaultToolbar="sticky" {...props} />
224+
<BlockToolbar {...props} />
225+
</>
226+
)}
227+
bottomToolbar={MetaToolbar}
228+
/>
229+
</main>
230+
));

tests/integration/PuppeteerEnvironment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const NodeEnvironment = require("jest-environment-node");
1+
const { TestEnvironment } = require("jest-environment-node");
22
const puppeteer = require("puppeteer");
33
const fs = require("fs");
44
const os = require("os");
@@ -12,7 +12,7 @@ const IS_WATCH = process.argv.includes("--watch");
1212
* Automated end to end integration tests built with Puppeteer.
1313
* See https://facebook.github.io/jest/docs/en/puppeteer.html.
1414
*/
15-
class PuppeteerEnvironment extends NodeEnvironment {
15+
class PuppeteerEnvironment extends TestEnvironment {
1616
constructor(config, options) {
1717
super(config, options);
1818

29 Bytes
Loading

tests/integration/examples.test.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ describe("/storybook/", () => {
88
let page;
99
beforeAll(async () => {
1010
page = await global.BROWSER.newPage();
11-
await page.goto(
12-
`${global.ROOT}?selectedKind=Examples&selectedStory=Wagtail%20features`,
13-
);
11+
await page.goto(`${global.ROOT}?id=tests--integration`);
1412

1513
await page.addScriptTag({ path: require.resolve("axe-core") });
1614
});
@@ -62,7 +60,7 @@ describe("/storybook/", () => {
6260
await page.keyboard.press("ArrowRight");
6361
await page.waitFor(100);
6462
const content = await page.evaluate(() =>
65-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
63+
JSON.parse(window.sessionStorage.getItem("integration:content")),
6664
);
6765
content.blocks.forEach((b) => delete b.key);
6866
expect(content.blocks).toMatchSnapshot();
@@ -72,7 +70,7 @@ describe("/storybook/", () => {
7270
await page.type('[role="textbox"]', "### H3");
7371
await page.waitFor(100);
7472
const content = await page.evaluate(() =>
75-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
73+
JSON.parse(window.sessionStorage.getItem("integration:content")),
7674
);
7775
content.blocks.forEach((b) => delete b.key);
7876
expect(content.blocks).toMatchSnapshot();
@@ -82,7 +80,7 @@ describe("/storybook/", () => {
8280
await page.type('[role="textbox"]', "* UL");
8381
await page.waitFor(100);
8482
const content = await page.evaluate(() =>
85-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
83+
JSON.parse(window.sessionStorage.getItem("integration:content")),
8684
);
8785
content.blocks.forEach((b) => delete b.key);
8886
expect(content.blocks).toMatchSnapshot();
@@ -92,7 +90,7 @@ describe("/storybook/", () => {
9290
await page.type('[role="textbox"]', "---");
9391
await page.waitFor(100);
9492
const content = await page.evaluate(() =>
95-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
93+
JSON.parse(window.sessionStorage.getItem("integration:content")),
9694
);
9795
content.blocks.forEach((b) => delete b.key);
9896
expect(content).toMatchSnapshot();
@@ -107,7 +105,7 @@ describe("/storybook/", () => {
107105
await page.type('[role="textbox"]', "lo");
108106
await page.waitFor(100);
109107
const content = await page.evaluate(() =>
110-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
108+
JSON.parse(window.sessionStorage.getItem("integration:content")),
111109
);
112110
content.blocks.forEach((b) => delete b.key);
113111
expect(content).toMatchSnapshot();
@@ -119,7 +117,7 @@ describe("/storybook/", () => {
119117
await page.keyboard.press("Enter");
120118
await page.waitFor(100);
121119
const content = await page.evaluate(() =>
122-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
120+
JSON.parse(window.sessionStorage.getItem("integration:content")),
123121
);
124122
content.blocks.forEach((b) => delete b.key);
125123
expect(content).toMatchSnapshot();
@@ -137,7 +135,7 @@ describe("/storybook/", () => {
137135
await page.keyboard.press("Enter");
138136
await page.waitFor(100);
139137
const content = await page.evaluate(() =>
140-
JSON.parse(window.sessionStorage.getItem("wagtail:content")),
138+
JSON.parse(window.sessionStorage.getItem("integration:content")),
141139
);
142140
content.blocks.forEach((b) => delete b.key);
143141
expect(content).toMatchSnapshot();

tests/integration/performance.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ describe("performance", () => {
77
});
88

99
it("simple editor", async () => {
10-
await page.goto(
11-
`${global.ROOT}?selectedKind=Draftail&selectedStory=Simple`,
12-
);
10+
await page.goto(`${global.ROOT}?id=draftail--simple`);
1311

1412
await page.type('[role="textbox"]', "Hello");
1513
await page.keyboard.press("Enter");
@@ -26,9 +24,7 @@ describe("performance", () => {
2624

2725
it("markov_draftjs 41 memory", async () => {
2826
jest.setTimeout(20000);
29-
await page.goto(
30-
`${global.ROOT}?selectedKind=Performance&selectedStory=markov_draftjs%2041`,
31-
);
27+
await page.goto(`${global.ROOT}?id=performance--markov_draftjs%2041`);
3228

3329
const heapSize = await page.evaluate(
3430
() => window.performance.memory.usedJSHeapSize,
@@ -39,9 +35,8 @@ describe("performance", () => {
3935

4036
it("markov_draftjs 41 speed", async () => {
4137
jest.setTimeout(20000);
42-
await page.goto(
43-
`${global.ROOT}?selectedKind=Performance&selectedStory=markov_draftjs%2041`,
44-
);
38+
await page.goto(`${global.ROOT}?id=performance--markov-draftjs-41`);
39+
await page.waitForSelector('[data-benchmark="mean"]');
4540

4641
const mean = await page.$eval('[data-benchmark="mean"]', (elt) =>
4742
parseFloat(elt.innerHTML),

0 commit comments

Comments
 (0)