AtOutliner.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. const { centerOfBbox } = require("../tests/helpers");
  2. const { I } = inject();
  3. module.exports = {
  4. _rootSelector: ".lsf-outliner",
  5. _regionListSelector: ".lsf-outliner-tree",
  6. _regionListItemSelector: ".lsf-tree__node:not(.lsf-tree__node_type_footer)",
  7. _regionListItemSelectedSelector: ".lsf-tree-node-selected",
  8. _regionListItemIndex: ".lsf-outliner-item__index",
  9. _regionVesibilityActionButton: ".lsf-outliner-item__control_type_visibility button",
  10. _incompleteStateIcon: ".lsf-outliner-item__incomplete",
  11. locateOutliner() {
  12. return locate(this._rootSelector);
  13. },
  14. locate(locator) {
  15. return locator ? locate(locator).inside(this.locateOutliner()) : this.locateOutliner();
  16. },
  17. locateRegionList() {
  18. return this.locate(this._regionListSelector);
  19. },
  20. locateRegionItemList(text) {
  21. if (text) {
  22. return locate(this._regionListItemSelector).withText(text).inside(this.locateRegionList());
  23. }
  24. return locate(this._regionListItemSelector).inside(this.locateRegionList());
  25. },
  26. locateRegionItemIndex(idx) {
  27. return locate(this._regionListItemIndex).withText(`${idx}`).inside(this.locateRegionItemList());
  28. },
  29. locateRegionIndex(idx) {
  30. return this.locateRegionItemList().withDescendant(
  31. `${locate(this._regionListItemIndex).toXPath()}[text()='${idx}']`,
  32. );
  33. },
  34. locateSelectedItem(locator) {
  35. const selectedLocator = locate(this._regionListItemSelectedSelector).inside(this.locateRegionList());
  36. return locator ? selectedLocator.find(locator) : selectedLocator;
  37. },
  38. locateRegion(idxOrText) {
  39. return typeof idxOrText === "number" ? this.locateRegionItemIndex(idxOrText) : this.locateRegionItemList(idxOrText);
  40. },
  41. locateIncompleteStateIcon(idxOrText) {
  42. if (idxOrText === undefined) {
  43. return locate(this._incompleteStateIcon).inside(this.locateRegionList());
  44. }
  45. return locate(this._incompleteStateIcon).inside(this.locateRegion(idxOrText));
  46. },
  47. see(text) {
  48. I.see(text, this._regionListSelector);
  49. },
  50. dontSee(text) {
  51. I.dontSee(text, this._regionListSelector);
  52. },
  53. seeElement(locator) {
  54. I.seeElement(this.locate(locator));
  55. },
  56. seeRegions(count) {
  57. // Avoid tries to find a region when there are 0 of them
  58. count && I.seeElement(this.locateRegionItemIndex(count));
  59. I.dontSeeElement(this.locateRegionItemIndex(count + 1));
  60. },
  61. dontSeeRegions(count) {
  62. count && I.dontSeeElement(this.locateRegionItemList().at(count));
  63. count === +count && I.dontSeeElement(this.locateRegionItemIndex(count));
  64. !count && I.see("Labeled regions will appear here");
  65. },
  66. clickRegion(idxOrText) {
  67. I.click(this.locateRegion(idxOrText));
  68. },
  69. hoverRegion(idxOrText) {
  70. I.moveCursorTo(this.locateRegion(idxOrText));
  71. },
  72. toggleRegionVisibility(idxOrText) {
  73. // Hover to see action button
  74. this.hoverRegion(idxOrText);
  75. // This button exist only for hovered list item
  76. I.click(locate(this._regionVesibilityActionButton));
  77. },
  78. seeSelectedRegion(text = undefined) {
  79. I.seeElement(text ? this.locateSelectedItem().withText(text) : this.locateSelectedItem());
  80. },
  81. dontSeeSelectedRegion(text = undefined) {
  82. I.dontSeeElement(text ? this.locateSelectedItem().withText(text) : this.locateSelectedItem());
  83. },
  84. /**
  85. * Verifies that the incomplete state icon is visible in a region list or for the specific region.
  86. *
  87. * @param {number|string} [idxOrText] - The index or text reference used to locate the region that should contain incomplete state icon.
  88. * Otherwise, it tries to find any.
  89. * @return {void} This method does not return any value.
  90. */
  91. seeIncompleteRegion(idxOrText) {
  92. I.seeElement(this.locateIncompleteStateIcon(idxOrText));
  93. },
  94. /**
  95. * Verifies that the incomplete state icon is not visible in a region list or for the specific region.
  96. *
  97. * @param {number|string} [idxOrText] - The index or text reference used to locate the region that should contain incomplete state icon.
  98. * Otherwise, it tries to find any.
  99. * @return {void} This method does not return any value.
  100. */
  101. dontSeeIncompleteRegion(idxOrText) {
  102. I.dontSeeElement(this.locateIncompleteStateIcon(idxOrText));
  103. },
  104. /**
  105. * Drag and drop region through the outliner's regions tree
  106. * @param {number} dragRegionIdx - Index of the dragged region
  107. * @param {number} dropRegionIdx - Index of the region that will be a drop zone
  108. * @param {number} [steps=3] - Sends intermediate mousemove events.
  109. * @returns {Promise<void>}
  110. */
  111. async dragAndDropRegion(dragRegionIdx, dropRegionIdx, steps = 3) {
  112. const fromBbox = await I.grabElementBoundingRect(this.locateRegionItemIndex(dragRegionIdx));
  113. const toBbox = await I.grabElementBoundingRect(this.locateRegionItemIndex(dropRegionIdx));
  114. const fromPoint = centerOfBbox(fromBbox);
  115. const toPoint = {
  116. x: toBbox.x + toBbox.width / 2,
  117. y: toBbox.y + (3 * toBbox.height) / 4,
  118. };
  119. return await I.dragAndDropMouse(fromPoint, toPoint, "left", steps);
  120. },
  121. };