Skip to content

feat(cypress-commands): add clearUi5Input to cypress commands #4980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/cypress-commands/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ declare global {
* @example cy.get('[ui5-input]').typeIntoUi5Input('Hello World');
*/
typeIntoUi5Input(text: string, options?: Partial<TypeOptions>): Chainable<Element>;
/**
* Clears a value from ui5-webcomponent that offers a typeable input field.
*
* @example cy.get('[ui5-input]').clearUi5Input();
*/
clearUi5Input(options?: Partial<ClearOptions>): Chainable<Element>;
/**
* Types a value with a delay into an ui5-webcomponent that offers a typeable input field.
*
Expand Down Expand Up @@ -69,6 +75,12 @@ Cypress.Commands.add('typeIntoUi5Input', { prevSubject: 'element' }, (subject, t
.type(text, { force: true, ...options });
});

Cypress.Commands.add('clearUi5Input', { prevSubject: 'element' }, (subject, text, options = {}) => {
cy.wrap(subject)
.findShadowInput()
.clear({ force: true, ...options });
});

Cypress.Commands.add(
'typeIntoUi5InputWithDelay',
{ prevSubject: 'element' },
Expand Down
6 changes: 6 additions & 0 deletions packages/cypress-commands/test/UI5WebComponentsChild.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ describe('UI5 Web Components - Child Commands', () => {
cy.findByTestId('input').should('have.attr', 'value', 'Hello World!');
});

it('clearUi5Input', () => {
cy.mount(<Input data-testId={'input'} value="Hello World" />);
cy.findByTestId('input').clearUi5Input();
cy.findByTestId('input').should('have.attr', 'value', '');
});

it('typeIntoUi5TextArea', () => {
cy.mount(<TextArea data-testId="textArea" />);

Expand Down