From 7208e6315511dfa51c3d807bea4a3da7ca26b5d2 Mon Sep 17 00:00:00 2001 From: Andrew Camilleri Date: Tue, 3 Sep 2019 13:11:36 +0200 Subject: [PATCH] Excerpts from #971 (manual PR) (part1 ) (#1006) * Excerpts from #971 Relating to selenium tests + small renamings * fix build --- BTCPayServer.Common/BTCPayNetworkProvider.cs | 1 - BTCPayServer.Tests/SeleniumTester.cs | 45 +++++++++++++++++-- BTCPayServer.Tests/SeleniumTests.cs | 18 ++++---- BTCPayServer/Controllers/StoresController.cs | 4 +- .../Models/StoreViewModels/StoreViewModel.cs | 17 +++---- .../Invoice/InvoicePaymentsPartial.cshtml | 2 +- .../Views/Invoice/ListInvoices.cshtml | 2 +- BTCPayServer/Views/Stores/UpdateStore.cshtml | 14 +++--- .../Views/UserStores/ListStores.cshtml | 4 +- 9 files changed, 68 insertions(+), 39 deletions(-) diff --git a/BTCPayServer.Common/BTCPayNetworkProvider.cs b/BTCPayServer.Common/BTCPayNetworkProvider.cs index 066178a9d..7bf9211a5 100644 --- a/BTCPayServer.Common/BTCPayNetworkProvider.cs +++ b/BTCPayServer.Common/BTCPayNetworkProvider.cs @@ -56,7 +56,6 @@ namespace BTCPayServer InitFeathercoin(); InitGroestlcoin(); InitViacoin(); - // Assume that electrum mappings are same as BTC if not specified foreach (var network in _Networks.Values.OfType()) { diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index ef6726b6a..a83bd5e02 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -67,14 +67,15 @@ namespace BTCPayServer.Tests return usr; } - public string CreateNewStore() + public (string storeName, string storeId) CreateNewStore() { var usr = "Store" + RandomUtils.GetUInt64().ToString(); Driver.FindElement(By.Id("Stores")).Click(); Driver.FindElement(By.Id("CreateStore")).Click(); Driver.FindElement(By.Id("Name")).SendKeys(usr); Driver.FindElement(By.Id("Create")).Click(); - return usr; + + return (usr, Driver.FindElement(By.Id("Id")).GetAttribute("value")); } public void AddDerivationScheme(string derivationScheme = "xpub661MyMwAqRbcGABgHMUXDzPzH1tU7eZaAaJQXhDXsSxsqyQzQeU6kznNfSuAyqAK9UaWSaZaMFdNiY5BCF4zBPAzSnwfUAwUhwttuAKwfRX-[legacy]") @@ -99,14 +100,24 @@ namespace BTCPayServer.Tests } } - public void CreateInvoice(string random) + public string CreateInvoice(string random, string refundEmail = "") { Driver.FindElement(By.Id("Invoices")).Click(); Driver.FindElement(By.Id("CreateNewInvoice")).Click(); Driver.FindElement(By.CssSelector("input#Amount.form-control")).SendKeys("100"); Driver.FindElement(By.Name("StoreId")).SendKeys("Deriv" + random + Keys.Enter); Driver.FindElement(By.Id("Create")).Click(); - return; + var statusElement = Driver.FindElement(By.ClassName("alert-success")); + var id = statusElement.Text.Split(" ")[1]; + if (!string.IsNullOrEmpty(refundEmail)) + { + GoToInvoiceCheckout(id); + Driver.FindElement(By.Id("emailAddressFormInput")).SendKeys(refundEmail); + Driver.FindElement(By.Id("emailAddressForm")).FindElement(By.CssSelector("button.action-button")) + .Click(); + } + + return id; } @@ -147,5 +158,31 @@ namespace BTCPayServer.Tests Driver.FindElement(By.Id("LoginButton")).Click(); } + + public void GoToStore(string storeId) + { + Driver.FindElement(By.Id("Stores")).Click(); + Driver.FindElement(By.Id($"update-store-{storeId}")).Click(); + } + + public void GoToInvoiceCheckout(string invoiceId) + { + Driver.FindElement(By.Id("Invoices")).Click(); + Driver.FindElement(By.Id($"invoice-checkout-{invoiceId}")).Click(); + } + + + public void SetCheckbox(IWebElement element, bool value) + { + if ((value && !element.Selected) || (!value && element.Selected)) + { + element.Click(); + } + } + + public void SetCheckbox(SeleniumTester s, string inputName, bool value) + { + SetCheckbox(s.Driver.FindElement(By.Name(inputName)), value); + } } } diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index b9f3b9f39..03ff81652 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -151,7 +151,7 @@ namespace BTCPayServer.Tests { s.Start(); var alice = s.RegisterNewUser(); - var store = s.CreateNewStore(); + var store = s.CreateNewStore().storeName; s.AddDerivationScheme(); s.Driver.AssertNoError(); Assert.Contains(store, s.Driver.PageSource); @@ -201,7 +201,7 @@ namespace BTCPayServer.Tests { s.Start(); s.RegisterNewUser(); - var store = s.CreateNewStore(); + var store = s.CreateNewStore().storeName; s.AddDerivationScheme(); CreateInvoice(s, store); @@ -236,11 +236,11 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("Apps")).Click(); s.Driver.FindElement(By.Id("CreateNewApp")).Click(); - s.Driver.FindElement(By.Name("Name")).SendKeys("PoS" + store); - s.Driver.FindElement(By.CssSelector("select#SelectedAppType.form-control")).SendKeys("PointOfSale" + Keys.Enter); - s.Driver.FindElement(By.CssSelector("select#SelectedStore.form-control")).SendKeys(store + Keys.Enter); + s.Driver.FindElement(By.Name("Name")).SendKeys("PoS" + Guid.NewGuid()); + s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("PointOfSale" + Keys.Enter); + s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter); s.Driver.FindElement(By.Id("Create")).Click(); - s.Driver.FindElement(By.CssSelector("input#EnableShoppingCart.form-check")).Click(); + s.Driver.FindElement(By.Id("EnableShoppingCart")).Click(); s.Driver.FindElement(By.Id("SaveSettings")).ForceClick(); s.Driver.FindElement(By.Id("ViewApp")).ForceClick(); s.Driver.SwitchTo().Window(s.Driver.WindowHandles.Last()); @@ -261,9 +261,9 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("Apps")).Click(); s.Driver.FindElement(By.Id("CreateNewApp")).Click(); - s.Driver.FindElement(By.Name("Name")).SendKeys("CF" + store); - s.Driver.FindElement(By.CssSelector("select#SelectedAppType.form-control")).SendKeys("Crowdfund" + Keys.Enter); - s.Driver.FindElement(By.CssSelector("select#SelectedStore.form-control")).SendKeys(store + Keys.Enter); + s.Driver.FindElement(By.Name("Name")).SendKeys("CF" + Guid.NewGuid()); + s.Driver.FindElement(By.Id("SelectedAppType")).SendKeys("Crowdfund" + Keys.Enter); + s.Driver.FindElement(By.Id("SelectedStore")).SendKeys(store + Keys.Enter); s.Driver.FindElement(By.Id("Create")).Click(); s.Driver.FindElement(By.Id("Title")).SendKeys("Kukkstarter"); s.Driver.FindElement(By.CssSelector("div.note-editable.card-block")).SendKeys("1BTC = 1BTC"); diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 288fc841c..12bede329 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -506,7 +506,7 @@ namespace BTCPayServer.Controllers } var changellyEnabled = storeBlob.ChangellySettings != null && storeBlob.ChangellySettings.Enabled; - vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod() + vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.AdditionalPaymentMethod() { Enabled = changellyEnabled, Action = nameof(UpdateChangellySettings), @@ -514,7 +514,7 @@ namespace BTCPayServer.Controllers }); var coinSwitchEnabled = storeBlob.CoinSwitchSettings != null && storeBlob.CoinSwitchSettings.Enabled; - vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.ThirdPartyPaymentMethod() + vm.ThirdPartyPaymentMethods.Add(new StoreViewModel.AdditionalPaymentMethod() { Enabled = coinSwitchEnabled, Action = nameof(UpdateCoinSwitchSettings), diff --git a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs index 924c6ca56..1c888c168 100644 --- a/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs +++ b/BTCPayServer/Models/StoreViewModels/StoreViewModel.cs @@ -1,14 +1,7 @@ -using BTCPayServer.Data; -using BTCPayServer.Services; -using BTCPayServer.Services.Invoices; -using BTCPayServer.Services.Rates; -using BTCPayServer.Validation; -using Microsoft.AspNetCore.Mvc.Rendering; -using System; +using BTCPayServer.Validation; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Threading.Tasks; +using BTCPayServer.Data; namespace BTCPayServer.Models.StoreViewModels { @@ -22,7 +15,7 @@ namespace BTCPayServer.Models.StoreViewModels public bool Enabled { get; set; } } - public class ThirdPartyPaymentMethod + public class AdditionalPaymentMethod { public string Provider { get; set; } public bool Enabled { get; set; } @@ -58,8 +51,8 @@ namespace BTCPayServer.Models.StoreViewModels public List DerivationSchemes { get; set; } = new List(); - public List ThirdPartyPaymentMethods { get; set; } = - new List(); + public List ThirdPartyPaymentMethods { get; set; } = + new List(); [Display(Name = "Invoice expires if the full amount has not been paid after ... minutes")] [Range(1, 60 * 24 * 24)] diff --git a/BTCPayServer/Views/Invoice/InvoicePaymentsPartial.cshtml b/BTCPayServer/Views/Invoice/InvoicePaymentsPartial.cshtml index 0c4c7455d..3d9d0806a 100644 --- a/BTCPayServer/Views/Invoice/InvoicePaymentsPartial.cshtml +++ b/BTCPayServer/Views/Invoice/InvoicePaymentsPartial.cshtml @@ -16,7 +16,7 @@ { Overpaid } - + @foreach (var payment in Model.CryptoPayments) diff --git a/BTCPayServer/Views/Invoice/ListInvoices.cshtml b/BTCPayServer/Views/Invoice/ListInvoices.cshtml index 88942f65d..6ef06291a 100644 --- a/BTCPayServer/Views/Invoice/ListInvoices.cshtml +++ b/BTCPayServer/Views/Invoice/ListInvoices.cshtml @@ -245,7 +245,7 @@ @if (invoice.ShowCheckout) { - Checkout + Checkout [^] @if (!invoice.CanMarkStatus) { diff --git a/BTCPayServer/Views/Stores/UpdateStore.cshtml b/BTCPayServer/Views/Stores/UpdateStore.cshtml index 40ddcafe4..6c6a9aae5 100644 --- a/BTCPayServer/Views/Stores/UpdateStore.cshtml +++ b/BTCPayServer/Views/Stores/UpdateStore.cshtml @@ -180,24 +180,24 @@
-
Third party Payment methods
+
Additional Payment methods
- - + + - @foreach(var scheme in Model.ThirdPartyPaymentMethods) + @foreach (var scheme in Model.ThirdPartyPaymentMethods) { - - + } diff --git a/BTCPayServer/Views/UserStores/ListStores.cshtml b/BTCPayServer/Views/UserStores/ListStores.cshtml index bd2dcd1ac..68dd4446e 100644 --- a/BTCPayServer/Views/UserStores/ListStores.cshtml +++ b/BTCPayServer/Views/UserStores/ListStores.cshtml @@ -34,7 +34,7 @@ @foreach (var store in Model.Stores) { - +
ProviderEnabledActionsEnabledActions
@scheme.Provider - @if(scheme.Enabled) + + @if (scheme.Enabled) { } @@ -206,7 +206,7 @@ } ModifyModify
@store.Name @if (!string.IsNullOrEmpty(store.WebSite)) @@ -46,7 +46,7 @@ Invoices - @if (store.IsOwner) { - Settings - + Settings - } Remove