@scm-manager/ui-components 2.28.0 → 2.28.1-20220005-140541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/Breadcrumb.stories.tsx +15 -2
- package/src/Breadcrumb.tsx +38 -14
- package/src/SyntaxHighlighter.stories.tsx +3 -0
- package/src/__snapshots__/storyshots.test.ts.snap +2978 -27
- package/src/markdown/MarkdownView.stories.tsx +7 -4
- package/src/storyshots.test.ts +47 -7
|
@@ -46,8 +46,11 @@ const Spacing = styled.div`
|
|
|
46
46
|
`;
|
|
47
47
|
|
|
48
48
|
storiesOf("MarkdownView", module)
|
|
49
|
-
.addDecorator(
|
|
50
|
-
.addDecorator(
|
|
49
|
+
.addDecorator(story => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>)
|
|
50
|
+
.addDecorator(story => <Spacing>{story()}</Spacing>)
|
|
51
|
+
// Add async parameter, because the tests needs to render async before snapshot is taken so that
|
|
52
|
+
// code fragments get highlighted properly
|
|
53
|
+
.addParameters({ storyshots: { async: true } })
|
|
51
54
|
.add("Default", () => <MarkdownView content={TestPage} skipHtml={false} />)
|
|
52
55
|
.add("Skip Html", () => <MarkdownView content={TestPage} skipHtml={true} />)
|
|
53
56
|
.add("Code without Lang", () => <MarkdownView content={MarkdownWithoutLang} skipHtml={false} />)
|
|
@@ -63,7 +66,7 @@ storiesOf("MarkdownView", module)
|
|
|
63
66
|
const binder = new Binder("custom protocol link renderer");
|
|
64
67
|
binder.bind("markdown-renderer.link.protocol", {
|
|
65
68
|
protocol: "scw",
|
|
66
|
-
renderer: ProtocolLinkRenderer
|
|
69
|
+
renderer: ProtocolLinkRenderer
|
|
67
70
|
} as ProtocolLinkRendererExtension);
|
|
68
71
|
return (
|
|
69
72
|
<BinderContext.Provider value={binder}>
|
|
@@ -75,7 +78,7 @@ storiesOf("MarkdownView", module)
|
|
|
75
78
|
const binder = new Binder("custom protocol link renderer");
|
|
76
79
|
binder.bind("markdown-renderer.link.protocol", {
|
|
77
80
|
protocol: "scw",
|
|
78
|
-
renderer: ProtocolLinkRenderer
|
|
81
|
+
renderer: ProtocolLinkRenderer
|
|
79
82
|
} as ProtocolLinkRendererExtension);
|
|
80
83
|
return (
|
|
81
84
|
<BinderContext.Provider value={binder}>
|
package/src/storyshots.test.ts
CHANGED
|
@@ -24,23 +24,63 @@
|
|
|
24
24
|
|
|
25
25
|
import path from "path";
|
|
26
26
|
import initStoryshots, { snapshotWithOptions } from "@storybook/addon-storyshots";
|
|
27
|
+
import { act, create, ReactTestRenderer } from "react-test-renderer";
|
|
28
|
+
import { StoryContext } from "@storybook/react";
|
|
27
29
|
|
|
28
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
31
|
const createNodeMock = (element: any) => {
|
|
30
32
|
if (element.type === "tr") {
|
|
31
33
|
return {
|
|
32
34
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
33
|
-
querySelector: (
|
|
35
|
+
querySelector: () => {}
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
|
|
40
|
+
async function wait(delay: number) {
|
|
41
|
+
return act(
|
|
42
|
+
() =>
|
|
43
|
+
new Promise(resolve => {
|
|
44
|
+
setTimeout(resolve, delay);
|
|
45
|
+
})
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function runAsyncTest(story: StoryContext) {
|
|
50
|
+
const storyElement = story.render();
|
|
51
|
+
let renderer: ReactTestRenderer | undefined;
|
|
52
|
+
act(() => {
|
|
53
|
+
renderer = create(storyElement);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// For Flow's benefit
|
|
57
|
+
if (!renderer) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Let one render cycle pass before rendering snapshot
|
|
62
|
+
await wait(0);
|
|
63
|
+
expect(renderer).toMatchSnapshot();
|
|
64
|
+
|
|
65
|
+
renderer.unmount();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const syncTest = snapshotWithOptions({
|
|
69
|
+
// @ts-ignore types seems not to match
|
|
70
|
+
createNodeMock
|
|
71
|
+
});
|
|
72
|
+
|
|
38
73
|
initStoryshots({
|
|
74
|
+
asyncJest: true,
|
|
39
75
|
configPath: path.resolve(__dirname, "..", ".storybook"),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
76
|
+
test: ({ story, context, done, ...rest }) => {
|
|
77
|
+
if (story.parameters?.storyshots?.async) {
|
|
78
|
+
runAsyncTest(story).then(done);
|
|
79
|
+
} else {
|
|
80
|
+
syncTest({ story, context, ...rest });
|
|
81
|
+
if (done) {
|
|
82
|
+
done();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
46
86
|
});
|