diff --git a/BTCPayServer.Tests/PlaywrightTests.cs b/BTCPayServer.Tests/PlaywrightTests.cs index 2ca973463..3771206ab 100644 --- a/BTCPayServer.Tests/PlaywrightTests.cs +++ b/BTCPayServer.Tests/PlaywrightTests.cs @@ -1211,6 +1211,123 @@ namespace BTCPayServer.Tests await s.FindAlertMessage(); Assert.Contains("There are no rules yet.", await s.Page.ContentAsync()); } + + [Fact] + public async Task CanUseDynamicDns() + { + await using var s = CreatePlaywrightTester(); + await s.StartAsync(); + await s.RegisterNewUser(isAdmin: true); + await s.GoToUrl("/server/services"); + Assert.Contains("Dynamic DNS", await s.Page.ContentAsync()); + + await s.GoToUrl("/server/services/dynamic-dns"); + await s.Page.AssertNoError(); + if ((await s.Page.ContentAsync()).Contains("pouet.hello.com")) + { + await s.GoToUrl("/server/services/dynamic-dns/pouet.hello.com/delete"); + await s.Page.ClickAsync("#ConfirmContinue"); + } + + await s.ClickPagePrimary(); + await s.Page.AssertNoError(); + await s.Page.FillAsync("#ServiceUrl", s.Link("/")); + await s.Page.FillAsync("#Settings_Hostname", "pouet.hello.com"); + await s.Page.FillAsync("#Settings_Login", "MyLog"); + await s.Page.FillAsync("#Settings_Password", "MyLog"); + await s.ClickPagePrimary(); + await s.Page.AssertNoError(); + Assert.Contains("The Dynamic DNS has been successfully queried", await s.Page.ContentAsync()); + Assert.EndsWith("/server/services/dynamic-dns", s.Page.Url); + + // Try to create the same hostname (should fail) + await s.ClickPagePrimary(); + await s.Page.AssertNoError(); + await s.Page.FillAsync("#ServiceUrl", s.Link("/")); + await s.Page.FillAsync("#Settings_Hostname", "pouet.hello.com"); + await s.Page.FillAsync("#Settings_Login", "MyLog"); + await s.Page.FillAsync("#Settings_Password", "MyLog"); + await s.ClickPagePrimary(); + await s.Page.AssertNoError(); + Assert.Contains("This hostname already exists", await s.Page.ContentAsync()); + + // Delete the hostname + await s.GoToUrl("/server/services/dynamic-dns"); + Assert.Contains("/server/services/dynamic-dns/pouet.hello.com/delete", await s.Page.ContentAsync()); + await s.GoToUrl("/server/services/dynamic-dns/pouet.hello.com/delete"); + await s.Page.ClickAsync("#ConfirmContinue"); + await s.Page.AssertNoError(); + + Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", await s.Page.ContentAsync()); + } + + [Fact] + public async Task CanCreateInvoiceInUI() + { + await using var s = CreatePlaywrightTester(); + await s.StartAsync(); + await s.RegisterNewUser(true); + await s.CreateNewStore(); + await s.GoToInvoices(); + + await s.ClickPagePrimary(); + Assert.Contains("To create an invoice, you need to", await s.Page.ContentAsync()); + + await s.AddDerivationScheme(); + await s.GoToInvoices(); + var invoiceId = await s.CreateInvoice(); + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-toggle"); + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-menu button:first-child"); + await TestUtils.EventuallyAsync(async () => Assert.Contains("Invalid (marked)", await s.Page.ContentAsync())); + await s.Page.ReloadAsync(); + + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-toggle"); + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-menu button:first-child"); + await TestUtils.EventuallyAsync(async () => Assert.Contains("Settled (marked)", await s.Page.ContentAsync())); + + await s.Page.ReloadAsync(); + + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-toggle"); + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-menu button:first-child"); + await TestUtils.EventuallyAsync(async () => Assert.Contains("Invalid (marked)", await s.Page.ContentAsync())); + await s.Page.ReloadAsync(); + + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-toggle"); + await s.Page.ClickAsync("[data-invoice-state-badge] .dropdown-menu button:first-child"); + await TestUtils.EventuallyAsync(async () => Assert.Contains("Settled (marked)", await s.Page.ContentAsync())); + + // Zero amount invoice should redirect to receipt + var zeroAmountId = await s.CreateInvoice(0); + await s.GoToUrl($"/i/{zeroAmountId}"); + Assert.EndsWith("/receipt", s.Page.Url); + Assert.Contains("$0.00", await s.Page.ContentAsync()); + await s.GoToInvoice(zeroAmountId); + Assert.Equal("Settled", (await s.Page.Locator("[data-invoice-state-badge]").TextContentAsync())?.Trim()); + } + + [Fact] + public async Task CanImportMnemonic() + { + await using var s = CreatePlaywrightTester(); + await s.StartAsync(); + await s.RegisterNewUser(true); + foreach (var isHotwallet in new[] { false, true }) + { + var cryptoCode = "BTC"; + await s.CreateNewStore(); + await s.GenerateWallet(cryptoCode, "melody lizard phrase voice unique car opinion merge degree evil swift cargo", isHotWallet: isHotwallet); + await s.GoToWalletSettings(cryptoCode); + if (isHotwallet) + { + await s.Page.ClickAsync("#ActionsDropdownToggle"); + Assert.True(await s.Page.Locator("#ViewSeed").IsVisibleAsync()); + } + else + { + Assert.False(await s.Page.Locator("#ViewSeed").IsVisibleAsync()); + } + } + } } } diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 6646fab09..3d1af58c5 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -80,99 +80,7 @@ namespace BTCPayServer.Tests Assert.Contains("Seed removed", seedEl.Text, StringComparison.OrdinalIgnoreCase); } - [Fact(Timeout = TestTimeout)] - public async Task CanUseDynamicDns() - { - using var s = CreateSeleniumTester(); - await s.StartAsync(); - s.RegisterNewUser(isAdmin: true); - s.Driver.Navigate().GoToUrl(s.Link("/server/services")); - Assert.Contains("Dynamic DNS", s.Driver.PageSource); - s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns")); - s.Driver.AssertNoError(); - if (s.Driver.PageSource.Contains("pouet.hello.com")) - { - // Cleanup old test run - s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete")); - s.Driver.FindElement(By.Id("ConfirmContinue")).Click(); - } - - s.ClickPagePrimary(); - s.Driver.AssertNoError(); - // We will just cheat for test purposes by only querying the server - s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/")); - s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com"); - s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog"); - s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter); - s.Driver.AssertNoError(); - Assert.Contains("The Dynamic DNS has been successfully queried", s.Driver.PageSource); - Assert.EndsWith("/server/services/dynamic-dns", s.Driver.Url); - - // Try to do the same thing should fail (hostname already exists) - s.ClickPagePrimary(); - s.Driver.AssertNoError(); - s.Driver.FindElement(By.Id("ServiceUrl")).SendKeys(s.Link("/")); - s.Driver.FindElement(By.Id("Settings_Hostname")).SendKeys("pouet.hello.com"); - s.Driver.FindElement(By.Id("Settings_Login")).SendKeys("MyLog"); - s.Driver.FindElement(By.Id("Settings_Password")).SendKeys("MyLog" + Keys.Enter); - s.Driver.AssertNoError(); - Assert.Contains("This hostname already exists", s.Driver.PageSource); - - // Delete it - s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns")); - Assert.Contains("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource); - s.Driver.Navigate().GoToUrl(s.Link("/server/services/dynamic-dns/pouet.hello.com/delete")); - s.Driver.FindElement(By.Id("ConfirmContinue")).Click(); - s.Driver.AssertNoError(); - - Assert.DoesNotContain("/server/services/dynamic-dns/pouet.hello.com/delete", s.Driver.PageSource); - } - - [Fact(Timeout = TestTimeout)] - public async Task CanCreateInvoiceInUI() - { - using var s = CreateSeleniumTester(); - await s.StartAsync(); - s.RegisterNewUser(true); - s.CreateNewStore(); - s.GoToInvoices(); - - // Should give us an error message if we try to create an invoice before adding a wallet - s.ClickPagePrimary(); - Assert.Contains("To create an invoice, you need to", s.Driver.PageSource); - - s.AddDerivationScheme(); - s.GoToInvoices(); - s.CreateInvoice(); - s.Driver.FindElement(By.CssSelector("[data-invoice-state-badge] .dropdown-toggle")).Click(); - s.Driver.FindElements(By.CssSelector("[data-invoice-state-badge] .dropdown-menu button"))[0].Click(); - TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); - s.Driver.Navigate().Refresh(); - - s.Driver.FindElement(By.CssSelector("[data-invoice-state-badge] .dropdown-toggle")).Click(); - s.Driver.FindElements(By.CssSelector("[data-invoice-state-badge] .dropdown-menu button"))[0].Click(); - TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); - - s.Driver.Navigate().Refresh(); - - s.Driver.FindElement(By.CssSelector("[data-invoice-state-badge] .dropdown-toggle")).Click(); - s.Driver.FindElements(By.CssSelector("[data-invoice-state-badge] .dropdown-menu button"))[0].Click(); - TestUtils.Eventually(() => Assert.Contains("Invalid (marked)", s.Driver.PageSource)); - s.Driver.Navigate().Refresh(); - - s.Driver.FindElement(By.CssSelector("[data-invoice-state-badge] .dropdown-toggle")).Click(); - s.Driver.FindElements(By.CssSelector("[data-invoice-state-badge] .dropdown-menu button"))[0].Click(); - TestUtils.Eventually(() => Assert.Contains("Settled (marked)", s.Driver.PageSource)); - - // zero amount invoice should redirect to receipt - var zeroAmountId = s.CreateInvoice(0); - s.GoToUrl($"/i/{zeroAmountId}"); - Assert.EndsWith("/receipt", s.Driver.Url); - Assert.Contains("$0.00", s.Driver.PageSource); - s.GoToInvoice(zeroAmountId); - Assert.Equal("Settled", s.Driver.FindElement(By.CssSelector("[data-invoice-state-badge]")).Text); - } [Fact(Timeout = TestTimeout)] public async Task CanUseInvoiceReceipts() @@ -1256,24 +1164,7 @@ namespace BTCPayServer.Tests s.FindAlertMessage(); } - [Fact(Timeout = TestTimeout)] - public async Task CanImportMnemonic() - { - using var s = CreateSeleniumTester(); - await s.StartAsync(); - s.RegisterNewUser(true); - foreach (var isHotwallet in new[] { false, true }) - { - var cryptoCode = "BTC"; - s.CreateNewStore(); - s.GenerateWallet(cryptoCode, "melody lizard phrase voice unique car opinion merge degree evil swift cargo", isHotWallet: isHotwallet); - s.GoToWalletSettings(cryptoCode); - if (isHotwallet) - Assert.Contains("View seed", s.Driver.PageSource); - else - Assert.DoesNotContain("View seed", s.Driver.PageSource); - } - } + [Fact] [Trait("Selenium", "Selenium")]