AtDetails.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. const { I } = inject();
  2. /**
  3. * Helper to test different information displayed in Details panel,
  4. * like region labels, editable fields, meta info, etc.
  5. */
  6. module.exports = {
  7. _rootSelector: ".lsf-details",
  8. _labelSelector: ".lsf-detailed-region .lsf-labels-list span",
  9. _textSelector: ".lsf-region-meta__content_type_text",
  10. _editMetaSelector: '[aria-label="Edit region\'s meta"]',
  11. _editableFieldInput: ".lsf-region-editor__input",
  12. _editableFieldTitle: ".lsf-region-editor__text",
  13. _metaField: ".lsf-detailed-region__meta-text",
  14. _resultBlockSelector: ".lsf-detailed-region__result",
  15. _resultTitleSelector: ".ant-typography,[class*='typography-']",
  16. _resultValueSelector: ".lsf-region-meta__value",
  17. _sectionHeadSelector: ".lsf-details__section-head",
  18. locateDetailPanel() {
  19. return locate(this._rootSelector);
  20. },
  21. locate(locator) {
  22. return locator ? locate(locator).inside(this.locateDetailPanel()) : this.locateDetailPanel();
  23. },
  24. locateMeta() {
  25. return this.locate(this._metaField);
  26. },
  27. locateEditableField(field) {
  28. const title = this.locate(this._editableFieldTitle).withText(field);
  29. return this.locate(this._editableFieldInput).before(title);
  30. },
  31. locateResultBlock() {
  32. return this.locate(this._resultBlockSelector);
  33. },
  34. locateResultRating(rating) {
  35. const locator = this.locateResultBlock().withDescendant(locate(this._resultTitleSelector).withText("Rating"));
  36. if (typeof rating === "undefined") return locator;
  37. return locator.withDescendant(locate(this._resultValueSelector).withText(`${rating}`));
  38. },
  39. locateResultTextarea(text) {
  40. const locator = this.locateResultBlock().withDescendant(locate(this._resultTitleSelector).withText("Text"));
  41. if (typeof text === "undefined") return locator;
  42. if (!Array.isArray(text)) text = [text];
  43. for (const line of text) {
  44. locator.withDescendant(locate(this._resultValueSelector).withText(line));
  45. }
  46. return locator;
  47. },
  48. locateResultChoices(value) {
  49. const locator = this.locateResultBlock().withDescendant(locate(this._resultTitleSelector).withText("Choices"));
  50. if (typeof value === "undefined") return locator;
  51. if (!Array.isArray(value)) value = [value];
  52. return locator.withDescendant(locate(this._resultValueSelector).withText(value.join(", ")));
  53. },
  54. locateLabel(text) {
  55. return text ? locate(this._labelSelector).withText(`${text}`) : locate(this._labelSelector);
  56. },
  57. locateText(text) {
  58. return text ? locate(this._textSelector).withText(`${text}`) : locate(this._textSelector);
  59. },
  60. clickEditMeta() {
  61. I.click(this.locate(this._editMetaSelector));
  62. },
  63. fillMeta(text) {
  64. I.fillField(this.locateMeta(), text);
  65. },
  66. // can be not very precise: actual '82.1000003' will match value '82.1'
  67. seeFieldWithValue(field, value) {
  68. I.seeInField(this.locateEditableField(field), value);
  69. },
  70. seeMeta(text) {
  71. I.see(text, this.locateMeta());
  72. },
  73. dontSeeMeta(text) {
  74. I.dontSee(text, this.locateMeta());
  75. },
  76. clickMeta() {
  77. I.click(this.locateMeta());
  78. },
  79. seeLabel(text) {
  80. I.seeElement(this.locateLabel(text));
  81. },
  82. seeLabels(count) {
  83. count && I.seeElement(this.locateLabel().at(count));
  84. I.dontSeeElement(this.locateLabel().at(count + 1));
  85. },
  86. seeText(text) {
  87. I.seeElement(this.locateText(text));
  88. },
  89. seeResultRating(rating) {
  90. I.seeElement(this.locateResultRating(rating));
  91. },
  92. seeResultTextarea(text) {
  93. I.seeElement(this.locateResultTextarea(text));
  94. },
  95. seeResultChoices(value) {
  96. I.seeElement(this.locateResultChoices(value));
  97. },
  98. clickCreateRelation() {
  99. I.click(this.locate('[aria-label="Create Relation"]'));
  100. },
  101. clickDeleteRegion() {
  102. I.click(this.locate('[aria-label="Delete selected region"]'));
  103. },
  104. seeRelations(count) {
  105. I.seeElement(this.locate(this._sectionHeadSelector).withText(`Relations (${count})`));
  106. },
  107. };