• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / ui5-webcomponents-react / 9495457180

13 Jun 2024 07:23AM CUT coverage: 31.508% (-54.8%) from 86.282%
9495457180

Pull #5883

github

web-flow
Merge c3057fa50 into 7a27b7f0a
Pull Request #5883: fix(deps): update dependency @tanstack/react-virtual to v3.5.1

641 of 4086 branches covered (15.69%)

1973 of 6262 relevant lines covered (31.51%)

165.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/packages/cypress-commands/src/commands.ts
1
declare global {
2
  // eslint-disable-next-line @typescript-eslint/no-namespace
3
  namespace Cypress {
4
    interface Chainable {
5
      /**
6
       * Types a value into a ui5-webcomponent that offers a typeable input field.
7
       *
8
       * @param {string} text Text that will be typed into the input.
9
       * @example cy.get('[ui5-input]').typeIntoUi5Input('Hello World');
10
       */
11
      typeIntoUi5Input(text: string, options?: Partial<TypeOptions>): Chainable<Element>;
12
      /**
13
       * Clears a value from ui5-webcomponent that offers a typeable input field.
14
       *
15
       * @example cy.get('[ui5-input]').clearUi5Input();
16
       */
17
      clearUi5Input(options?: Partial<ClearOptions>): Chainable<Element>;
18
      /**
19
       * Types a value with a delay into an ui5-webcomponent that offers a typeable input field.
20
       *
21
       * __Note:__ Use this command if you render a component that should show suggestions while typing (e.g. `ComboBox`) but the corresponding popover does not open.
22
       * This command waits for the appropriate delay (in ms), giving the web component time to define all necessary customElements and boot web components.
23
       * The delay time can vary from environment to environment.
24
       *
25
       * @param {string} text Text that will be typed into the input.
26
       * @param {number} [delay=500] Delay in ms to wait for the web-component to be ready. Default: 500
27
       * @example cy.get('[ui5-combobox]').typeIntoUi5InputWithDelay('Hello World', 1000);
28
       */
29
      typeIntoUi5InputWithDelay(text: string, delay?: number, options?: Partial<TypeOptions>): Chainable<Element>;
30

31
      /**
32
       * Types a value into `ui5-textarea`.
33
       * @param {string} text Text that will be typed into the text-area.
34
       * @example cy.get('[ui5-textarea]').typeIntoUi5TextArea('Hello World');
35
       */
36
      typeIntoUi5TextArea(text: string, options?: Partial<TypeOptions>): Chainable<Element>;
37

38
      /**
39
       * Toggles the state of a `ui5-checkbox`.
40
       * @example cy.get('[ui5-checkbox]').toggleUi5Checkbox();
41
       */
42
      toggleUi5Checkbox(): Chainable<Element>;
43

44
      /**
45
       * Toggles the state of a `ui5-switch`
46
       * @example cy.get('[ui5-switch]').toggleUi5Switch();
47
       */
48
      toggleUi5Switch(): Chainable<Element>;
49

50
      /**
51
       * Click on a `ui5-radio-button`
52
       * @example cy.get('[ui5-radio-button]').clickUi5RadioButton();
53
       */
54
      clickUi5RadioButton(): Chainable<Element>;
55

56
      /**
57
       * Close ui5-webcomponents popups like `ui5-dialog` or `ui5-popover` by pressing the "Escape" key.
58
       * @example cy.closeUi5PopupWithEsc()
59
       */
60
      closeUi5PopupWithEsc(): Chainable<Element>;
61

62
      /**
63
       * Click on a list item of the `List` component by text.
64
       * @param {string} text The text of the list item that should be clicked.
65
       * @example cy.clickUi5ListItemByText("List Item")
66
       */
67
      clickUi5ListItemByText(text: string): Chainable<Element>;
68

69
      /**
70
       * Click on an `ui5-option` of the `ui5-select` component by text.
71
       *
72
       * __Note:__ The select popover must be visible, otherwise it can lead to unwanted side effects.
73
       *
74
       * @param text text of the ui5-option that should be clicked
75
       * @param options ClickOptions
76
       *
77
       *
78
       * @example cy.get('[ui5-select]').clickUi5SelectOptionByText('Option2');*
79
       */
80
      clickUi5SelectOptionByText(text: string, options?: Partial<ClickOptions>): Chainable<Element>;
81

82
      /**
83
       * Click on chained `ui5-option`.
84
       *
85
       * __Note:__ The select popover must be visible, otherwise it can lead to unwanted side effects.
86
       *
87
       * @deprecated: This command is deprecated. Please use `clickDropdownMenuItem` instead.
88
       *
89
       * @example cy.get('[ui5-option]').clickUi5SelectOption();
90
       */
91
      clickUi5SelectOption(options?: Partial<ClickOptions>): Chainable<Element>;
92

93
      /**
94
       * Click on an option of "select-like" components by text. Currently supported components are `ui5-select`, `ui5-combobox` and `ui5-multi-combobox`.
95
       *
96
       * __Note:__ The popover must be visible, otherwise it can lead to unwanted side effects.
97
       *
98
       * @param text text of the item inside the popover that should be clicked
99
       * @param options Cypress.ClickOptions
100
       * @example cy.get('[ui5-select]').clickDropdownMenuItemByText('Option2');
101
       *
102
       */
103
      clickDropdownMenuItemByText(text: string, options?: Partial<ClickOptions>): Chainable<Element>;
104

105
      /**
106
       * Click on a chained option of "select-like" components. Currently supported components are `ui5-option`, `ui5-mcb-item` and `ui5-cb-item` (since v1.24.3 of `@ui5/webcomponents`).
107
       *
108
       * __Note:__ The popover must be visible, otherwise it can lead to unwanted side effects.
109
       *
110
       * @example cy.get('[ui5-option]').clickDropdownMenuItem();
111
       */
112
      clickDropdownMenuItem(options?: Partial<ClickOptions>): Chainable<Element>;
113

114
      /**
115
       * Click on the open button in "select-like" components to open the popover. Currently supported components are `ui5-select`, `ui5-combobox` and `ui5-multi-combobox`.
116
       *
117
       * @example cy.get('[ui5-select]').openDropDownByClick();
118
       */
119
      openDropDownByClick(options?: Partial<ClickOptions>): Chainable<Element>;
120
    }
121
  }
122
}
123

