Update device-management.spec.ts - use Cypress Testing Library (#10585)

Signed-off-by: Suguru Hirahara <luixxiul@users.noreply.github.com>
This commit is contained in:
Suguru Hirahara 2023-04-12 15:58:28 +00:00 committed by GitHub
parent c5de595e79
commit 9b8459e8e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,74 +48,94 @@ describe("Device manager", () => {
it("should display sessions", () => { it("should display sessions", () => {
cy.openUserSettings("Sessions"); cy.openUserSettings("Sessions");
cy.contains("Current session").should("exist"); cy.findByText("Current session").should("exist");
cy.get('[data-testid="current-session-section"]').within(() => { cy.findByTestId("current-session-section").within(() => {
cy.contains("Unverified session").should("exist"); cy.findByText("Unverified session").should("exist");
// current session details opened
cy.findByRole("button", { name: "Show details" }).click();
cy.findByText("Session details").should("exist");
// close current session details
cy.findByRole("button", { name: "Hide details" }).click();
cy.findByText("Session details").should("not.exist");
}); });
// current session details opened cy.findByTestId("security-recommendations-section").within(() => {
cy.get('[data-testid="current-session-toggle-details"]').click(); cy.findByText("Security recommendations").should("exist");
cy.contains("Session details").should("exist"); cy.findByRole("button", { name: "View all (3)" }).click();
// close current session details
cy.get('[data-testid="current-session-toggle-details"]').click();
cy.contains("Session details").should("not.exist");
cy.get('[data-testid="security-recommendations-section"]').within(() => {
cy.contains("Security recommendations").should("exist");
cy.get('[data-testid="unverified-devices-cta"]').should("have.text", "View all (3)").click();
}); });
/** /**
* Other sessions section * Other sessions section
*/ */
cy.contains("Other sessions").should("exist"); cy.findByText("Other sessions").should("exist");
// filter applied after clicking through from security recommendations // filter applied after clicking through from security recommendations
cy.get('[aria-label="Filter devices"]').should("have.text", "Show: Unverified"); cy.findByLabelText("Filter devices").should("have.text", "Show: Unverified");
cy.get(".mx_FilteredDeviceList_list").find(".mx_FilteredDeviceList_listItem").should("have.length", 3); cy.get(".mx_FilteredDeviceList_list").within(() => {
cy.get(".mx_FilteredDeviceList_listItem").should("have.length", 3);
// select two sessions // select two sessions
cy.get(".mx_FilteredDeviceList_list .mx_FilteredDeviceList_listItem .mx_Checkbox").first().click(); cy.get(".mx_FilteredDeviceList_listItem")
cy.get(".mx_FilteredDeviceList_list .mx_FilteredDeviceList_listItem .mx_Checkbox").last().click(); .first()
.within(() => {
// force click as the input element itself is not visible (its size is zero)
cy.findByRole("checkbox").click({ force: true });
});
cy.get(".mx_FilteredDeviceList_listItem")
.last()
.within(() => {
// force click as the input element itself is not visible (its size is zero)
cy.findByRole("checkbox").click({ force: true });
});
});
// sign out from list selection action buttons // sign out from list selection action buttons
cy.get('[data-testid="sign-out-selection-cta"]').click(); cy.findByRole("button", { name: "Sign out" }).click();
cy.get('[data-testid="dialog-primary-button"]').click(); cy.get(".mx_Dialog .mx_QuestionDialog").within(() => {
cy.findByRole("button", { name: "Sign out" }).click();
});
// list updated after sign out // list updated after sign out
cy.get(".mx_FilteredDeviceList_list").find(".mx_FilteredDeviceList_listItem").should("have.length", 1); cy.get(".mx_FilteredDeviceList_list").find(".mx_FilteredDeviceList_listItem").should("have.length", 1);
// security recommendation count updated // security recommendation count updated
cy.get('[data-testid="unverified-devices-cta"]').should("have.text", "View all (1)"); cy.findByRole("button", { name: "View all (1)" });
const sessionName = `Alice's device`; const sessionName = `Alice's device`;
// open the first session // open the first session
cy.get(".mx_FilteredDeviceList_list .mx_FilteredDeviceList_listItem") cy.get(".mx_FilteredDeviceList_list .mx_FilteredDeviceList_listItem")
.first() .first()
.within(() => { .within(() => {
cy.get('[aria-label="Show details"]').click(); cy.findByRole("button", { name: "Show details" }).click();
cy.contains("Session details").should("exist"); cy.findByText("Session details").should("exist");
cy.get('[data-testid="device-heading-rename-cta"]').click(); cy.findByRole("button", { name: "Rename" }).click();
cy.get('[data-testid="device-rename-input"]').type(sessionName); cy.findByTestId("device-rename-input").type(sessionName);
cy.get('[data-testid="device-rename-submit-cta"]').click(); cy.findByRole("button", { name: "Save" }).click();
// there should be a spinner while device updates // there should be a spinner while device updates
cy.get(".mx_Spinner").should("exist"); cy.get(".mx_Spinner").should("exist");
// wait for spinner to complete // wait for spinner to complete
cy.get(".mx_Spinner").should("not.exist"); cy.get(".mx_Spinner").should("not.exist");
// session name updated in details // session name updated in details
cy.get(".mx_DeviceDetailHeading h4").should("have.text", sessionName); cy.get(".mx_DeviceDetailHeading h4").within(() => {
cy.findByText(sessionName);
});
// and main list item // and main list item
cy.get(".mx_DeviceTile h4").should("have.text", sessionName); cy.get(".mx_DeviceTile h4").within(() => {
cy.findByText(sessionName);
});
// sign out using the device details sign out // sign out using the device details sign out
cy.get('[data-testid="device-detail-sign-out-cta"]').click(); cy.findByRole("button", { name: "Sign out of this session" }).click();
}); });
// confirm the signout // confirm the signout
cy.get('[data-testid="dialog-primary-button"]').click(); cy.get(".mx_Dialog .mx_QuestionDialog").within(() => {
cy.findByRole("button", { name: "Sign out" }).click();
});
// no other sessions or security recommendations sections when only one session // no other sessions or security recommendations sections when only one session
cy.contains("Other sessions").should("not.exist"); cy.findByText("Other sessions").should("not.exist");
cy.get('[data-testid="security-recommendations-section"]').should("not.exist"); cy.findByTestId("security-recommendations-section").should("not.exist");
}); });
}); });