AtParagraphs.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const { I } = inject();
  2. const Helpers = require("../tests/helpers");
  3. module.exports = {
  4. _rootSelector: ".lsf-paragraphs",
  5. _filterSelector: "button[data-testid*='select-trigger']",
  6. _phraseSelector: "[class^='phrase--']",
  7. _phraseDialoguetextSelector: "[class^='dialoguetext--']",
  8. getParagraphTextSelector(idx) {
  9. // Convert 1-based test index to 0-based data-testid index
  10. const zeroBasedIdx = idx - 1;
  11. return `[data-testid="phrase:${zeroBasedIdx}"] [class^='dialoguetext--']`;
  12. },
  13. selectTextByOffset(paragraphIdx, startOffset, endOffset) {
  14. I.executeScript(Helpers.selectText, {
  15. selector: this.getParagraphTextSelector(paragraphIdx),
  16. rangeStart: startOffset,
  17. rangeEnd: endOffset,
  18. });
  19. },
  20. setSelection(startLocator, startOffset, endLocator, endOffset) {
  21. I.setSelection(startLocator, startOffset, endLocator, endOffset);
  22. },
  23. locate(locator) {
  24. return locator ? locate(locator).inside(this.locateRoot()) : this.locateRoot();
  25. },
  26. locateRoot() {
  27. return locate(this._rootSelector);
  28. },
  29. locateText(text) {
  30. const locator = locate(
  31. `${this.locateRoot().toXPath()}//*[starts-with(@class,'phrase--')]//*[contains(@class,'text--')]//text()[contains(.,'${text}')]`,
  32. );
  33. return locator;
  34. },
  35. clickFilter(...authors) {
  36. // Open dropdown and wait for it to appear
  37. I.click(locate(this._filterSelector));
  38. I.waitTicks(1);
  39. // For the new select component, we need to select each author
  40. // and the dropdown is managed automatically
  41. for (const author of authors) {
  42. // We may or may not have a search field depending on number of options
  43. const hasSearchField = I.executeScript(() => {
  44. return !!document.querySelector("input[data-testid='select-search-field']");
  45. });
  46. if (hasSearchField) {
  47. // Try to search if field is available
  48. I.fillField(locate("input[data-testid='select-search-field']"), author);
  49. I.waitTicks(3);
  50. }
  51. // Select the author option
  52. I.click(locate(`div[data-testid='select-option-${author}']`));
  53. I.waitTicks(3);
  54. }
  55. // Close any open dropdown
  56. I.pressKey("Escape");
  57. I.waitTicks(3); // Wait for UI to update after filter change
  58. },
  59. // Select All button helpers
  60. seeSelectAllButton(index) {
  61. I.seeElement(`[data-testid="select-all-btn:${index}"]`);
  62. },
  63. clickSelectAllButton(index) {
  64. I.click(`[data-testid="select-all-btn:${index}"]`);
  65. },
  66. seeSelectAllButtonDisabled(index) {
  67. I.seeElement(`[data-testid="select-all-btn:${index}"][disabled]`);
  68. },
  69. dontSeeSelectAllButton(index) {
  70. I.dontSeeElement(`[data-testid="select-all-btn:${index}"]`);
  71. },
  72. };