import { hR as d, R as h, hd as u, b_ as y, b$ as n, c0 as c, hS as g, hT as x } from "./603b75d9.js";
import { loadComps as v } from "./e8e5a2bd.js";
import "react";
import "react-dom";
import "./7699935c.js";
import "./26dac75c.js";
import "./d5bce8af.js";
import "./00883e1f.js";
import "./f0eb9d1f.js";
import "./d91d7adf.js";
import "./23a8bd12.js";
import "./48fb13b8.js";
import "./046c0def.js";
import "./67806ec9.js";
import "./30970d5d.js";
import "./fc161105.js";
import "./f9847c56.js";
import "./3e83ebec.js";
import "./5e877a2d.js";
import "./32abb214.js";
import "./d09c8993.js";
import "./38ce1504.js";
import "./2ce59d2a.js";
import "./f93b9d69.js";
import "./1924a3af.js";
import "./838a2a4e.js";
import "./364198c1.js";
import "./d7f8f8f0.js";
import "./c41c92f6.js";
import "./267ca380.js";
import "./06d051b0.js";
import "./3b47f9d5.js";
import "./42df2f03.js";
import "./75b71678.js";
import "./94ac819c.js";
import "./81ffbd97.js";
import "./7ceea4ac.js";
import "./3566f3e7.js";
import "./94a8eb58.js";
import "./85cc6984.js";
import "./af99c341.js";
import "./383dbbc4.js";
import "./31c877ff.js";
import "./41aba172.js";
import "./81bfe0f9.js";
import "./d9ab1b80.js";
import "./60eb7a4c.js";
import "./52bdf634.js";
import "./cee178c0.js";
import "./2e7b5067.js";
import "./55456d28.js";
import "./447997e0.js";
import "./9a25521a.js";
import "./f64a8554.js";
import "./d50792b8.js";
import "./0cc240d3.js";
import "./00d44232.js";
import "./a4d0e31e.js";
import "./2cdd2fea.js";
import "./0cdeb449.js";
import "./74fa36a6.js";
import "./3d576d10.js";
import "./89ddb817.js";
import "./43832441.js";
import "./f023d901.js";
import "./9a3e93cb.js";
import "./158dca8d.js";
import "./18a95abc.js";
import "./c2be1293.js";
import "./4963ac97.js";
import "./ffcffc16.js";
import "./62f393ec.js";
import "./11b05d65.js";
import "./56edae87.js";
import "./e735e391.js";
import "./140b48ce.js";
import "./f5fb28b1.js";
import "./930af84f.js";
import "./9c5ea6de.js";
import "./7f1b43fa.js";
import "./43b58a96.js";
import "./19a46fb5.js";
import "./98f17e53.js";
import "./794d827a.js";
import "./cf72e8e5.js";
import "./84cede66.js";
import "./3dfed0b7.js";
import "./57f24d28.js";
import "./be662667.js";
import "./8064caf1.js";
import "./d8fd0c14.js";
import "./048c5fdf.js";
import "./2d0ef255.js";
import "./44e33607.js";
import "./2effcf20.js";
import "./6cc9aba1.js";
import "./c873d014.js";
import "./4c7b25f6.js";
import "./8db6cdf1.js";
import "./a64b9c3a.js";
import "./567cf38b.js";
import "./9f5db0d1.js";
import "./aeaf9bba.js";
import "./da47580c.js";
import "./aec4efa8.js";
import "./c7df3849.js";
import "./f091fa82.js";
import "./f52ee168.js";
import "./de2e4e92.js";
import "./bf2ffa97.js";
import "./90e6d3f7.js";
import "./3eacf14a.js";
import "./a353f3e4.js";
import "./a6ed71f1.js";
import "./69cfbcbf.js";
import "./0e668316.js";
import "./42971a23.js";
import "./bf5e4a58.js";
import "./89f08b0b.js";
import "./13a6a41a.js";
import "./a762fbe5.js";
import "./eb70d496.js";
import "./a441195a.js";
import "./9164baee.js";
import "./6db3bdec.js";
import "./0a417d48.js";
import "./ef246ad6.js";
import "./c3d6afd0.js";
import "./c320947b.js";
import "./8fde2cf8.js";
import "./773cc29a.js";
import "./425a28f6.js";
import "./7030eb81.js";
import "./eb1bbe08.js";
import "./5e74bf99.js";
import "./f1dd0ef6.js";
import "./82e5befc.js";
import "./2ea58d20.js";
import "./e303a972.js";
import "./379c092e.js";
import "./bf5d5efa.js";
import "./0f379ce8.js";
import "./e1018db0.js";
import "./e7aef1c7.js";
import "./1fadbfa9.js";
import "./1e933919.js";
import "./e00ea3ee.js";
import "./8e1169f3.js";
import "./7358332b.js";
import "./c236c7a3.js";
import "./6d60fff6.js";
import "./b65cd26c.js";
import "./ca0a47e8.js";
import "./1774f380.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);
    });
  });
});
