Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJosipovic committed May 28, 2024
1 parent ca7f275 commit aa9a468
Showing 1 changed file with 109 additions and 3 deletions.
112 changes: 109 additions & 3 deletions tests/BlazorApplicationInsights.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ public async Task Test(string id, int timeout, List<AIRequestObject> expectedCal
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

Expand All @@ -485,6 +486,7 @@ public async Task Test(string id, int timeout, List<AIRequestObject> expectedCal
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

Expand Down Expand Up @@ -520,7 +522,7 @@ public async Task Test(string id, int timeout, List<AIRequestObject> expectedCal
}
}

hasError.Should().Be(false);
hasError.Should().BeFalse();
validCalls.Should().Be(expectedCalls.Count);
}

Expand Down Expand Up @@ -619,6 +621,7 @@ public async Task TestBlocked(string id)
if (e.Type == "error" && e.Text != "Failed to load resource: net::ERR_FAILED" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

Expand All @@ -633,6 +636,7 @@ public async Task TestBlocked(string id)
e.Url != "https://localhost:5001/_framework/blazor-hotreload")
{
hasError = true;
output.WriteLine(e.Url);
}
};

Expand All @@ -647,11 +651,31 @@ public async Task TestBlocked(string id)
[Fact]
public async Task GetUserId_ShouldReturnAGeneratedValue_WhenNotSet()
{
bool hasError = false;

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = Headless });
var page = await browser.NewPageAsync(new BrowserNewPageOptions() { IgnoreHTTPSErrors = true });

page.Console += (sender, e) =>
{
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

page.RequestFailed += (sender, e) =>
{
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

await page.GotoAsync(BaseAddress);
await page.ClickAsync("#GetUserId");

Expand All @@ -660,16 +684,37 @@ public async Task GetUserId_ShouldReturnAGeneratedValue_WhenNotSet()
var userId = (await page.Locator("#UserId").AllInnerTextsAsync()).FirstOrDefault();

userId.Should().NotBeNullOrEmpty();
hasError.Should().BeFalse();
}

[Fact]
public async Task GetUserId_ShouldReturnSetUserId_WhenSet()
{
bool hasError = false;

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = Headless });
var page = await browser.NewPageAsync(new BrowserNewPageOptions() { IgnoreHTTPSErrors = true });

page.Console += (sender, e) =>
{
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

page.RequestFailed += (sender, e) =>
{
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

await page.GotoAsync(BaseAddress);
await page.ClickAsync("#SetAuthenticatedUserContext");

Expand All @@ -681,16 +726,36 @@ public async Task GetUserId_ShouldReturnSetUserId_WhenSet()
var userId = (await page.Locator("#UserId").AllInnerTextsAsync()).FirstOrDefault();

userId.Should().Be("myUserId");
hasError.Should().BeFalse();
}

[Fact]
public async Task GetSessionId_ShouldReturnAGeneratedValue()
{
bool hasError = false;
using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = Headless });
var page = await browser.NewPageAsync(new BrowserNewPageOptions() { IgnoreHTTPSErrors = true });

page.Console += (sender, e) =>
{
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

page.RequestFailed += (sender, e) =>
{
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

await page.GotoAsync(BaseAddress);
await page.ClickAsync("#GetSessionId");

Expand All @@ -699,16 +764,37 @@ public async Task GetSessionId_ShouldReturnAGeneratedValue()
var sessionId = (await page.Locator("#SessionId").AllInnerTextsAsync()).FirstOrDefault();

sessionId.Should().NotBeNullOrEmpty();
hasError.Should().BeFalse();
}

[Fact]
public async Task SetCookiesEnabled_False_ShouldDisableCookies()
{
bool hasError = false;

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = Headless });
var page = await browser.NewPageAsync(new BrowserNewPageOptions() { IgnoreHTTPSErrors = true });

page.Console += (sender, e) =>
{
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

page.RequestFailed += (sender, e) =>
{
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

await page.GotoAsync(BaseAddress);
await page.ClickAsync("#DisableCookies");

Expand All @@ -718,17 +804,37 @@ public async Task SetCookiesEnabled_False_ShouldDisableCookies()
var enabled = (await page.Locator("#CookiesEnabled").AllInnerTextsAsync()).FirstOrDefault();

enabled.Should().Be("False");
hasError.Should().BeFalse();
}


[Fact]
public async Task SetCookiesEnabled_True_ShouldEnableCookies()
{
bool hasError = false;

using var playwright = await Playwright.CreateAsync();

await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions() { Headless = Headless });
var page = await browser.NewPageAsync(new BrowserNewPageOptions() { IgnoreHTTPSErrors = true });

page.Console += (sender, e) =>
{
if (e.Type == "error" && !e.Text.Contains("Something wrong happened :("))
{
hasError = true;
output.WriteLine(e.Text);
}
};

page.RequestFailed += (sender, e) =>
{
if (!e.Url.Equals("https://localhost:5001/_framework/blazor-hotreload"))
{
hasError = true;
output.WriteLine(e.Url);
}
};

await page.GotoAsync(BaseAddress);
await page.ClickAsync("#DisableCookies");
await page.WaitForTimeoutAsync(1000);
Expand All @@ -740,7 +846,7 @@ public async Task SetCookiesEnabled_True_ShouldEnableCookies()
var enabled = (await page.Locator("#CookiesEnabled").AllInnerTextsAsync()).FirstOrDefault();

enabled.Should().Be("True");
hasError.Should().BeFalse();
}

}
}

0 comments on commit aa9a468

Please sign in to comment.