SubnetAndVisualiseTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using Microsoft.Playwright;
  2. using Tests.E2e.Infra;
  3. using Tests.E2e.PageObjectModels;
  4. using Xunit.Abstractions;
  5. namespace Tests.E2e;
  6. /// <summary>
  7. /// Coverage for the two read-only overview pages, /subnets and /visualise.
  8. /// Both derive entirely from the resources in the config, so the tests
  9. /// create what they assert on. Kept in one class so they share a container.
  10. /// </summary>
  11. public class SubnetAndVisualiseTests(
  12. PlaywrightFixture fixture,
  13. ITestOutputHelper output) : E2ETestBase(fixture, output) {
  14. private readonly PlaywrightFixture _fixture = fixture;
  15. private readonly ITestOutputHelper _output = output;
  16. // =============================================================
  17. // Subnet browser
  18. // =============================================================
  19. [Fact]
  20. public async Task Subnet_Browser_Groups_A_System_Under_Its_Slash_24() {
  21. (IBrowserContext context, IPage page) = await CreatePageAsync();
  22. var name = $"e2e-sn-{Guid.NewGuid():N}"[..14];
  23. const string ip = "10.99.4.17";
  24. const string subnet = "10.99.4.x";
  25. try {
  26. await CreateSystemWithIpAsync(page, name, ip);
  27. await page.GotoAsync($"{_fixture.BaseUrl}/subnets");
  28. var subnets = new SubnetBrowserPom(page);
  29. await subnets.AssertLoadedAsync();
  30. await subnets.AssertGroupVisibleAsync(subnet);
  31. await subnets.AssertGroupContainsAsync(subnet, ip);
  32. await subnets.AssertGroupContainsAsync(subnet, name);
  33. }
  34. catch (Exception) {
  35. await DumpAsync(page);
  36. throw;
  37. }
  38. finally {
  39. await context.CloseAsync();
  40. }
  41. }
  42. [Fact]
  43. public async Task Subnet_Browser_Filter_Narrows_And_Can_Match_Nothing() {
  44. (IBrowserContext context, IPage page) = await CreatePageAsync();
  45. var name = $"e2e-sf-{Guid.NewGuid():N}"[..14];
  46. const string ip = "10.88.3.9";
  47. const string subnet = "10.88.3.x";
  48. try {
  49. await CreateSystemWithIpAsync(page, name, ip);
  50. await page.GotoAsync($"{_fixture.BaseUrl}/subnets");
  51. var subnets = new SubnetBrowserPom(page);
  52. await subnets.AssertLoadedAsync();
  53. await subnets.AssertGroupVisibleAsync(subnet);
  54. // A matching prefix keeps the group.
  55. await subnets.FilterAsync("10.88.3");
  56. await subnets.AssertGroupVisibleAsync(subnet);
  57. // A subnet nothing lives in falls through to the empty state.
  58. await subnets.FilterAsync("203.0.113");
  59. await subnets.AssertEmptyAsync();
  60. }
  61. catch (Exception) {
  62. await DumpAsync(page);
  63. throw;
  64. }
  65. finally {
  66. await context.CloseAsync();
  67. }
  68. }
  69. // =============================================================
  70. // Visualise
  71. // =============================================================
  72. [Fact]
  73. public async Task User_Can_Switch_Between_Visualise_Views() {
  74. (IBrowserContext context, IPage page) = await CreatePageAsync();
  75. try {
  76. await page.GotoAsync($"{_fixture.BaseUrl}/visualise");
  77. var visualise = new VisualisePom(page);
  78. await visualise.AssertLoadedAsync();
  79. await visualise.SelectLogicalAsync();
  80. await visualise.AssertLoadedAsync();
  81. await visualise.SelectTopologyAsync();
  82. await visualise.AssertLoadedAsync();
  83. }
  84. catch (Exception) {
  85. await DumpAsync(page);
  86. throw;
  87. }
  88. finally {
  89. await context.CloseAsync();
  90. }
  91. }
  92. [Fact]
  93. public async Task Visualise_Deep_Links_Straight_To_A_View() {
  94. (IBrowserContext context, IPage page) = await CreatePageAsync();
  95. try {
  96. await page.GotoAsync($"{_fixture.BaseUrl}/visualise/logical");
  97. var visualise = new VisualisePom(page);
  98. await visualise.AssertLoadedAsync();
  99. }
  100. catch (Exception) {
  101. await DumpAsync(page);
  102. throw;
  103. }
  104. finally {
  105. await context.CloseAsync();
  106. }
  107. }
  108. // =============================================================
  109. // Helpers
  110. // =============================================================
  111. private async Task CreateSystemWithIpAsync(IPage page, string name, string ip) {
  112. await page.GotoAsync($"{_fixture.BaseUrl}/systems/list");
  113. var list = new SystemsListPom(page);
  114. await list.AssertLoadedAsync();
  115. await list.AddSystemAsync(name);
  116. if (!page.Url.Contains($"/resources/systems/{name}", StringComparison.OrdinalIgnoreCase))
  117. await list.OpenSystemAsync(name);
  118. var card = new SystemCardPom(page);
  119. await card.AssertVisibleAsync(name);
  120. await card.BeginEditAsync(name);
  121. await card.IpInput(name).FillAsync(ip);
  122. await card.SaveAsync(name);
  123. await Assertions.Expect(card.IpValue(name)).ToContainTextAsync(ip);
  124. }
  125. private async Task DumpAsync(IPage page) {
  126. _output.WriteLine("TEST FAILED — Capturing diagnostics");
  127. _output.WriteLine($"Current URL: {page.Url}");
  128. var html = await page.ContentAsync();
  129. _output.WriteLine("==== DOM SNAPSHOT START ====");
  130. _output.WriteLine(html);
  131. _output.WriteLine("==== DOM SNAPSHOT END ====");
  132. }
  133. }