From e22bdf1e54b32b5df3501115cc306f3099af371e Mon Sep 17 00:00:00 2001 From: Johannes Maron Date: Fri, 1 Nov 2024 13:30:30 +0100 Subject: [PATCH] Add change test --- s3file/static/s3file/js/s3file.js | 6 ++++++ tests/test_forms.py | 22 +++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/s3file/static/s3file/js/s3file.js b/s3file/static/s3file/js/s3file.js index cd28257..43d62cc 100644 --- a/s3file/static/s3file/js/s3file.js +++ b/s3file/static/s3file/js/s3file.js @@ -32,6 +32,12 @@ export class S3FileInput extends globalThis.HTMLInputElement { changeHandler () { this.keys = [] this.upload = null + try { + this.form.removeEventListener('submit', this.submitHandler.bind(this)) + } catch (error) { + console.debug(error) + } + this.form.addEventListener('submit', this.submitHandler.bind(this), { once: true }) } /** diff --git a/tests/test_forms.py b/tests/test_forms.py index a22e766..508665a 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -231,15 +231,6 @@ def test_file_update( def test_file_insert_submit_value( self, driver, live_server, upload_file, freeze_upload_folder ): - driver.get(live_server + self.create_url) - file_input = driver.find_element(By.XPATH, "//input[@name='file']") - file_input.send_keys(upload_file) - assert file_input.get_attribute("name") == "file" - save_button = driver.find_element(By.XPATH, "//input[@name='save']") - with wait_for_page_load(driver, timeout=10): - save_button.click() - assert "save" in driver.page_source - driver.get(live_server + self.create_url) file_input = driver.find_element(By.XPATH, "//input[@name='file']") file_input.send_keys(upload_file) @@ -266,6 +257,19 @@ def test_file_insert_submit_formaction( assert "foo" in driver.page_source assert "bar" in driver.page_source + @pytest.mark.selenium + def test_file_insert_change_event( + self, driver, live_server, upload_file, another_upload_file, freeze_upload_folder + ): + driver.get(live_server + self.create_url) + file_input = driver.find_element(By.XPATH, "//input[@name='file']") + file_input.send_keys(upload_file) + file_input.send_keys(another_upload_file) + save_button = driver.find_element(By.CSS_SELECTOR, "input[name=save]") + with wait_for_page_load(driver, timeout=10): + save_button.click() + assert "save" in driver.page_source + @pytest.mark.selenium def test_multi_file( self,