| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using Microsoft.Playwright;
- using Tests.E2e.Infra;
- using Tests.E2e.PageObjectModels;
- using Xunit.Abstractions;
- namespace Tests.E2e;
- /// <summary>
- /// Coverage for the two read-only overview pages, /subnets and /visualise.
- /// Both derive entirely from the resources in the config, so the tests
- /// create what they assert on. Kept in one class so they share a container.
- /// </summary>
- public class SubnetAndVisualiseTests(
- PlaywrightFixture fixture,
- ITestOutputHelper output) : E2ETestBase(fixture, output) {
- private readonly PlaywrightFixture _fixture = fixture;
- private readonly ITestOutputHelper _output = output;
- // =============================================================
- // Subnet browser
- // =============================================================
- [Fact]
- public async Task Subnet_Browser_Groups_A_System_Under_Its_Slash_24() {
- (IBrowserContext context, IPage page) = await CreatePageAsync();
- var name = $"e2e-sn-{Guid.NewGuid():N}"[..14];
- const string ip = "10.99.4.17";
- const string subnet = "10.99.4.x";
- try {
- await CreateSystemWithIpAsync(page, name, ip);
- await page.GotoAsync($"{_fixture.BaseUrl}/subnets");
- var subnets = new SubnetBrowserPom(page);
- await subnets.AssertLoadedAsync();
- await subnets.AssertGroupVisibleAsync(subnet);
- await subnets.AssertGroupContainsAsync(subnet, ip);
- await subnets.AssertGroupContainsAsync(subnet, name);
- }
- catch (Exception) {
- await DumpAsync(page);
- throw;
- }
- finally {
- await context.CloseAsync();
- }
- }
- [Fact]
- public async Task Subnet_Browser_Filter_Narrows_And_Can_Match_Nothing() {
- (IBrowserContext context, IPage page) = await CreatePageAsync();
- var name = $"e2e-sf-{Guid.NewGuid():N}"[..14];
- const string ip = "10.88.3.9";
- const string subnet = "10.88.3.x";
- try {
- await CreateSystemWithIpAsync(page, name, ip);
- await page.GotoAsync($"{_fixture.BaseUrl}/subnets");
- var subnets = new SubnetBrowserPom(page);
- await subnets.AssertLoadedAsync();
- await subnets.AssertGroupVisibleAsync(subnet);
- // A matching prefix keeps the group.
- await subnets.FilterAsync("10.88.3");
- await subnets.AssertGroupVisibleAsync(subnet);
- // A subnet nothing lives in falls through to the empty state.
- await subnets.FilterAsync("203.0.113");
- await subnets.AssertEmptyAsync();
- }
- catch (Exception) {
- await DumpAsync(page);
- throw;
- }
- finally {
- await context.CloseAsync();
- }
- }
- // =============================================================
- // Visualise
- // =============================================================
- [Fact]
- public async Task User_Can_Switch_Between_Visualise_Views() {
- (IBrowserContext context, IPage page) = await CreatePageAsync();
- try {
- await page.GotoAsync($"{_fixture.BaseUrl}/visualise");
- var visualise = new VisualisePom(page);
- await visualise.AssertLoadedAsync();
- await visualise.SelectLogicalAsync();
- await visualise.AssertLoadedAsync();
- await visualise.SelectTopologyAsync();
- await visualise.AssertLoadedAsync();
- }
- catch (Exception) {
- await DumpAsync(page);
- throw;
- }
- finally {
- await context.CloseAsync();
- }
- }
- [Fact]
- public async Task Visualise_Deep_Links_Straight_To_A_View() {
- (IBrowserContext context, IPage page) = await CreatePageAsync();
- try {
- await page.GotoAsync($"{_fixture.BaseUrl}/visualise/logical");
- var visualise = new VisualisePom(page);
- await visualise.AssertLoadedAsync();
- }
- catch (Exception) {
- await DumpAsync(page);
- throw;
- }
- finally {
- await context.CloseAsync();
- }
- }
- // =============================================================
- // Helpers
- // =============================================================
- private async Task CreateSystemWithIpAsync(IPage page, string name, string ip) {
- await page.GotoAsync($"{_fixture.BaseUrl}/systems/list");
- var list = new SystemsListPom(page);
- await list.AssertLoadedAsync();
- await list.AddSystemAsync(name);
- if (!page.Url.Contains($"/resources/systems/{name}", StringComparison.OrdinalIgnoreCase))
- await list.OpenSystemAsync(name);
- var card = new SystemCardPom(page);
- await card.AssertVisibleAsync(name);
- await card.BeginEditAsync(name);
- await card.IpInput(name).FillAsync(ip);
- await card.SaveAsync(name);
- await Assertions.Expect(card.IpValue(name)).ToContainTextAsync(ip);
- }
- private async Task DumpAsync(IPage page) {
- _output.WriteLine("TEST FAILED — Capturing diagnostics");
- _output.WriteLine($"Current URL: {page.Url}");
- var html = await page.ContentAsync();
- _output.WriteLine("==== DOM SNAPSHOT START ====");
- _output.WriteLine(html);
- _output.WriteLine("==== DOM SNAPSHOT END ====");
- }
- }
|