From d6f13be95fd9608ebe1f77fce645e65680a2bc50 Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Thu, 7 Jul 2022 05:47:59 -0700 Subject: [PATCH] Redirect to invoice details instead of list upon creation (#3936) * Redirect to invoice details instead of list upon creation close #3909 * fix tests --- BTCPayServer.Tests/CheckoutUITests.cs | 9 --------- BTCPayServer.Tests/SeleniumTests.cs | 13 ++++++------- BTCPayServer/Controllers/UIInvoiceController.UI.cs | 6 +++--- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/BTCPayServer.Tests/CheckoutUITests.cs b/BTCPayServer.Tests/CheckoutUITests.cs index 5e8ad521d..5c7630877 100644 --- a/BTCPayServer.Tests/CheckoutUITests.cs +++ b/BTCPayServer.Tests/CheckoutUITests.cs @@ -37,9 +37,6 @@ namespace BTCPayServer.Tests s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput")); s.GoToHome(); s.CreateInvoice(); - s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); - s.Driver.AssertNoError(); - s.Driver.Navigate().Back(); s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click(); Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl"))); @@ -102,9 +99,6 @@ namespace BTCPayServer.Tests // Now create an invoice that doesn't require a refund email s.CreateInvoice(100, "USD", "", null, false); - s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); - s.Driver.AssertNoError(); - s.Driver.Navigate().Back(); s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click(); Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl"))); s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput")); @@ -115,9 +109,6 @@ namespace BTCPayServer.Tests // Now create an invoice that requires refund email but already has one set, email input shouldn't show up s.CreateInvoice(100, "USD", "a@g.com", null, true); - s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); - s.Driver.AssertNoError(); - s.Driver.Navigate().Back(); s.Driver.FindElement(By.ClassName("invoice-checkout-link")).Click(); Assert.NotEmpty(s.Driver.FindElements(By.Id("checkoutCtrl"))); s.Driver.AssertElementNotFound(By.Id("emailAddressFormInput")); diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 9b823fd46..27099c317 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -417,24 +417,23 @@ namespace BTCPayServer.Tests s.AddDerivationScheme(); s.GoToInvoices(); s.CreateInvoice(); - s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElement(By.Id("markStatusDropdownMenuButton")).Click(); s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); s.Driver.Navigate().Refresh(); - s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElement(By.Id("markStatusDropdownMenuButton")).Click(); s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); - s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); - Assert.Contains("Settled (marked)", s.Driver.PageSource); + s.Driver.Navigate().Refresh(); - s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElement(By.Id("markStatusDropdownMenuButton")).Click(); s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); s.Driver.Navigate().Refresh(); - s.Driver.FindElement(By.ClassName("changeInvoiceStateToggle")).Click(); + s.Driver.FindElement(By.Id("markStatusDropdownMenuButton")).Click(); s.Driver.FindElements(By.ClassName("changeInvoiceState"))[0].Click(); TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); } @@ -562,7 +561,7 @@ namespace BTCPayServer.Tests Assert.Contains("There are no invoices matching your criteria.", s.Driver.PageSource); var invoiceId = s.CreateInvoice(); s.FindAlertMessage(); - s.Driver.FindElement(By.ClassName("invoice-details-link")).Click(); + var invoiceUrl = s.Driver.Url; //let's test archiving an invoice diff --git a/BTCPayServer/Controllers/UIInvoiceController.UI.cs b/BTCPayServer/Controllers/UIInvoiceController.UI.cs index 8ba4ea456..eeb64482d 100644 --- a/BTCPayServer/Controllers/UIInvoiceController.UI.cs +++ b/BTCPayServer/Controllers/UIInvoiceController.UI.cs @@ -1,6 +1,5 @@ #nullable enable using System; -using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -33,7 +32,6 @@ using Microsoft.EntityFrameworkCore; using NBitcoin; using NBitpayClient; using NBXplorer; -using NBXplorer.Models; using Newtonsoft.Json.Linq; using BitpayCreateInvoiceRequest = BTCPayServer.Models.BitpayCreateInvoiceRequest; using StoreData = BTCPayServer.Data.StoreData; @@ -86,6 +84,7 @@ namespace BTCPayServer.Controllers } [HttpGet("invoices/{invoiceId}")] + [HttpGet("/stores/{storeId}/invoices/${invoiceId}")] [Authorize(Policy = Policies.CanViewInvoices, AuthenticationSchemes = AuthenticationSchemes.Cookie)] public async Task Invoice(string invoiceId) { @@ -1100,7 +1099,8 @@ namespace BTCPayServer.Controllers TempData[WellKnownTempData.SuccessMessage] = $"Invoice {result.Data.Id} just created!"; CreatedInvoiceId = result.Data.Id; - return RedirectToAction(nameof(ListInvoices), new { result.Data.StoreId }); + + return RedirectToAction(nameof(Invoice), new { storeId = result.Data.StoreId, invoiceId = result.Data.Id }); } catch (BitpayHttpException ex) {