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
71
72
73
class DateTimeHelper {
  private get _baseRootSelector() {
    return ".htx-datetime";
  }
 
  private _rootSelector: string;
 
  constructor(rootSelector) {
    this._rootSelector = rootSelector.replace(/^\&/, this._baseRootSelector);
  }
 
  get root() {
    return cy.get(this._rootSelector);
  }
 
  get dateInput() {
    return this.root.find('[type="date"]');
  }
 
  get timeInput() {
    return this.root.find('[type="time"]');
  }
 
  private _dateRegExp = /^\d{4}-\d{2}-\d{2}$/;
  private _timeRegExp = /^\d{2}:\d{2}$/;
  /**
   *
   * @param datetime accepts formats `YYYY-MM-DD`, `HH:mm`, `YYYY-MM-DDTHH:mm`, `YYYY-MM-DD HH:mm`, `YYYY-MM-DD, HH:mm`
   */
  type(datetime: string) {
    const parts = datetime
      .split(/[^\d\-:]/)
      .filter((value) => value.match(this._dateRegExp) || value.match(this._timeRegExp));
 
    cy.wrap(parts).should("have.lengthOf.at.least", 1);
 
    for (const value of parts) {
      if (value.match(this._dateRegExp)) {
        this.dateInput.type(value);
      }
      if (value.match(this._timeRegExp)) {
        this.timeInput.type(value);
      }
    }
  }
  /**
   *
   * @param datetime accepts formats `YYYY-MM-DD`, `HH:mm`, `YYYY-MM-DDTHH:mm`, `YYYY-MM-DD HH:mm`, `YYYY-MM-DD, HH:mm`
   */
  hasValue(datetime: string) {
    const parts = datetime
      .split(/[^\d\-:]/)
      .filter((value) => value.match(this._dateRegExp) || value.match(this._timeRegExp));
 
    cy.wrap(parts).should("have.lengthOf.at.least", 1);
 
    for (const value of parts) {
      if (value.match(this._dateRegExp)) {
        this.dateInput.should("have.value", value);
      }
      if (value.match(this._timeRegExp)) {
        this.timeInput.should("have.value", value);
      }
    }
  }
}
 
const DateTime = new DateTimeHelper("&:eq(0)");
const useDateTime = (rootSelector: string) => {
  return new DateTimeHelper(rootSelector);
};
 
export { DateTime, useDateTime };