From eb9fe7c4017b718f9a964bc18ed0740b7b63cbfe Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 16 Sep 2020 08:54:09 +0200 Subject: [PATCH] add tests --- BTCPayServer.Tests/BTCPayServer.Tests.csproj | 2 +- BTCPayServer.Tests/SeleniumTester.cs | 11 +++++++ BTCPayServer.Tests/SeleniumTests.cs | 30 +++++++++++++++++-- BTCPayServer/Views/Account/SetPassword.cshtml | 4 +-- BTCPayServer/Views/Server/CreateUser.cshtml | 2 +- BTCPayServer/Views/Server/ListUsers.cshtml | 2 +- BTCPayServer/Views/Server/_Nav.cshtml | 18 +++++------ 7 files changed, 53 insertions(+), 16 deletions(-) diff --git a/BTCPayServer.Tests/BTCPayServer.Tests.csproj b/BTCPayServer.Tests/BTCPayServer.Tests.csproj index f7d08c634..d6ab7faa4 100644 --- a/BTCPayServer.Tests/BTCPayServer.Tests.csproj +++ b/BTCPayServer.Tests/BTCPayServer.Tests.csproj @@ -22,7 +22,7 @@ - + all diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index f4d02f370..4e6cff7e9 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -12,6 +12,7 @@ using BTCPayServer.Models; using BTCPayServer.Services; using BTCPayServer.Tests.Logging; using BTCPayServer.Views.Manage; +using BTCPayServer.Views.Server; using BTCPayServer.Views.Stores; using BTCPayServer.Views.Wallets; using NBitcoin; @@ -382,6 +383,16 @@ namespace BTCPayServer.Tests Driver.FindElement(By.Id($"Wallet{navPages}")).Click(); } } + + public void GoToServer(ServerNavPages navPages = ServerNavPages.Index) + { + Driver.FindElement(By.Id("ServerSettings")).Click(); + if (navPages != ServerNavPages.Index) + { + Driver.FindElement(By.Id($"Server-{navPages}")).Click(); + } + + } public void GoToInvoice(string id) { diff --git a/BTCPayServer.Tests/SeleniumTests.cs b/BTCPayServer.Tests/SeleniumTests.cs index 4145dba4f..5af241405 100644 --- a/BTCPayServer.Tests/SeleniumTests.cs +++ b/BTCPayServer.Tests/SeleniumTests.cs @@ -8,6 +8,7 @@ using BTCPayServer.Data; using BTCPayServer.Models; using BTCPayServer.Services.Wallets; using BTCPayServer.Tests.Logging; +using BTCPayServer.Views.Server; using BTCPayServer.Views.Wallets; using Microsoft.EntityFrameworkCore; using NBitcoin; @@ -88,7 +89,7 @@ namespace BTCPayServer.Tests await s.StartAsync(); //Register & Log Out var email = s.RegisterNewUser(); - s.Driver.FindElement(By.Id("Logout")).Click(); + s.Logout(); s.Driver.AssertNoError(); Assert.Contains("Account/Login", s.Driver.Url); // Should show the Tor address @@ -129,7 +130,32 @@ namespace BTCPayServer.Tests s.Driver.FindElement(By.Id("MySettings")).Click(); s.ClickOnAllSideMenus(); - s.Driver.Quit(); + //let's test invite link + s.Logout(); + s.GoToRegister(); + var newAdminUser = s.RegisterNewUser(true); + s.GoToServer(ServerNavPages.Users); + s.Driver.FindElement(By.Id("CreateUser")).Click(); + + var usr = RandomUtils.GetUInt256().ToString().Substring(64 - 20) + "@a.com"; + s.Driver.FindElement(By.Id("Email")).SendKeys(usr); + s.Driver.FindElement(By.Id("Save")).Click(); + var url = s.AssertHappyMessage().FindElement(By.TagName("a")).Text;; + s.Logout(); + s.Driver.Navigate().GoToUrl(url); + Assert.Equal("hidden",s.Driver.FindElement(By.Id("Email")).GetAttribute("type")); + Assert.Equal(usr,s.Driver.FindElement(By.Id("Email")).GetAttribute("value")); + + s.Driver.FindElement(By.Id("Password")).SendKeys("123456"); + s.Driver.FindElement(By.Id("ConfirmPassword")).SendKeys("123456"); + s.Driver.FindElement(By.Id("SetPassword")).Click(); + s.AssertHappyMessage(); + s.Driver.FindElement(By.Id("Email")).SendKeys(usr); + s.Driver.FindElement(By.Id("Password")).SendKeys("123456"); + s.Driver.FindElement(By.Id("LoginButton")).Click(); + + // We should be logged in now + s.Driver.FindElement(By.Id("mainNav")); } } diff --git a/BTCPayServer/Views/Account/SetPassword.cshtml b/BTCPayServer/Views/Account/SetPassword.cshtml index 0f654a4dd..dd8f575c1 100644 --- a/BTCPayServer/Views/Account/SetPassword.cshtml +++ b/BTCPayServer/Views/Account/SetPassword.cshtml @@ -29,7 +29,7 @@ - + diff --git a/BTCPayServer/Views/Server/CreateUser.cshtml b/BTCPayServer/Views/Server/CreateUser.cshtml index 8c19439b8..385a3f8bb 100644 --- a/BTCPayServer/Views/Server/CreateUser.cshtml +++ b/BTCPayServer/Views/Server/CreateUser.cshtml @@ -47,7 +47,7 @@ } - + diff --git a/BTCPayServer/Views/Server/ListUsers.cshtml b/BTCPayServer/Views/Server/ListUsers.cshtml index 9b3c90148..77c5d71f1 100644 --- a/BTCPayServer/Views/Server/ListUsers.cshtml +++ b/BTCPayServer/Views/Server/ListUsers.cshtml @@ -9,7 +9,7 @@
Total Users: @Model.Total - + Add User diff --git a/BTCPayServer/Views/Server/_Nav.cshtml b/BTCPayServer/Views/Server/_Nav.cshtml index f148f3157..5553d6c86 100644 --- a/BTCPayServer/Views/Server/_Nav.cshtml +++ b/BTCPayServer/Views/Server/_Nav.cshtml @@ -1,10 +1,10 @@ -