From 5ce8648bd2a9956832479c985da0fc5ca71b7f97 Mon Sep 17 00:00:00 2001 From: rockstardev <5191402+rockstardev@users.noreply.github.com> Date: Sat, 15 Mar 2025 03:24:19 -0500 Subject: [PATCH] Fixing tests --- BTCPayServer.Tests/SeleniumTests.cs | 12 +-- .../UIStoresController.EmailRules.cs | 15 +++- .../Views/UIStores/StoreEmailRulesList.cshtml | 73 +++++++++++-------- .../UIStores/StoreEmailRulesManage.cshtml | 2 +- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 6bec76f44..f1ebb2f1a 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -828,14 +828,16 @@ namespace BTCPayServer.Tests Assert.DoesNotContain("You need to configure email settings before this feature works", s.Driver.PageSource); s.Driver.FindElement(By.Id("CreateEmailRule")).Click(); - var select = new SelectElement(s.Driver.FindElement(By.Id("Rules_0__Trigger"))); + var select = new SelectElement(s.Driver.FindElement(By.Id("Trigger"))); select.SelectByText("An invoice has been settled", true); - s.Driver.FindElement(By.Id("Rules_0__To")).SendKeys("test@gmail.com"); - s.Driver.FindElement(By.Id("Rules_0__CustomerEmail")).Click(); - s.Driver.FindElement(By.Id("Rules_0__Subject")).SendKeys("Thanks!"); + s.Driver.FindElement(By.Id("To")).SendKeys("test@gmail.com"); + s.Driver.FindElement(By.Id("CustomerEmail")).Click(); + s.Driver.FindElement(By.Id("Subject")).SendKeys("Thanks!"); s.Driver.FindElement(By.ClassName("note-editable")).SendKeys("Your invoice is settled"); s.Driver.FindElement(By.Id("SaveEmailRules")).Click(); - Assert.Contains("Store email rules saved", s.FindAlertMessage().Text); + // we now have a rule + Assert.DoesNotContain("There are no rules yet.", s.Driver.PageSource); + Assert.Contains("test@gmail.com", s.Driver.PageSource); s.GoToStore(StoreNavPages.Emails); Assert.True(s.Driver.FindElement(By.Id("IsCustomSMTP")).Selected); diff --git a/BTCPayServer/Controllers/UIStoresController.EmailRules.cs b/BTCPayServer/Controllers/UIStoresController.EmailRules.cs index 9aabb999f..369d67e5f 100644 --- a/BTCPayServer/Controllers/UIStoresController.EmailRules.cs +++ b/BTCPayServer/Controllers/UIStoresController.EmailRules.cs @@ -4,6 +4,8 @@ using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Linq; using System.Threading.Tasks; +using BTCPayServer.Abstractions.Extensions; +using BTCPayServer.Abstractions.Models; using BTCPayServer.Client; using BTCPayServer.Data; using BTCPayServer.Models; @@ -18,10 +20,21 @@ namespace BTCPayServer.Controllers public partial class UIStoresController { [HttpGet("{storeId}/emails/rules")] - public IActionResult EmailRulesIndex(string storeId) + public async Task EmailRulesIndex(string storeId) { var store = HttpContext.GetStoreData(); if (store == null) return NotFound(); + + var configured = await _emailSenderFactory.IsComplete(store.Id); + if (!configured && !TempData.HasStatusMessage()) + { + TempData.SetStatusMessageModel(new StatusMessageModel + { + Severity = StatusMessageModel.StatusSeverity.Warning, + Html = "You need to configure email settings before this feature works." + + $" Configure store email settings." + }); + } var rules = store.GetStoreBlob().EmailRules ?? new List(); return View("StoreEmailRulesList", rules); diff --git a/BTCPayServer/Views/UIStores/StoreEmailRulesList.cshtml b/BTCPayServer/Views/UIStores/StoreEmailRulesList.cshtml index 249aaa4b0..250e64c67 100644 --- a/BTCPayServer/Views/UIStores/StoreEmailRulesList.cshtml +++ b/BTCPayServer/Views/UIStores/StoreEmailRulesList.cshtml @@ -17,7 +17,7 @@

@ViewData["Title"]

- Create Email Rule @@ -28,34 +28,43 @@ Email rules allow BTCPay Server to send customized emails from your store based on events.

-
- - - - - - - - - - - - @foreach (var rule in Model.Select((value, index) => new { value, index })) - { - - - - - - - - } - -
TriggerCustomer EmailToSubjectActions
@rule.value.Trigger@(rule.value.CustomerEmail ? "Yes" : "No")@rule.value.To@rule.value.Subject - Edit - - -
- Delete -
-
-
+@if (Model.Any()) +{ +
+ + + + + + + + + + + + @foreach (var rule in Model.Select((value, index) => new { value, index })) + { + + + + + + + + } + +
TriggerCustomer EmailToSubjectActions
@rule.value.Trigger@(rule.value.CustomerEmail ? "Yes" : "No")@rule.value.To@rule.value.Subject + Edit + - +
+ Delete +
+
+
+} +else +{ +

+ There are no rules yet. +

+} diff --git a/BTCPayServer/Views/UIStores/StoreEmailRulesManage.cshtml b/BTCPayServer/Views/UIStores/StoreEmailRulesManage.cshtml index f30212f78..5126378ab 100644 --- a/BTCPayServer/Views/UIStores/StoreEmailRulesManage.cshtml +++ b/BTCPayServer/Views/UIStores/StoreEmailRulesManage.cshtml @@ -17,7 +17,7 @@