Skip to content
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

feat(react): added tabbing and other interactions into cypress tests … #1685

Merged
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
1 change: 1 addition & 0 deletions packages/react/cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// <reference types="cypress" />

import "./component";
import "cypress-real-events";

import Commands from "./commands";

Expand Down
10 changes: 10 additions & 0 deletions packages/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"cypress-axe": "^1.5.0",
"cypress-file-upload": "^5.0.8",
"cypress-image-diff-js": "^2.1.3",
"cypress-real-events": "^1.12.0",
"eslint-plugin-cypress": "^2.15.1",
"mkdirp": "^1.0.4",
"np": "^7.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,32 @@ describe("IcAccordionGroup", () => {
<TwoAccordionsWithOneExpanded />
</IcAccordionGroup>
);
cy.checkHydrated(IC_ACCORDION_GROUP);

cy.get(getAccordionSelector(1))
.invoke("prop", "expanded")
.should("eq", false);
cy.get(getAccordionSelector(2))
.invoke("prop", "expanded")
.should("eq", true);

cy.get(getAccordionSelector(1)).click();
cy.findShadowEl(getAccordionSelector(1), "button")
.focus()
.realPress("Space");
cy.get(getAccordionSelector(1))
.invoke("prop", "expanded")
.should("eq", true);
cy.get(getAccordionSelector(2))
.invoke("prop", "expanded")
.should("eq", false);

cy.realPress("Tab").realPress("Space");
cy.get(getAccordionSelector(1))
.invoke("prop", "expanded")
.should("eq", false);
cy.get(getAccordionSelector(2))
.invoke("prop", "expanded")
.should("eq", true);
});

it("both accordions should open when single expansion is false", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
StaticSideNav,
checkSideNavSize,
} from "./IcSideNavigationTestData";
import _ from "cypress/types/lodash";

const DEFAULT_HEIGHT = 1171;
const DEFAULT_TEST_THRESHOLD = 0.06;
Expand Down Expand Up @@ -285,6 +286,18 @@ describe("IcSideNavigation", () => {
cy.checkSideNavSize(false);
});

it("expands when expand button is tabbed to and pressed", () => {
mount(<BasicSideNav />);
cy.checkHydrated(SIDE_NAV_LABEL);
cy.findShadowEl("ic-side-navigation", ".title-link").focus();
Cypress._.times(4, () => cy.realPress("Tab"));
cy.realPress("Enter");
cy.checkSideNavSize(true);

cy.clickOnShadowEl(SIDE_NAV_LABEL, EXPAND_BUTTON_SELECTOR);
cy.checkSideNavSize(false);
});

it("renders collapsed and expanded when expanded state is externally controlled", () => {
mount(<DynamicExpandedSideNav />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ describe("IcToggleButtonGroup", () => {
getToggle(1).click({ force: true });
cy.get(WIN_CONSOLE_SPY).should(NOT_HAVE_BEEN_CALLED);
});
it("should tab through toggles and check focus and selection state", () => {
mount(<ToggleGroupSingle />);
cy.checkHydrated(IC_TOGGLE_BUTTON_GROUP);

getToggle(2).focus().realPress(["Shift", "Tab"]);
cy.get(IC_TOGGLE_BUTTON_GROUP).should(HAVE_FOCUS);
});
});
describe("screenshots", () => {
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"noImplicitAny": true,
"jsx": "react",
"allowJs": true,
"types": ["cypress", "node", "cypress-axe", "cypress-file-upload"]
"types": ["cypress", "node", "cypress-axe", "cypress-file-upload", "cypress-real-events"]
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["**/__tests__/**", "cypress/**", "src/component-tests/**/*"],
Expand Down
Loading