Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class TaxonomyHelper {
  private get _baseRootSelector() {
    return ".taxonomy";
  }
 
  public selectors = {
    root: this._baseRootSelector,
    selected: ".htx-taxonomy-selected",
    input: ".htx-taxonomy",
    dropdown: "[class^=taxonomy__dropdown]",
    item: "[class^=taxonomy__item]",
    open: '[class*="taxonomy_open--"]',
    closed: ':not([class*="taxonomy_open--"])',
  };
 
  private _new_selectors = {
    root: this._baseRootSelector,
    selected: ".ant-select-selector",
    input: ".htx-taxonomy",
    dropdown: ".ant-select-dropdown",
    item: ".ant-select-tree-treenode",
    open: ".ant-select-open",
    closed: ":not(.ant-select-open)",
  };
 
  public isNew = false;
 
  constructor(rootSelector, isNew = false) {
    if (isNew) this.selectors = this._new_selectors;
    this.selectors.root = rootSelector.replace(/^\&/, this._baseRootSelector);
    this.isNew = isNew;
  }
 
  get root() {
    return cy.get(this.selectors.root);
  }
 
  get selected() {
    return this.root.find(this.selectors.selected);
  }
 
  get input() {
    return this.root.find(this.selectors.input);
  }
  get dropdown() {
    return this.isNew ? cy.get(this.selectors.dropdown) : this.root.find(this.selectors.dropdown);
  }
  findItem(text) {
    return this.dropdown.contains(this.selectors.item, text).scrollIntoView();
  }
  hasSelected(text) {
    return this.selected.contains("div", text).should("exist");
  }
  hasNoSelected(text) {
    return this.selected.contains("div", text).should("not.exist");
  }
  open() {
    this.input.filter(this.selectors.closed).click();
  }
  close() {
    this.input.filter(this.selectors.open).click();
  }
}
 
const Taxonomy = new TaxonomyHelper("&:eq(0)");
const useTaxonomy = (rootSelector: string, isNew = false) => {
  return new TaxonomyHelper(rootSelector, isNew);
};
 
export { Taxonomy, useTaxonomy };