124
Cypress.Commands.add('typeIntoUi5Input', { prevSubject: 'element' }, (subject, text, options = {}) => {
139✔
125
  cy.wrap(subject)
13✔
126
    .findShadowInput()
127
    .type(text, { force: true, ...options });
128
});
129

130
Cypress.Commands.add('clearUi5Input', { prevSubject: 'element' }, (subject, text, options = {}) => {
139✔
131
  cy.wrap(subject)
12✔
132
    .findShadowInput()
133
    .clear({ force: true, ...options });
134
});
135

136
Cypress.Commands.add(
139✔
137
  'typeIntoUi5InputWithDelay',
138
  { prevSubject: 'element' },
139
  (subject, text, delay = 500, options = {}) => {
22✔
140
    cy.wrap(subject)
11✔
141
      .findShadowInput()
142
      .wait(delay)
143
      .type(text, { force: true, ...options });
144
  }
145
);
146

147
Cypress.Commands.add('typeIntoUi5TextArea', { prevSubject: 'element' }, (subject, text, options = {}) => {
139✔
148
  cy.wrap(subject)
11✔
149
    .shadow()
150
    .find('textarea')
151
    .type(text, { force: true, ...options });
152
});
153

154
Cypress.Commands.add('toggleUi5Checkbox', { prevSubject: 'element' }, (subject) => {
139✔
155
  cy.wrap(subject).findShadowInput().click({ force: true });
10✔
156
});
157

158
Cypress.Commands.add('toggleUi5Switch', { prevSubject: 'element' }, (subject) => {
139✔
159
  cy.wrap(subject).findShadowInput().click({ force: true });
18✔
160
});
161

162
Cypress.Commands.add('clickUi5RadioButton', { prevSubject: 'element' }, (subject) => {
139✔
163
  cy.wrap(subject).findShadowInput().click({ force: true });
16✔
164
});
165

166
Cypress.Commands.add('closeUi5PopupWithEsc', () => {
139✔
167
  cy.get('body').type('{esc}', { force: true });
×
168
});
169

170
Cypress.Commands.add('clickUi5ListItemByText', (text) => {
139✔
171
  cy.contains(text).find('li').click({ force: true });
×
172
});
173

174
Cypress.Commands.add('clickUi5SelectOptionByText', { prevSubject: 'element' }, (subject, text, options = {}) => {
139✔
175
  cy.wrap(subject)
8✔
176
    .contains(text)
177
    .then(($option) => {
178
      $option.get(0).focus();
8✔
179
    })
180
    .click(options);
181
});
182

183
Cypress.Commands.add('clickUi5SelectOption', { prevSubject: 'element' }, (subject, options = {}) => {
139✔
184
  cy.wrap(subject).then(($option) => {
8✔
185
    // @ts-expect-error: cannot set $option to use OptionDomRef
186
    const domRef = $option.get(0).getDomRef();
8✔
187
    cy.wrap(domRef).click(options);
8✔
188
  });
189
});
190

191
Cypress.Commands.add('clickDropdownMenuItemByText', { prevSubject: 'element' }, (subject, text, options = {}) => {
139✔
192
  cy.wrap(subject)
6✔
193
    .find('[ui5-responsive-popover]')
194
    .then(($popover) => {
195
      cy.wrap($popover).should('have.attr', 'open');
6✔
196
      // necessary as otherwise focusing the ui5-li is flaky
197
      cy.wait(300);
6✔
198
      cy.wrap($popover)
6✔
199
        .contains(text)
200
        .then(($li) => {
201
          $li.get(0).focus();
6✔
202
          cy.wrap($li)
6✔
203
            .find('li')
204
            .click({ force: true, ...options });
205
        });
206
    });
207
});
208

209
Cypress.Commands.add('clickDropdownMenuItem', { prevSubject: 'element' }, (subject, options = {}) => {
139✔
210
  cy.wrap(subject).then(($option) => {
4✔
211
    // @ts-expect-error: ui5-webcomponent types are not bundled in
212
    const domRef = $option.get(0).getDomRef();
4✔
213
    cy.wrap(domRef)
4✔
214
      .find('li')
215
      .click({ force: true, ...options });
216
  });
217
});
218

219
Cypress.Commands.add('openDropDownByClick', { prevSubject: 'element' }, (subject, options = {}) => {
139✔
220
  if (subject.get(0).hasAttribute('ui5-multi-combobox')) {
10✔
221
    // mcb needs a lot of calculation time to make the popover available
222
    cy.wait(500);
5✔
223
  }
224
  cy.wrap(subject).shadow().find('.inputIcon').click(options);
10✔
225
});
226

227
export {};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc