aboutsummaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/index.test.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-04-21 10:47:47 -0300
committerSebastian <sebasjm@gmail.com>2023-04-21 10:47:47 -0300
commitf470f167e32d8f7775ad994f09afb1d353b0b300 (patch)
tree3a1f2a040bb09d6639c81436b90b416fb8044f91 /packages/anastasis-webui/src/index.test.ts
parent6dcc488a2c8fd681941e5d3b62bb04af7669888e (diff)
downloadwallet-core-f470f167e32d8f7775ad994f09afb1d353b0b300.tar.xz
integrate anastasis to the web-utils testing api
Diffstat (limited to 'packages/anastasis-webui/src/index.test.ts')
-rw-r--r--packages/anastasis-webui/src/index.test.ts74
1 files changed, 53 insertions, 21 deletions
diff --git a/packages/anastasis-webui/src/index.test.ts b/packages/anastasis-webui/src/index.test.ts
index 572ce4a46..f5873f540 100644
--- a/packages/anastasis-webui/src/index.test.ts
+++ b/packages/anastasis-webui/src/index.test.ts
@@ -19,31 +19,63 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
import { setupI18n } from "@gnu-taler/taler-util";
-import { renderNodeOrBrowser } from "./test-utils.js";
-import * as pages from "./pages/home/index.storiesNo.js";
+import { parseGroupImport, tests } from "@gnu-taler/web-util/lib/index.browser";
+import * as pages from "./pages/home/index.stories.js";
+import { ComponentChildren, VNode, h as create } from "preact";
+import { AnastasisProvider } from "./context/anastasis.js";
+import { AnastasisReducerApi } from "./hooks/use-anastasis-reducer.js";
+import { ReducerState } from "@gnu-taler/anastasis-core";
setupI18n("en", { en: {} });
-function testThisStory(key: string, st: any): any {
- describe.skip(`render examples for ${key}`, () => {
- Object.keys(st).forEach((k) => {
- const Component = (st as any)[k];
- if (k === "default" || !Component) return;
-
- it(`example: ${k}`, () => {
- renderNodeOrBrowser(Component, Component.args);
+describe("All the examples:", () => {
+ const cms = parseGroupImport({ pages });
+ cms.forEach((group) => {
+ describe(`Example for group "${group.title}":`, () => {
+ group.list.forEach((component) => {
+ describe(`Component ${component.name}:`, () => {
+ component.examples.forEach((example) => {
+ it(`should render example: ${example.name}`, () => {
+ tests.renderUI(example.render, DefaultTestingContext);
+ });
+ });
+ });
});
});
});
-}
-
-describe.skip("render every storybook example", () => {
- Object.entries(pages).forEach(function testAll([key, value]) {
- const st: any = value;
- if (Array.isArray(st.default)) {
- st.default.forEach(testAll);
- } else {
- testThisStory(key, st);
- }
- });
});
+
+const noop = async (): Promise<void> => {
+ return;
+};
+
+function DefaultTestingContext({
+ children,
+ ...rest
+}: {
+ children: ComponentChildren;
+}): VNode {
+ //some UI example can specify the state of the reducer
+ const currentReducerState = rest as ReducerState;
+ const value: AnastasisReducerApi = {
+ currentReducerState,
+ discoverMore: noop,
+ discoverStart: noop,
+ discoveryState: {
+ state: "finished",
+ },
+ currentError: undefined,
+ back: noop,
+ dismissError: noop,
+ reset: noop,
+ runTransaction: noop,
+ startBackup: noop,
+ startRecover: noop,
+ transition: noop,
+ exportState: () => {
+ return "{}";
+ },
+ importState: noop,
+ };
+ return create(AnastasisProvider, { value, children });
+}