Skip to content

Commit

Permalink
Merge branch 'main' into #827-Playwright-Test---Stappen-Nieuwswerkins…
Browse files Browse the repository at this point in the history
…tructies-Skills-Filter
  • Loading branch information
felixcicatt committed Dec 16, 2024
2 parents 2abbfb4 + 10e2b13 commit 3c2de0f
Showing 1 changed file with 29 additions and 45 deletions.
74 changes: 29 additions & 45 deletions Kiss.Bff.EndToEndTest/NieuwsEnWerkInstructies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,8 @@ public async Task Als_ik_een_oud_bericht_update_komt_deze_bovenaan()
public async Task Als_ik_een_belangrijk_bericht_publiceer_komt_deze_bovenaan()
{
var titel = $"End to end test {Guid.NewGuid()}";
int initialFeatureCount = 0; // Initialize count

// Declare featuredIndicator outside the try block so it's accessible throughout the method
var featuredIndicator = Page.Locator(".featured-indicator");

try
{
// Step 1: Get the initial featured indicator count (if visible)
if (await featuredIndicator.IsVisibleAsync())
{
var featureText = await featuredIndicator.TextContentAsync();
if (int.TryParse(featureText, out var count))
{
initialFeatureCount = count;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error fetching initial featured count: {ex.Message}");
}
// Step 1: Get the initial featured indicator count
var initialFeatureCount = await GetFeaturedCount();

// Step 2: Create a new important message
await CreateBericht(titel, true, "");
Expand All @@ -221,46 +202,49 @@ public async Task Als_ik_een_belangrijk_bericht_publiceer_komt_deze_bovenaan()
// Step 4: Check if the newly created important message appears at the top
var firstArticle = NieuwsSection.GetByRole(AriaRole.Article).First;
await Expect(firstArticle).ToContainTextAsync(titel);
await Expect(firstArticle).ToContainTextAsync("Belangrijk"); // Check for "Belangrijk" tag

// Step 5: Ensure the featured indicator is now visible and check the updated count
await Expect(featuredIndicator).ToBeVisibleAsync();
var isBelangrijk = await firstArticle.Locator(".featured").IsVisibleAsync();

// Step 6: Validate that the featured count is now at least 1 or higher than the initial count
var updatedFeatureText = await featuredIndicator.TextContentAsync();
if (int.TryParse(updatedFeatureText, out var updatedCount))
// Ensure the first article contains "Belangrijk" only if it's supposed to
if (isBelangrijk)
{
Assert.IsTrue(updatedCount >= initialFeatureCount + 1, $"Expected featured count to be at least {initialFeatureCount + 1}, but got {updatedCount}");
await Expect(firstArticle.Locator(".featured")).ToContainTextAsync("Belangrijk");
}
else
{
Assert.Fail("Featured indicator did not update with a valid number.");
Console.WriteLine("This article does not contain the 'Belangrijk' tag.");
}

// Step 7: Mark the article as read
await firstArticle.GetByRole(AriaRole.Button, new() { Name = "Markeer als gelezen" }).ClickAsync();
// Step 5: Get the new featured count
var updatedCount = await GetFeaturedCount();
Assert.IsTrue(updatedCount >= initialFeatureCount + 1, $"Expected featured count to be at least {initialFeatureCount + 1}, but got {updatedCount}");

// Step 8: Wait for the response related to the featured count update
await Page.WaitForResponseAsync(x => x.Url.Contains("featuredcount"));
// Step 6: Mark the article as read
await firstArticle.GetByRole(AriaRole.Button, new() { Name = "Markeer als gelezen" }).ClickAsync();

// Step 9: Validate that the featured count is now back to the initial count
var reUpdatedFeatureText = await featuredIndicator.TextContentAsync();
if (int.TryParse(reUpdatedFeatureText, out var reUpdatedCount))
{
Assert.IsTrue(reUpdatedCount == initialFeatureCount, $"Expected featured count to be equal to the initial count again, but instead got {reUpdatedCount}");
}
else
{
Assert.Fail("Featured indicator did not update with a valid number.");
}
// Step 7: Validate that the featured count is now back to the initial count
var reUpdatedCount = await GetFeaturedCount();
Assert.IsTrue(reUpdatedCount == initialFeatureCount, $"Expected featured count to be equal to the initial count {initialFeatureCount} again, but instead got {reUpdatedCount}");
}
finally
{
// Step 10: Clean up by deleting the created message
// Step 8: Clean up by deleting the created message
await DeleteBericht(titel);
}
}

private async Task<int> GetFeaturedCount()
{
// Declare featuredIndicator outside the try block so it's accessible throughout the method
var featuredIndicator = Page.Locator(".featured-indicator");
await Page.WaitForResponseAsync(x => x.Url.Contains("featuredcount"));
if (await featuredIndicator.IsVisibleAsync())
{
var featureText = await featuredIndicator.TextContentAsync();
return int.Parse(featureText!);
}
return 0;
}


// This test covers Step 12. 13. 14.
[TestMethod]
Expand Down

0 comments on commit 3c2de0f

Please sign in to comment.