YamlImportPom.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  39. public async Task PasteAsync(string yaml)
  40. => await Input.FillAsync(yaml);
  41. public async Task ApplyAsync() {
  42. await Assertions.Expect(ApplyButton).ToBeEnabledAsync();
  43. await ApplyButton.ClickAsync();
  44. }
  45. public async Task AssertNoErrorAsync()
  46. => await Assertions.Expect(Error).ToHaveCountAsync(0);
  47. public async Task AssertErrorShownAsync()
  48. => await Assertions.Expect(Error).ToBeVisibleAsync();
  49. public async Task AssertConnectionsSummaryVisibleAsync()
  50. => await Assertions.Expect(ConnectionsSummary).ToBeVisibleAsync();
  51. public async Task AssertConnectionAddedContainsAsync(string text)
  52. => await Assertions.Expect(ConnectionsAdded.First).ToContainTextAsync(text);
  53. }