import { hb as d, R as h, gn as u, cb as y, cc as n, cd as c, hc as g, hd as x } from "./56c67d3b.js";
import { loadComps as v } from "./a3054d7f.js";
import "react";
import "react-dom";
import "./590a55aa.js";
import "./d08f5278.js";
import "./838c28e6.js";
import "./30970d5d.js";
import "./f146bb7b.js";
import "./85fb0bcf.js";
import "./d9000f33.js";
import "./4cac7a5d.js";
import "./381f866e.js";
import "./3aa1b662.js";
import "./37fe8ff5.js";
import "./80ec0617.js";
import "./28c8044f.js";
import "./14f3cb46.js";
import "./f6893ddd.js";
import "./c57f24d6.js";
import "./5f1c844f.js";
import "./38d8a151.js";
import "./be290860.js";
import "./3ebea0a4.js";
import "./58aaa138.js";
import "./2ca8b68a.js";
import "./68aff0fe.js";
import "./a035a58e.js";
import "./6bf41a33.js";
import "./fb53fa7f.js";
import "./d55ed660.js";
import "./e2effbbc.js";
import "./4824c2dd.js";
import "./e216cc9c.js";
import "./5608d4fb.js";
import "./9705a5f9.js";
import "./a596fb06.js";
import "./71259289.js";
import "./41a09f5e.js";
import "./01daa15d.js";
import "./148baa10.js";
import "./5aa5c532.js";
import "./04cb63ea.js";
import "./3a7caf73.js";
import "./8ee6bfe5.js";
import "./21a6c95f.js";
import "./cd6ad4ce.js";
import "./5f75d4d9.js";
import "./9574b978.js";
import "./01e3e710.js";
import "./b6f8d60c.js";
import "./f52ee168.js";
import "./de2e4e92.js";
import "./bf2ffa97.js";
import "./90e6d3f7.js";
import "./3eacf14a.js";
import "./a353f3e4.js";
import "./a6ed71f1.js";
import "./a6057d6a.js";
import "./b6466fb6.js";
import "./8e561439.js";
import "./40fca083.js";
import "./4fe224ad.js";
import "./270283bf.js";
import "./46847de0.js";
import "./642e506a.js";
import "./b2ce40f6.js";
import "./ede1fc51.js";
import "./ef27b737.js";
import "./0a417d48.js";
import "./447d2efa.js";
import "./cf64eb1a.js";
import "./c320947b.js";
import "./99912daf.js";
import "./cd2a73b9.js";
import "./1428e5db.js";
import "./b10db7f7.js";
import "./3531d6d7.js";
import "./f570c66c.js";
import "./4afc263f.js";
import "./c1ef149c.js";
import "./7780104f.js";
import "./cf0c467c.js";
import "./9a1bcddc.js";
import "./145a5620.js";
import "./6d0ad852.js";
import "./967203ef.js";
import "./4a69de7b.js";
import "./04ffe6b4.js";
import "./c2318700.js";
import "./b8c81969.js";
import "./b5c6a90f.js";
import "./41ae39f7.js";
import "./3fa53843.js";
import "./a7e48161.js";
import "./ad48ffa2.js";
import "./97e5fa86.js";
import "./0845e032.js";
const T = {
  ui: {
    items: {
      "2e2d4bf2": {
        compType: "module",
        comp: {
          appId: "123",
          events: [{
            name: "event1",
            handler: {
              compType: "executeComp",
              comp: {
                name: "outerInput",
                methodName: "setValue",
                params: [{
                  compType: "string",
                  comp: "event1_triggered",
                  name: "value"
                }]
              }
            }
          }]
        },
        name: "module1"
      },
      "2bb084bf": {
        compType: "input",
        comp: {
          value: ""
        },
        name: "outerInput"
      }
    }
  },
  queries: [{
    compType: "js",
    comp: {
      script: "return 3;"
    },
    id: "dievziawwqy72gszoa42i6m8",
    name: "jsQuery3",
    triggerType: "manual"
  }, {
    compType: "js",
    comp: {
      script: "return 3 + a;"
    },
    id: "dievziawwqy72gszoa42i6m9",
    name: "jsQuery4",
    triggerType: "manual"
  }]
}, f = {
  ui: {
    compType: "module",
    comp: {
      methods: [{
        name: "method1",
        action: {
          compType: "executeComp",
          comp: {
            name: "input1",
            methodName: "setValue",
            params: [{
              compType: "string",
              comp: "hello method1",
              name: "value"
            }]
          }
        }
      }, {
        name: "method2",
        params: [{
          name: "param1",
          type: "string"
        }],
        action: {
          compType: "executeComp",
          comp: {
            name: "input1",
            methodName: "setValue",
            params: [{
              compType: "string",
              comp: "hello {{param1}}",
              name: "value"
            }]
          }
        }
      }],
      events: {
        list: [{
          name: "event1",
          description: ""
        }, {
          name: "event2",
          description: ""
        }],
        onEvent: [{
          name: "event1",
          handler: {
            compType: "executeComp",
            comp: {
              name: "input1",
              methodName: "setValue",
              params: [{
                compType: "string",
                comp: "from_event1",
                name: "value"
              }]
            }
          }
        }]
      },
      io: {
        inputs: [{
          name: "inQuery",
          description: "",
          type: "query"
        }, {
          name: "inNum",
          description: "",
          type: "number"
        }, {
          name: "inString",
          description: "",
          type: "string",
          defaultValue: {
            compType: "string",
            comp: "default_value"
          },
          test: {
            compType: "string",
            comp: "test_value"
          }
        }],
        outputs: [{
          description: "",
          value: "{{input1.value}}",
          name: "out"
        }]
      },
      containerSize: {
        height: 20,
        width: 24
      },
      container: {
        items: {
          "2010af2a": {
            compType: "input",
            comp: {
              value: "hello"
            },
            name: "input1"
          },
          e97d3df7: {
            compType: "text",
            comp: {
              text: "inNum:{{inNum.value}}"
            },
            name: "text1"
          },
          e97d3df8: {
            compType: "text",
            comp: {
              text: "inString:{{inString.value}}"
            },
            name: "text2"
          },
          e97d3df9: {
            compType: "text",
            comp: {
              text: "inQueryData:{{inQuery.data}}"
            },
            name: "text3"
          }
        }
      }
    }
  },
  queries: [{
    compType: "js",
    comp: {
      script: "return 1 + 1"
    },
    id: "dievziawwqy72gszoa42i6m7",
    name: "jsQuery",
    triggerType: "manual",
    onEvent: [{
      name: "success",
      handler: {
        compType: "executeComp",
        comp: {
          name: "input1",
          methodName: "setValue",
          params: [{
            compType: "string",
            comp: "hello success",
            name: "value"
          }]
        }
      }
    }]
  }, {
    compType: "js",
    comp: {
      script: `inQuery.run({a: 10}); 
input1.setValue('hello input query'); return 'ok'`
    },
    id: "dievziawwqy72gszoa42i6m8",
    name: "jsQuery2",
    triggerType: "manual"
  }, {
    compType: "js",
    comp: {
      script: "event1.trigger();"
    },
    id: "dievziawwqy72gszoa42i6m9",
    name: "jsQuery3",
    triggerType: "manual"
  }]
};
function r(o) {
  const e = d({
    Comp: h,
    initialValue: T,
    reduceContext: {
      readOnly: !1,
      applicationId: "123",
      moduleDSL: {
        123: f
      },
      parentApplicationPath: []
    }
  });
  if (!e)
    throw new Error();
  const t = (a, s) => a.children.ui.getAllCompItems()[s].children.comp, i = (a) => t(e.comp, a), p = () => i("2e2d4bf2"), m = (a) => {
    const l = p().moduleRootComp;
    return t(l, a);
  };
  e.init().then(() => {
    p().dispatch(u({
      type: "init"
    }, !1)), setTimeout(() => {
      o({
        root: () => e.comp,
        moduleRoot: () => p().moduleRootComp,
        module: p,
        moduleOutputNodes: () => p().getOutputNodes(),
        input: () => m("2010af2a"),
        inputValue: () => m("2010af2a").children.value.getView().value,
        text1: () => m("e97d3df7"),
        text2: () => m("e97d3df8"),
        text3: () => m("e97d3df9"),
        outerInputValue: () => i("2bb084bf").children.value.getView().value
      });
    });
  });
}
beforeAll(async () => {
  await v();
});
describe("module comp", () => {
  test("init module to ready", (o) => {
    r(({
      module: e,
      text1: t,
      text2: i
    }) => {
      expect(Object.keys(e().getOutputNodes())).toStrictEqual(["out"]), expect(e().exposingValues.out).toBe("hello"), expect(Object.keys(e().children.inputs.getInputNodes())).toStrictEqual([]), expect(t().children.text.getView().value).toBe("inNum:"), e().children.inputs.children.inNum.dispatchChangeValueAction(1), expect(t().children.text.getView().value).toBe("inNum:1"), expect(Object.keys(e().children.inputs.getInputNodes())).toStrictEqual(["inNum"]), expect(i().children.text.getView().value).toBe("inString:default_value"), e().children.inputs.children.inString.dispatchChangeValueAction("hello"), expect(i().children.text.getView().value).toBe("inString:hello"), expect(Object.keys(e().children.inputs.getInputNodes())).toStrictEqual(["inNum", "inString"]), o();
    });
  }), test("change value in module", (o) => {
    r(({
      input: e,
      inputValue: t
    }) => {
      expect(t()).toBe("hello"), e().children.value.dispatchChangeValueAction("world"), expect(t()).toBe("world"), y(e().children.value.dispatch, e().children.value.changeValueAction("hello world"), {
        autoHandleAfterReduce: !0
      }).then(() => {
        expect(t()).toBe("hello world"), o();
      });
    });
  }), test("exec query in module", (o) => {
    r(({
      moduleRoot: e,
      module: t,
      inputValue: i
    }) => {
      expect(t().exposingValues.out).toBe("hello"), e().dispatch(n("jsQuery", c({}))), setTimeout(() => {
        expect(i()).toBe("hello success"), expect(t().exposingValues.out).toBe("hello success"), o();
      }, 300);
    });
  }), test("input query data", (o) => {
    r(({
      text3: e,
      module: t,
      root: i,
      inputValue: p
    }) => {
      expect(e().children.text.getView().value).toBe("inQueryData:"), t().children.inputs.children.inQuery.dispatchChangeValueAction({
        value: "jsQuery3"
      }), expect(Object.keys(t().children.inputs.getInputNodes())).toStrictEqual(["inQuery"]), expect(e().children.text.getView().value).toBe("inQueryData:"), i().dispatch(n("jsQuery3", c({}))), setTimeout(() => {
        expect(e().children.text.getView().value).toBe("inQueryData:3"), o();
      }, 1e3);
    });
  }), test("exec input query", (o) => {
    r(({
      text3: e,
      module: t,
      moduleRoot: i,
      inputValue: p
    }) => {
      expect(e().children.text.getView().value).toBe("inQueryData:"), t().children.inputs.children.inQuery.dispatchChangeValueAction({
        value: "jsQuery4"
      }), expect(Object.keys(t().children.inputs.getInputNodes())).toStrictEqual(["inQuery"]), expect(e().children.text.getView().value).toBe("inQueryData:"), i().dispatch(n("jsQuery2", c({}))), setTimeout(() => {
        expect(p()).toBe("hello input query"), expect(e().children.text.getView().value).toBe("inQueryData:13"), o();
      }, 1e3);
    });
  }), test("exec methods", (o) => {
    r(({
      root: e,
      inputValue: t
    }) => {
      const i = e().nameAndExposingInfo();
      expect(Object.keys(i.module1.methods)).toStrictEqual(["method1", "method2"]), e().dispatch(n("module1", u({
        type: "execute",
        methodName: "method1",
        params: []
      }, !1))), setTimeout(() => {
        expect(t()).toBe("hello method1"), o();
      }, 2e3);
    });
  }), test("exec methods with params", (o) => {
    r(({
      root: e,
      inputValue: t
    }) => {
      const i = e().nameAndExposingInfo();
      expect(Object.keys(i.module1.methods)).toStrictEqual(["method1", "method2"]), e().dispatch(n("module1", u({
        type: "execute",
        methodName: "method2",
        params: ["Lucy"]
      }, !1))), setTimeout(() => {
        expect(t()).toBe("hello Lucy"), o();
      }, 2e3);
    });
  }), test("trigger events by event", (o) => {
    r(({
      root: e,
      text3: t,
      module: i,
      moduleRoot: p,
      outerInputValue: m
    }) => {
      expect(m()).toBe(""), p().dispatch(n(x, g("event1"))), setTimeout(() => {
        expect(m()).toBe("event1_triggered"), o();
      });
    });
  }), test("trigger events by js query", (o) => {
    r(({
      root: e,
      text3: t,
      module: i,
      moduleRoot: p,
      outerInputValue: m
    }) => {
      expect(m()).toBe(""), p().dispatch(n("jsQuery3", c({}))), setTimeout(() => {
        expect(m()).toBe("event1_triggered"), o();
      }, 1e3);
    });
  });
});
