ui: Fix repeat offer selected coins.

This commit is contained in:
tecnovert 2023-07-29 15:30:41 +02:00
parent 55ded71686
commit 547e50acb6
No known key found for this signature in database
GPG Key ID: 8ED6D8750C4E3F93
2 changed files with 67 additions and 11 deletions

View File

@ -12,19 +12,23 @@ function setupCustomSelect(select) {
} }
}); });
if (select.value == '-1') {
// Set the selected option based on the stored value // Set the selected option based on the stored value
const storedValue = localStorage.getItem(select.name); const storedValue = localStorage.getItem(select.name);
if (storedValue) { if (storedValue) {
const selectedOption = select.querySelector(`option[value="${storedValue}"]`);
if (selectedOption) {
select.value = storedValue; select.value = storedValue;
}
}
// Set the selected option image based on the selected value
const selectedOption = select.querySelector(`option[value="${select.value}"]`);
if (selectedOption) {
const image = selectedOption.getAttribute('data-image'); const image = selectedOption.getAttribute('data-image');
if (image) { if (image) {
select.style.backgroundImage = `url(${image})`; select.style.backgroundImage = `url(${image})`;
selectImage.src = image; selectImage.src = image;
} }
} }
}
// Update the select element and image when the user makes a selection // Update the select element and image when the user makes a selection
select.addEventListener('change', () => { select.addEventListener('change', () => {

View File

@ -16,8 +16,10 @@ python tests/basicswap/selenium/test_offer.py
""" """
import json
import time import time
from urllib.request import urlopen
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
@ -41,11 +43,61 @@ def test_html():
select.select_by_visible_text('Monero') select.select_by_visible_text('Monero')
driver.find_element(By.NAME, 'amt_from').send_keys('1') driver.find_element(By.NAME, 'amt_from').send_keys('1')
driver.find_element(By.NAME, 'amt_to').send_keys('1') driver.find_element(By.NAME, 'amt_to').send_keys('2')
driver.find_element(By.NAME, 'continue').click() driver.find_element(By.NAME, 'continue').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
offer1_id = offer_link.text.split(' ')[2]
driver.get(node1_url + '/newoffer')
time.sleep(1)
select = Select(driver.find_element(By.ID, 'coin_from'))
select.select_by_visible_text('Particl')
select = Select(driver.find_element(By.ID, 'coin_to'))
select.select_by_visible_text('Monero')
driver.find_element(By.NAME, 'amt_from').send_keys('3')
driver.find_element(By.NAME, 'amt_to').send_keys('4')
driver.find_element(By.NAME, 'continue').click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
offer2_id = offer_link.text.split(' ')[2]
driver.get(node1_url + '/offer/' + offer1_id)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'repeat_offer'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
offer3_id = offer_link.text.split(' ')[2]
offer3_json = json.loads(urlopen(node1_url + '/json/offers/' + offer3_id).read())[0]
assert (offer3_json['coin_from'] == 'Bitcoin')
assert (offer3_json['coin_to'] == 'Monero')
driver.get(node1_url + '/offer/' + offer2_id)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'repeat_offer'))).click()
time.sleep(1) # Add time for setupCustomSelect to fire
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'check_offer'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, 'submit_offer'))).click()
time.sleep(1)
offer_link = driver.find_element(By.XPATH, "//a[contains(text(),'Sent Offer')]")
offer4_id = offer_link.text.split(' ')[2]
offer4_json = json.loads(urlopen(node1_url + '/json/offers/' + offer4_id).read())[0]
assert (offer4_json['coin_from'] == 'Particl')
assert (offer4_json['coin_to'] == 'Monero')
driver.close() driver.close()