Select then clear several file uploads and check that they are cleared. Args: tmp_path: pytest tmp_path fixture upload_file: harness for UploadFile app. driver: WebDriver instance. upload_root_id: ID of the upload root element, or None for the default.
(
tmp_path, upload_file: AppHarness, driver: WebDriver, upload_root_id: str | None
)
| 724 | |
| 725 | @pytest.mark.parametrize("upload_root_id", [None, "secondary"]) |
| 726 | def test_clear_files( |
| 727 | tmp_path, upload_file: AppHarness, driver: WebDriver, upload_root_id: str | None |
| 728 | ): |
| 729 | """Select then clear several file uploads and check that they are cleared. |
| 730 | |
| 731 | Args: |
| 732 | tmp_path: pytest tmp_path fixture |
| 733 | upload_file: harness for UploadFile app. |
| 734 | driver: WebDriver instance. |
| 735 | upload_root_id: ID of the upload root element, or None for the default. |
| 736 | """ |
| 737 | assert upload_file.app_instance is not None |
| 738 | poll_for_token(driver, upload_file) |
| 739 | clear_btn = driver.find_element(By.ID, "clear_uploads") |
| 740 | clear_btn.click() |
| 741 | |
| 742 | suffix = f"_{upload_root_id}" if upload_root_id else "" |
| 743 | |
| 744 | upload_box = get_upload_box(driver, upload_root_id=upload_root_id) |
| 745 | assert upload_box |
| 746 | upload_button = driver.find_element(By.ID, f"upload_button{suffix}") |
| 747 | assert upload_button |
| 748 | |
| 749 | exp_files = { |
| 750 | "test1.txt": "test file contents!", |
| 751 | "test2.txt": "this is test file number 2!", |
| 752 | "reflex.txt": "reflex is awesome!", |
| 753 | } |
| 754 | for exp_name, exp_contents in exp_files.items(): |
| 755 | target_file = tmp_path / exp_name |
| 756 | target_file.write_text(exp_contents) |
| 757 | upload_box.send_keys(str(target_file)) |
| 758 | |
| 759 | time.sleep(0.2) |
| 760 | |
| 761 | # check that the selected files are displayed |
| 762 | selected_files = driver.find_element(By.ID, f"selected_files{suffix}") |
| 763 | assert [Path(name).name for name in selected_files.text.split("\n")] == [ |
| 764 | Path(name).name for name in exp_files |
| 765 | ] |
| 766 | |
| 767 | clear_button = driver.find_element(By.ID, f"clear_button{suffix}") |
| 768 | assert clear_button |
| 769 | clear_button.click() |
| 770 | |
| 771 | # check that the selected files are cleared |
| 772 | selected_files = driver.find_element(By.ID, f"selected_files{suffix}") |
| 773 | assert selected_files.text == "" |
| 774 | |
| 775 | |
| 776 | # TODO: drag and drop directory |
nothing calls this directly
no test coverage detected