ConnectionModalPom.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. /// <summary>
  4. /// Drives PortConnectionModal, wherever it is mounted.
  5. /// The modal builds its test ids from its TestIdPrefix parameter, which
  6. /// differs by host: a resource card passes "{kind}-ports-port-group", while
  7. /// the global /connections page passes plain "connections". This POM is
  8. /// keyed on that base so both can share one implementation.
  9. /// </summary>
  10. public class ConnectionModalPom(IPage page, string baseTestId) {
  11. private string Id(string suffix) => $"{baseTestId}-connection-modal-{suffix}";
  12. public ILocator Container => page.GetByTestId(Id("container"));
  13. public ILocator ResourceASelect => page.GetByTestId(Id("resource-a"));
  14. public ILocator GroupASelect => page.GetByTestId(Id("group-a"));
  15. public ILocator PortASelect => page.GetByTestId(Id("port-a"));
  16. public ILocator ResourceBSelect => page.GetByTestId(Id("resource-b"));
  17. public ILocator GroupBSelect => page.GetByTestId(Id("group-b"));
  18. public ILocator PortBSelect => page.GetByTestId(Id("port-b"));
  19. public ILocator LabelInput => page.GetByTestId(Id("label"));
  20. public ILocator SubmitButton => page.GetByTestId(Id("submit"));
  21. public ILocator CancelButton => page.GetByTestId(Id("cancel"));
  22. // -------------------------------------------------
  23. // Assertions
  24. // -------------------------------------------------
  25. public async Task AssertOpenAsync()
  26. => await Assertions.Expect(Container).ToBeVisibleAsync();
  27. /// <summary>
  28. /// The modal is wrapped in an @if, so when closed it is absent from the
  29. /// DOM rather than merely hidden.
  30. /// </summary>
  31. public async Task AssertClosedAsync()
  32. => await Assertions.Expect(Container).ToHaveCountAsync(0);
  33. // -------------------------------------------------
  34. // Actions
  35. // -------------------------------------------------
  36. public async Task CreateConnectionAsync(
  37. string resourceA,
  38. string groupA,
  39. string portA,
  40. string resourceB,
  41. string groupB,
  42. string portB,
  43. string? label = null) {
  44. await ResourceASelect.SelectOptionAsync(new SelectOptionValue { Label = resourceA });
  45. await GroupASelect.SelectOptionAsync(new SelectOptionValue { Label = groupA });
  46. await PortASelect.SelectOptionAsync(new SelectOptionValue { Label = portA });
  47. await ResourceBSelect.SelectOptionAsync(new SelectOptionValue { Label = resourceB });
  48. await GroupBSelect.SelectOptionAsync(new SelectOptionValue { Label = groupB });
  49. await PortBSelect.SelectOptionAsync(new SelectOptionValue { Label = portB });
  50. if (label is not null)
  51. await LabelInput.FillAsync(label);
  52. await SubmitButton.ClickAsync();
  53. }
  54. public async Task CancelAsync()
  55. => await CancelButton.ClickAsync();
  56. // -------------------------------------------------
  57. // Option label formats, as rendered by PortConnectionModal
  58. // -------------------------------------------------
  59. public static string GroupLabel(string type, string speed, int count)
  60. => $"{type} — {speed} Gbps ({count})";
  61. public static string PortLabel(int oneBasedIndex)
  62. => $"Port {oneBasedIndex}";
  63. }