| 90 | |
| 91 | |
| 92 | async def test_script_from_src(display: DisplayFixture): |
| 93 | incr_src_id = Ref() |
| 94 | file_name_template = "__some_js_script_{src_id}__.js" |
| 95 | |
| 96 | @component |
| 97 | def HasScript(): |
| 98 | src_id, incr_src_id.current = use_counter(0) |
| 99 | if src_id == 0: |
| 100 | # on initial display we haven't added the file yet. |
| 101 | return html.div() |
| 102 | else: |
| 103 | return html.div( |
| 104 | html.div({"id": "run-count", "data_value": 0}), |
| 105 | html.script( |
| 106 | { |
| 107 | "src": f"/_reactpy/modules/{file_name_template.format(src_id=src_id)}" |
| 108 | } |
| 109 | ), |
| 110 | ) |
| 111 | |
| 112 | await display.show(HasScript) |
| 113 | |
| 114 | for i in range(1, 4): |
| 115 | script_file = ( |
| 116 | config.REACTPY_WEB_MODULES_DIR.current / file_name_template.format(src_id=i) |
| 117 | ) |
| 118 | script_file.write_text( |
| 119 | f""" |
| 120 | let runCountEl = document.getElementById("run-count"); |
| 121 | runCountEl.setAttribute("data-value", {i}); |
| 122 | """ |
| 123 | ) |
| 124 | |
| 125 | await poll(lambda: hasattr(incr_src_id, "current")).until_is(True) |
| 126 | incr_src_id.current() |
| 127 | |
| 128 | run_count = await display.page.wait_for_selector("#run-count", state="attached") |
| 129 | poll_run_count = poll(run_count.get_attribute, "data-value") |
| 130 | await poll_run_count.until_equals("1") |
| 131 | |
| 132 | |
| 133 | def test_script_may_only_have_one_child(): |