Add Cypress Testing Library (#10446)

This commit is contained in:
Michael Weimann
2023-03-29 08:47:05 +02:00
committed by GitHub
parent 6eda1fa6e2
commit 7cb90d0f78
7 changed files with 123 additions and 12 deletions

View File

@@ -18,6 +18,7 @@ limitations under the License.
import "@percy/cypress";
import "cypress-real-events";
import "@testing-library/cypress/add-commands";
import "./homeserver";
import "./login";
@@ -37,3 +38,4 @@ import "./network";
import "./composer";
import "./proxy";
import "./axe";
import "./find";

70
cypress/support/find.ts Normal file
View File

@@ -0,0 +1,70 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// <reference types="cypress" />
import Chainable = Cypress.Chainable;
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
/**
* Finds an element with the role "button".
*
* @param name - accessible name of the element to find
*/
findButton(name: string): Chainable<JQuery>;
/**
* Finds an element with the role "textbox".
*
* @param name - accessible name of the element to find
*/
findTextbox(name: string): Chainable<JQuery>;
/**
* Finds an element with the role "option".
*
* @param name - accessible name of the element to find
*/
findOption(name: string): Chainable<JQuery>;
/**
* Finds an element with the role "menuitem".
*
* @param name - accessible name of the element to find
*/
findMenuitem(name: string): Chainable<JQuery>;
}
}
}
Cypress.Commands.add("findButton", (name: string): Chainable<JQuery> => {
return cy.findByRole("button", { name });
});
Cypress.Commands.add("findTextbox", (name: string): Chainable<JQuery> => {
return cy.findByRole("textbox", { name });
});
Cypress.Commands.add("findOption", (name: string): Chainable<JQuery> => {
return cy.findByRole("option", { name });
});
Cypress.Commands.add("findMenuitem", (name: string): Chainable<JQuery> => {
return cy.findByRole("menuitem", { name });
});
// Needed to make this file a module
export {};