Add Cypress Testing Library (#10446)
This commit is contained in:
@@ -20,8 +20,8 @@ import { HomeserverInstance } from "../../plugins/utils/homeserver";
|
||||
import Chainable = Cypress.Chainable;
|
||||
|
||||
function openCreateRoomDialog(): Chainable<JQuery<HTMLElement>> {
|
||||
cy.get('[aria-label="Add room"]').click();
|
||||
cy.get('.mx_ContextualMenu [aria-label="New room"]').click();
|
||||
cy.findButton("Add room").click();
|
||||
cy.findMenuitem("New room").click();
|
||||
return cy.get(".mx_CreateRoomDialog");
|
||||
}
|
||||
|
||||
@@ -46,20 +46,23 @@ describe("Create Room", () => {
|
||||
|
||||
openCreateRoomDialog().within(() => {
|
||||
// Fill name & topic
|
||||
cy.get('[label="Name"]').type(name);
|
||||
cy.get('[label="Topic (optional)"]').type(topic);
|
||||
cy.findTextbox("Name").type(name);
|
||||
cy.findTextbox("Topic (optional)").type(topic);
|
||||
// Change room to public
|
||||
cy.get('[aria-label="Room visibility"]').click();
|
||||
cy.get("#mx_JoinRuleDropdown__public").click();
|
||||
cy.findButton("Room visibility").click();
|
||||
cy.findOption("Public room").click();
|
||||
// Fill room address
|
||||
cy.get('[label="Room address"]').type("test-room-1");
|
||||
cy.findTextbox("Room address").type("test-room-1");
|
||||
// Submit
|
||||
cy.get(".mx_Dialog_primary").click();
|
||||
cy.findButton("Create room").click();
|
||||
});
|
||||
|
||||
cy.url().should("contain", "/#/room/#test-room-1:localhost");
|
||||
cy.contains(".mx_RoomHeader_nametext", name);
|
||||
cy.contains(".mx_RoomHeader_topic", topic);
|
||||
|
||||
cy.get(".mx_RoomHeader").within(() => {
|
||||
cy.findByText(name);
|
||||
cy.findByText(topic);
|
||||
});
|
||||
});
|
||||
|
||||
it("should create a room with a long room name, which is displayed with ellipsis", () => {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 {};
|
||||
@@ -3,7 +3,7 @@
|
||||
"target": "es2016",
|
||||
"jsx": "react",
|
||||
"lib": ["es2020", "dom", "dom.iterable"],
|
||||
"types": ["cypress", "cypress-axe", "@percy/cypress"],
|
||||
"types": ["cypress", "cypress-axe", "@percy/cypress", "@testing-library/cypress"],
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "node",
|
||||
|
||||
Reference in New Issue
Block a user