YamlImportPom.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. public class YamlImportPom(IPage page) {
  4. // -------------------------------------------------
  5. // Input
  6. // -------------------------------------------------
  7. /// <summary>
  8. /// The YAML textarea carries no test id, so it is addressed by its
  9. /// placeholder. It binds on oninput and recomputes the diff after each
  10. /// change, so filling it is enough to render the preview.
  11. /// </summary>
  12. public ILocator Input
  13. => page.GetByPlaceholder("Paste YAML here...");
  14. public ILocator ApplyButton
  15. => page.GetByRole(AriaRole.Button, new PageGetByRoleOptions { Name = "Apply" });
  16. // -------------------------------------------------
  17. // Errors
  18. // -------------------------------------------------
  19. public ILocator Error
  20. => page.GetByTestId("yaml-import-error");
  21. public ILocator ErrorSnippet
  22. => page.GetByTestId("yaml-import-error-snippet");
  23. // -------------------------------------------------
  24. // Connections preview (issue #308)
  25. // -------------------------------------------------
  26. public ILocator ConnectionsSummary
  27. => page.GetByTestId("import-connections-summary");
  28. public ILocator ConnectionsAdded
  29. => page.GetByTestId("import-connection-added");
  30. public ILocator ConnectionsRemoved
  31. => page.GetByTestId("import-connection-removed");
  32. // -------------------------------------------------
  33. // High-Level Actions
  34. // -------------------------------------------------
  35. public async Task GotoAsync(string baseUrl) {
  36. await page.GotoAsync($"{baseUrl}/yaml/import");
  37. await Assertions.Expect(Input).ToBeVisibleAsync();
  38. // Never type into the prerendered page: input events are lost before the
  39. // circuit attaches, so the oninput diff never runs and Apply stays disabled.
  40. // Same race the Add form hit (b8f6d23) — wait for the live circuit first.
  41. await Assertions.Expect(page.GetByTestId("circuit-probe"))
  42. .ToHaveAttributeAsync("data-circuit-ready", "true");
  43. }
  44. public async Task PasteAsync(string yaml)
  45. => await Input.FillAsync(yaml);
  46. public async Task ApplyAsync() {
  47. await Assertions.Expect(ApplyButton).ToBeEnabledAsync();
  48. await ApplyButton.ClickAsync();
  49. }
  50. public async Task AssertNoErrorAsync()
  51. => await Assertions.Expect(Error).ToHaveCountAsync(0);
  52. public async Task AssertErrorShownAsync()
  53. => await Assertions.Expect(Error).ToBeVisibleAsync();
  54. public async Task AssertConnectionsSummaryVisibleAsync()
  55. => await Assertions.Expect(ConnectionsSummary).ToBeVisibleAsync();
  56. public async Task AssertConnectionAddedContainsAsync(string text)
  57. => await Assertions.Expect(ConnectionsAdded.First).ToContainTextAsync(text);
  58. }