Skip to content

Commit

Permalink
fix now obsolete playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Jul 3, 2024
1 parent 7792d14 commit 1266de1
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 242 deletions.
2 changes: 1 addition & 1 deletion src/web/Jordnaer/Components/Account/Pages/Logout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</form>

<MudContainer MaxWidth="MaxWidth.Small">
<MudAlert ContentAlignment="HorizontalAlignment.Center" Severity="Severity.Info">Logger dig ud...</MudAlert>
<MudAlert ContentAlignment="HorizontalAlignment.Center" Severity="Severity.Info">Du er nu logget ud.</MudAlert>
</MudContainer>

<script>
Expand Down
2 changes: 1 addition & 1 deletion src/web/Jordnaer/Pages/Shared/TopBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{
} *@
<MudIconButton Title="Redigér Profil" Href="profile" Icon="@Icons.Material.Filled.Person" />
<MudIconButton Title="Log af" Href="Account/Logout" Icon="@Icons.Material.Filled.Logout" />
<MudIconButton Title="Log ud" Href="Account/Logout" Icon="@Icons.Material.Filled.Logout" />
</Authorized>
<NotAuthorized>
<MudIconButton Title="Log ind" Href="/Account/Login" Icon="@Icons.Material.Filled.Login" Variant="Variant.Outlined" Color="Color.Default" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Text.RegularExpressions;
using Jordnaer.E2E.Tests.Infrastructure;
using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace Jordnaer.E2E.Tests.AuthenticatedTests;

