AtTaxonomy.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const { I } = inject();
  2. class Taxonomy {
  3. rootBase = '//div[contains(concat(" ", @class, " "), " taxonomy ")]'; // [./child::*[class*="taxonomy--"]]
  4. input = '[class*="taxonomy--"]';
  5. selectedList = '[class*="taxonomy__selected"]';
  6. item = '[class*="taxonomy__item"]';
  7. group = '[class*="taxonomy__grouping"]';
  8. search = '[class*="taxonomy__search"]';
  9. newItemField = '[name="taxonomy__add"]';
  10. itemActions = '[class*="taxonomy__extra_actions"]';
  11. constructor(config = {}) {
  12. if (config.index) {
  13. this.root = `.${this.rootBase}${[config.index]}`;
  14. } else if (config.selector) {
  15. this.root = `${config.selector}${this.rootBase}`;
  16. } else {
  17. this.root = `.${this.rootBase}`;
  18. }
  19. }
  20. locateTaxonomy() {
  21. return locate(this.root);
  22. }
  23. locate(locator) {
  24. return locator ? locate(locator).inside(this.locateTaxonomy()) : this.locateTaxonomy();
  25. }
  26. locateInput() {
  27. return this.locate(this.input);
  28. }
  29. locateItemByText(itemText) {
  30. return this.locate(this.item).withDescendant(`.//label[text()='${itemText}']`);
  31. }
  32. locateSelectedByText(itemText) {
  33. return this.locate(this.selectedList).find("./div").withDescendant(`.//*[text()='${itemText}']`);
  34. }
  35. locateActions(itemLocator) {
  36. let actionsLocator = this.locate(this.itemActions);
  37. if (itemLocator) {
  38. actionsLocator = actionsLocator.inside(itemLocator);
  39. }
  40. return actionsLocator;
  41. }
  42. seeTaxonomy() {
  43. I.seeElement(this.locateInput());
  44. }
  45. dontSeeTaxonomy() {
  46. I.dontSeeElement(this.locateInput());
  47. }
  48. clickTaxonomy() {
  49. I.click(this.locateInput());
  50. }
  51. toggleGroupWithText(text) {
  52. I.click(this.locate(this.group).inside(this.locateItemByText(text)));
  53. }
  54. fillSearch(text) {
  55. I.fillField(this.locate(this.search), text);
  56. }
  57. seeItemByText(itemText) {
  58. I.seeElement(this.locateItemByText(itemText));
  59. }
  60. dontSeeItemByText(itemText) {
  61. I.dontSeeElement(this.locateItemByText(itemText));
  62. }
  63. seeCheckedItemByText(itemText) {
  64. I.seeElement(this.locateItemByText(itemText).withDescendant(".//input[@checked]"));
  65. }
  66. dontSeeCheckedItemByText(itemText) {
  67. I.dontSeeElement(this.locateItemByText(itemText).withDescendant(".//input[@checked]"));
  68. }
  69. seeSelectedValues(selectedValues) {
  70. if (!Array.isArray(selectedValues)) {
  71. selectedValues = [selectedValues];
  72. }
  73. for (const value of selectedValues) {
  74. I.seeElement(this.locateSelectedByText(value));
  75. }
  76. }
  77. dontSeeSelectedValues(selectedValues) {
  78. if (!Array.isArray(selectedValues)) {
  79. selectedValues = [selectedValues];
  80. }
  81. for (const value of selectedValues) {
  82. I.dontSeeElement(this.locateSelectedByText(value));
  83. }
  84. }
  85. clickItem(itemLocator) {
  86. I.click(itemLocator);
  87. }
  88. clickItemByText(itemText) {
  89. this.clickItem(this.locateItemByText(itemText));
  90. }
  91. clickAdd() {
  92. I.click(this.locate("button").withText("Add"));
  93. }
  94. fillNewItem(value) {
  95. I.fillField(this.locate(this.newItemField), value);
  96. I.pressKey("Enter");
  97. }
  98. addNewItem(value) {
  99. this.clickAdd();
  100. this.fillNewItem(value);
  101. }
  102. addItemInside(value, itemLocator) {
  103. this.expandItemMenu(itemLocator);
  104. this.clickAddInside();
  105. this.fillNewItem(value);
  106. }
  107. deleteItem(itemLocator) {
  108. this.expandItemMenu(itemLocator);
  109. this.clickDelete();
  110. }
  111. expandItemMenu(itemLocator) {
  112. const toggleLocator = this.locateActions(itemLocator);
  113. I.moveCursorTo(toggleLocator, 5, 5);
  114. I.click(toggleLocator);
  115. }
  116. clickAddInside() {
  117. I.click(locate(".ant-dropdown-menu-item").withText("Add Inside"));
  118. }
  119. clickDelete() {
  120. I.click(locate(".ant-dropdown-menu-item").withText("Delete"));
  121. }
  122. }
  123. module.exports = new Taxonomy();
  124. /**
  125. * Create AtTaxonomy with specific root selector
  126. * @param {number} index - can be selector or just an index
  127. * @returns {AtTaxonomy}
  128. */
  129. module.exports.useTaxonomyAt = (index) => {
  130. return new Taxonomy({ index });
  131. };
  132. /**
  133. * Create AtTaxonomy with specific root selector
  134. * @param {string} selector - selector of an ancestor element
  135. * @returns {AtTaxonomy}
  136. */
  137. module.exports.useTaxonomyInside = (selector) => {
  138. return new Taxonomy({ selector });
  139. };