4
0

DesktopCardPom.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using Microsoft.Playwright;
  2. namespace Tests.E2e.PageObjectModels;
  3. public class DesktopCardPom(IPage page) {
  4. public TagsPom Tags => new(page);
  5. public LabelsPom Labels => new(page);
  6. // -------------------------------------------------
  7. // Modals
  8. // -------------------------------------------------
  9. // ConfirmModal TestIdPrefix="Desktop" => "Desktop-confirm-modal-*"
  10. public ILocator DeleteConfirmModal => page.GetByTestId("Desktop-confirm-modal");
  11. public ILocator DeleteConfirmButton => page.GetByTestId("Desktop-confirm-modal-confirm");
  12. public ILocator DeleteCancelButton => page.GetByTestId("Desktop-confirm-modal-cancel");
  13. // StringValueModal prefixes you set:
  14. // desktop-rename => "desktop-rename-string-value-modal-*"
  15. public ILocator RenameModal => page.GetByTestId("desktop-rename-string-value-modal");
  16. public ILocator RenameModalInput => page.GetByTestId("desktop-rename-string-value-modal-input");
  17. public ILocator RenameModalAccept => page.GetByTestId("desktop-rename-string-value-modal-submit");
  18. public ILocator RenameModalCancel => page.GetByTestId("desktop-rename-string-value-modal-cancel");
  19. // desktop-clone => "desktop-clone-string-value-modal-*"
  20. public ILocator CloneModal => page.GetByTestId("desktop-clone-string-value-modal");
  21. public ILocator CloneModalInput => page.GetByTestId("desktop-clone-string-value-modal-input");
  22. public ILocator CloneModalAccept => page.GetByTestId("desktop-clone-string-value-modal-submit");
  23. public ILocator CloneModalCancel => page.GetByTestId("desktop-clone-string-value-modal-cancel");
  24. // -------------------------------------------------
  25. // Root + Navigation
  26. // -------------------------------------------------
  27. public ILocator DesktopItem(string name)
  28. => page.GetByTestId($"desktop-item-{Sanitize(name)}");
  29. public ILocator OpenDesktopLink(string name)
  30. => page.GetByTestId($"desktop-item-{Sanitize(name)}-link");
  31. public async Task OpenDesktopAsync(string name) {
  32. await OpenDesktopLink(name).ClickAsync();
  33. await page.WaitForURLAsync($"**/resources/hardware/{name}");
  34. }
  35. // -------------------------------------------------
  36. // Header actions
  37. // -------------------------------------------------
  38. public ILocator RenameButton(string name)
  39. => DesktopItem(name).GetByTestId("rename-desktop-button");
  40. public ILocator CloneButton(string name)
  41. => DesktopItem(name).GetByTestId("clone-desktop-button");
  42. public ILocator DeleteButton(string name)
  43. => DesktopItem(name).GetByTestId("delete-desktop-button");
  44. public ILocator ModelBadge(string name)
  45. => DesktopItem(name).GetByTestId("desktop-model-badge");
  46. // -------------------------------------------------
  47. // CPU section
  48. // -------------------------------------------------
  49. public ILocator CpuSection(string name)
  50. => DesktopItem(name).GetByTestId("desktop-cpu-section");
  51. public ILocator AddCpuButton(string name)
  52. => DesktopItem(name).GetByTestId("add-cpu-button");
  53. public ILocator EditCpuButton(string name, string cpuToString)
  54. => DesktopItem(name).GetByTestId($"edit-cpu-{Sanitize(cpuToString)}");
  55. // -------------------------------------------------
  56. // RAM section
  57. // -------------------------------------------------
  58. public ILocator RamSection(string name)
  59. => DesktopItem(name).GetByTestId("desktop-ram-section");
  60. public ILocator EditRamButton(string name)
  61. => DesktopItem(name).GetByTestId("edit-ram-button");
  62. public ILocator RamValueButton(string name)
  63. => DesktopItem(name).GetByTestId("ram-value-button");
  64. // -------------------------------------------------
  65. // Drive section
  66. // -------------------------------------------------
  67. public ILocator DriveSection(string name)
  68. => DesktopItem(name).GetByTestId("desktop-drive-section");
  69. public ILocator AddDriveButton(string name)
  70. => DesktopItem(name).GetByTestId("add-drive-button");
  71. public ILocator EditDriveButton(string name, string type, int size)
  72. => DesktopItem(name).GetByTestId($"edit-drive-{type}-{size}");
  73. // -------------------------------------------------
  74. // NIC section
  75. // -------------------------------------------------
  76. public ILocator NicSection(string name)
  77. => DesktopItem(name).GetByTestId("desktop-nic-section");
  78. public ILocator AddNicButton(string name)
  79. => DesktopItem(name).GetByTestId("add-nic-button");
  80. public ILocator EditNicButton(string name, string type, double speed)
  81. => DesktopItem(name).GetByTestId($"edit-nic-{type}-{speed}");
  82. // -------------------------------------------------
  83. // GPU section
  84. // -------------------------------------------------
  85. public ILocator GpuSection(string name)
  86. => DesktopItem(name).GetByTestId("desktop-gpu-section");
  87. public ILocator AddGpuButton(string name)
  88. => DesktopItem(name).GetByTestId("add-gpu-button");
  89. public ILocator EditGpuButton(string name, string model, int vram)
  90. => DesktopItem(name).GetByTestId($"edit-gpu-{model}-{vram}");
  91. // -------------------------------------------------
  92. // Notes (MarkdownViewer/MarkdownEditor use prefixes)
  93. // -------------------------------------------------
  94. public ILocator NotesSection(string name)
  95. => DesktopItem(name).GetByTestId("desktop-notes-section");
  96. // MarkdownViewer (TestIdPrefix="desktop-notes-viewer")
  97. public ILocator NotesViewerRoot(string name)
  98. => DesktopItem(name).GetByTestId("desktop-notes-viewer-markdown-viewer");
  99. public ILocator NotesViewerEditButton(string name)
  100. => DesktopItem(name).GetByTestId("desktop-notes-viewer-markdown-viewer-edit-button");
  101. // MarkdownEditor (TestIdPrefix="desktop-notes-editor")
  102. public ILocator NotesEditorRoot(string name)
  103. => DesktopItem(name).GetByTestId("desktop-notes-editor-markdown-editor");
  104. public ILocator NotesEditorTextarea(string name)
  105. => DesktopItem(name).GetByTestId("desktop-notes-editor-markdown-editor-textarea");
  106. public ILocator NotesEditorSave(string name)
  107. => DesktopItem(name).GetByTestId("desktop-notes-editor-markdown-editor-save");
  108. public ILocator NotesEditorCancel(string name)
  109. => DesktopItem(name).GetByTestId("desktop-notes-editor-markdown-editor-cancel");
  110. // -------------------------------------------------
  111. // Actions helpers
  112. // -------------------------------------------------
  113. public async Task DeleteDesktopAsync(string name) {
  114. await DeleteButton(name).ClickAsync();
  115. await Assertions.Expect(DeleteConfirmModal).ToBeVisibleAsync();
  116. await DeleteConfirmButton.ClickAsync();
  117. await Assertions.Expect(DesktopItem(name)).Not.ToBeVisibleAsync();
  118. }
  119. public async Task RenameDesktopAsync(string currentName, string newName) {
  120. await RenameButton(currentName).ClickAsync();
  121. await Assertions.Expect(RenameModal).ToBeVisibleAsync();
  122. await RenameModalInput.FillAsync(newName);
  123. await RenameModalAccept.ClickAsync();
  124. await page.WaitForURLAsync($"**/resources/hardware/{newName}");
  125. }
  126. public async Task CloneDesktopAsync(string currentName, string cloneName) {
  127. await CloneButton(currentName).ClickAsync();
  128. await Assertions.Expect(CloneModal).ToBeVisibleAsync();
  129. await CloneModalInput.FillAsync(cloneName);
  130. await CloneModalAccept.ClickAsync();
  131. await page.WaitForURLAsync($"**/resources/hardware/{cloneName}");
  132. }
  133. private static string Sanitize(string value)
  134. => value.Replace(" ", "-");
  135. }