ServicesListPom.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. public class ServicesListPom {
  4. private readonly IPage _page;
  5. public ServicesListPom(IPage page) {
  6. _page = page;
  7. }
  8. // -------------------------------------------------
  9. // Root & State
  10. // -------------------------------------------------
  11. public ILocator PageRoot => _page.GetByTestId("services-page-root");
  12. public ILocator PageTitle => _page.GetByTestId("services-page-title");
  13. public ILocator Loading => _page.GetByTestId("services-loading");
  14. public ILocator EmptyState => _page.GetByTestId("services-empty");
  15. public ILocator ServicesList => _page.GetByTestId("services-list");
  16. // -------------------------------------------------
  17. // Add Service Component (Reusable Component Object)
  18. // -------------------------------------------------
  19. public AddResourceComponent AddService => new(_page, "service");
  20. // -------------------------------------------------
  21. // Grouping (RunsOn)
  22. // -------------------------------------------------
  23. public ILocator Group(string groupKey) => _page.GetByTestId($"services-group-{SanitizeGroup(groupKey)}");
  24. public ILocator GroupTitle(string groupKey) => _page.GetByTestId($"services-group-title-{SanitizeGroup(groupKey)}");
  25. public ILocator GroupList(string groupKey) => _page.GetByTestId($"services-group-list-{SanitizeGroup(groupKey)}");
  26. // -------------------------------------------------
  27. // Individual Services
  28. // -------------------------------------------------
  29. public ILocator ServiceListItem(string name) => _page.GetByTestId($"services-list-item-{Sanitize(name)}");
  30. public ILocator ServiceCard(string name) => _page.GetByTestId($"service-item-{Sanitize(name)}");
  31. public ILocator DeleteButton(string name) => ServiceCard(name).GetByTestId("delete-service-button");
  32. public ILocator EditButton(string name) => ServiceCard(name).GetByTestId("edit-service-button");
  33. public ILocator RenameButton(string name) => ServiceCard(name).GetByTestId("rename-service-button");
  34. public ILocator CloneButton(string name) => ServiceCard(name).GetByTestId("clone-service-button");
  35. // -------------------------------------------------
  36. // Navigation
  37. // -------------------------------------------------
  38. public async Task GotoAsync(string baseUrl) {
  39. await _page.GotoAsync($"{baseUrl}/services/list");
  40. await AssertLoadedAsync();
  41. }
  42. public async Task AssertLoadedAsync() {
  43. await Assertions.Expect(PageRoot).ToBeVisibleAsync();
  44. await Assertions.Expect(PageTitle).ToBeVisibleAsync();
  45. }
  46. public async Task WaitForListAsync() => await Assertions.Expect(ServicesList).ToBeVisibleAsync();
  47. public async Task AssertEmptyAsync() => await Assertions.Expect(EmptyState).ToBeVisibleAsync();
  48. // -------------------------------------------------
  49. // Actions
  50. // -------------------------------------------------
  51. public async Task AddServiceAsync(string name) {
  52. await AddService.AddAsync(name);
  53. await Assertions.Expect(ServiceCard(name))
  54. .ToBeVisibleAsync();
  55. }
  56. public async Task DeleteServiceAsync(string name) {
  57. await DeleteButton(name).ClickAsync();
  58. await _page.GetByTestId("service-delete-confirm-modal-confirm")
  59. .ClickAsync();
  60. await Assertions.Expect(ServiceCard(name))
  61. .Not.ToBeVisibleAsync();
  62. }
  63. public async Task OpenServiceAsync(string name) {
  64. await ServiceCard(name).ClickAsync();
  65. await _page.WaitForURLAsync($"**/resources/services/{name}");
  66. }
  67. // -------------------------------------------------
  68. // Assertions
  69. // -------------------------------------------------
  70. public async Task AssertServiceExists(string name) {
  71. await Assertions.Expect(ServiceCard(name))
  72. .ToBeVisibleAsync();
  73. }
  74. public async Task AssertServiceDoesNotExist(string name) {
  75. await Assertions.Expect(ServiceCard(name))
  76. .Not.ToBeVisibleAsync();
  77. }
  78. public async Task AssertGroupExists(string groupKey) {
  79. await Assertions.Expect(Group(groupKey))
  80. .ToBeVisibleAsync();
  81. }
  82. public async Task AssertServiceInGroup(string groupKey, string serviceName) {
  83. await Assertions.Expect(
  84. GroupList(groupKey)
  85. .GetByTestId($"services-list-item-{Sanitize(serviceName)}")
  86. )
  87. .ToBeVisibleAsync();
  88. }
  89. // -------------------------------------------------
  90. // Utilities
  91. // -------------------------------------------------
  92. private static string Sanitize(string value) => value.Replace(" ", "-");
  93. private static string SanitizeGroup(string? value) {
  94. return string.IsNullOrWhiteSpace(value)
  95. ? "unassigned"
  96. : value.Replace(" ", "-");
  97. }
  98. }