[Parallelizable(ParallelScope.All)]
[TestFixture]
[Category(nameof(TestCategory.UI))]
[Category(nameof(TestCategory.Authenticated))]
public class TopBarTests : BrowserTest
{
[Test]
[TestCase("Chat", ".*/chat")]
[TestCase("Redigér Profil", ".*/profile")]
[TestCase("Log ud", ".*")]
public async Task Links_Should_Be_Visible_In_The_Topbar_And_Redirect_Correctly(string linkName, string redirectUrlRegex)
{
var page = await SetUpFixture.Context.NewPageAsync();
await page.GotoAsync(TestConfiguration.Values.BaseUrl);

var link = page.GetByRole(AriaRole.Link,
new PageGetByRoleOptions
{
Name = linkName
});

await Expect(link).ToBeVisibleAsync();

await link.ClickAsync();

await Expect(page).ToHaveURLAsync(new Regex(redirectUrlRegex));

await page.CloseAsync();
}
}
28 changes: 7 additions & 21 deletions tests/web/Jordnaer.E2E.Tests/AuthenticatedTests/ChatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,6 @@ namespace Jordnaer.E2E.Tests.AuthenticatedTests;
[Category(nameof(TestCategory.SkipInCi))]
public class ChatTests : BrowserTest
{
[Test]
public async Task Chat_Search_Should_Return_No_Results_When_Searching_For_Random_String()
{
var page = await SetUpFixture.Context.NewPageAsync();
await page.GotoAsync(TestConfiguration.Values.BaseUrl + "/chat");

// Search for user
await Expect(page.Locator("div").Filter(new LocatorFilterOptions
{
HasText = "Søg efter bruger"
}).Nth(2)).ToBeVisibleAsync();
await page.GetByRole(AriaRole.Textbox).ClickAsync();
await page.GetByRole(AriaRole.Textbox).FillAsync(Guid.NewGuid().ToString());
await Expect(page.GetByText("Ingen brugere fundet")).ToBeVisibleAsync();

await page.CloseAsync();
}

[Test]
public async Task Chat_Search_Should_Return_Niels_When_Searching_For_Niels()
{
Expand All @@ -39,7 +21,7 @@ public async Task Chat_Search_Should_Return_Niels_When_Searching_For_Niels()
// Search for user
await page.GetByRole(AriaRole.Textbox).ClickAsync();
await page.GetByRole(AriaRole.Textbox).FillAsync("Niels Pilgaard Grøndahl");
await Expect(page.GetByText("Niels Pilgaard Grøndahl")).ToBeVisibleAsync();
await Expect(page.GetByText("Niels Pilgaard Grøndahl").First).ToBeVisibleAsync();

await page.CloseAsync();
}
Expand All @@ -62,7 +44,9 @@ public async Task Chat_Should_Be_Able_To_Send_Messages()
// Send message
await page.Locator("#chat-message-input").ClickAsync();
await page.Locator("#chat-message-input").FillAsync("Dette er en test meddelelse.");
await page.GetByLabel("Icon Button").ClickAsync();

// Click send icon
await page.GetByRole(AriaRole.Button).Nth(2).ClickAsync();

// Assert message was sent
await Expect(page.GetByRole(AriaRole.Heading, new PageGetByRoleOptions
Expand Down Expand Up @@ -91,7 +75,9 @@ public async Task Chat_Should_Clear_The_Input_After_Message_Is_Sent()
// Send message
await page.Locator("#chat-message-input").ClickAsync();
await page.Locator("#chat-message-input").FillAsync("Dette er en test meddelelse.");
await page.GetByLabel("Icon Button").ClickAsync();

// Click send icon
await page.GetByRole(AriaRole.Button).Nth(2).ClickAsync();

// Assert message input is now empty
await Expect(page.Locator("#chat-message-input")).ToBeEmptyAsync();
Expand Down
72 changes: 0 additions & 72 deletions tests/web/Jordnaer.E2E.Tests/AuthenticatedTests/SidebarTests.cs

This file was deleted.

34 changes: 0 additions & 34 deletions tests/web/Jordnaer.E2E.Tests/GroupSearchTests.cs

This file was deleted.

49 changes: 0 additions & 49 deletions tests/web/Jordnaer.E2E.Tests/Infrastructure/ConfigurationValues.cs

This file was deleted.

48 changes: 48 additions & 0 deletions tests/web/Jordnaer.E2E.Tests/Infrastructure/TestConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
using Microsoft.Extensions.Configuration;

namespace Jordnaer.E2E.Tests.Infrastructure;

public static class TestConfiguration
{
// ReSharper disable once InconsistentNaming
private static readonly Lazy<ConfigurationValues> _configuration = new(() => new ConfigurationValues());
public static readonly ConfigurationValues Values = _configuration.Value;
}

public class ConfigurationValues
{
public ConfigurationValues()
{
var configurationBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true)
.AddUserSecrets<ConfigurationValues>()
.AddEnvironmentVariables();

IConfiguration configuration = configurationBuilder.Build();

BaseUrl = (configuration["Playwright_BaseUrl"] ?? "https://localhost:7116").TrimEnd('/');
_username = configuration["Playwright_Username"];
_password = configuration["Playwright_Password"];
Device = configuration["Playwright_Device"];
Browser = configuration["Playwright_Browser"] ?? "Chromium";
Headless = configuration["Playwright_Headless"]?
.Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase)
?? true;

if (!float.TryParse(configuration["Playwright_SlowMo"], out var slowMo))
{
slowMo = 0;
}

SlowMo = slowMo;
}

public string Browser { get; }
public string BaseUrl { get; }
public string? Device { get; }
public bool Headless { get; }
public float? SlowMo { get; }

private readonly string? _username;
public string TestUserName => string.IsNullOrEmpty(_username)
? throw new InvalidOperationException("Test user name is not set")
: _username;

private readonly string? _password;

public string TestUserPassword => string.IsNullOrEmpty(_password)
? throw new InvalidOperationException("Test user password is not set")
: _password;
}
32 changes: 1 addition & 31 deletions tests/web/Jordnaer.E2E.Tests/LoginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task When_User_Goes_To_Login_External_Provider_Login_Is_Visible(str
public async Task When_User_Goes_To_Login_Links_Are_Visible(string linkTextRegex)
{
var page = await SetUpFixture.Browser.NewPageAsync(Playwright, false);

await page.GotoAsync(TestConfiguration.Values.BaseUrl);
await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Log ind" }).ClickAsync();

Expand All @@ -51,35 +52,4 @@ public async Task When_User_Goes_To_Login_Links_Are_Visible(string linkTextRegex

await page.CloseAsync();
}

[Test]
public async Task When_User_Goes_To_Login_Topbar_Menu_Should_Be_Clickable_And_Have_Links()
{
var page = await SetUpFixture.Browser.NewPageAsync(Playwright, false);

await page.GotoAsync(TestConfiguration.Values.BaseUrl);
await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Log ind" }).ClickAsync();

await Expect(page.GetByRole(AriaRole.Banner).GetByRole(AriaRole.Button)).ToBeVisibleAsync();
await Expect(page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Personer" }))
.ToBeVisibleAsync();
await Expect(page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Grupper", Exact = true }))
.ToBeVisibleAsync();

await page.CloseAsync();
}

[Test]
public async Task When_User_Goes_To_Login_Topbar_Logo_Should_Be_Visible()
{
var page = await SetUpFixture.Browser.NewPageAsync(Playwright, false);

await page.GotoAsync(TestConfiguration.Values.BaseUrl);
await page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Log ind" }).ClickAsync();

await Expect(page.GetByRole(AriaRole.Link, new PageGetByRoleOptions { Name = "Logo" }))
.ToBeVisibleAsync();

await page.CloseAsync();
}
}
Loading

0 comments on commit 1266de1

Please sign in to comment.