Skip to content
Open
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
143 changes: 143 additions & 0 deletions packages/main/cypress/specs/Bar.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Bar from "../../src/Bar.js";
import Button from "../../src/Button.js";
import Input from "../../src/Input.js";

describe("Bar Accessibility", () => {
it("Should use accessibleName property as aria-label", () => {
Expand Down Expand Up @@ -64,4 +65,146 @@ describe("Bar Accessibility", () => {
.find(".ui5-bar-root")
.should("have.attr", "aria-label", "External Navigation Label");
});
});

describe("Bar Keyboard Navigation", () => {
it("ArrowRight moves focus forward through all three slots", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-mid">Middle</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-mid").should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-end").should("be.focused");
});

it("ArrowLeft moves focus backward", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-mid">Middle</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-mid").should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-end").should("be.focused");
cy.realPress("ArrowLeft");
cy.get("#btn-mid").should("be.focused");
cy.realPress("ArrowLeft");
cy.get("#btn-start").should("be.focused");
});

it("ArrowRight at last item does not move focus", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-end").should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-end").should("be.focused");
});

it("ArrowLeft at first item does not move focus", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("ArrowLeft");
cy.get("#btn-start").should("be.focused");
});

it("End key jumps to last focusable item", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-mid">Middle</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("End");
cy.get("#btn-end").should("be.focused");
});

it("Home key jumps to first focusable item", () => {
cy.mount(
<Bar>
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-mid">Middle</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("End");
cy.get("#btn-end").should("be.focused");
cy.realPress("Home");
cy.get("#btn-start").should("be.focused");
});

it("ArrowRight inside input with mid-text caret does not move focus", () => {
cy.mount(
<Bar>
<Input id="input-start" slot="startContent" value="hello"></Input>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#input-start").realClick();
// place caret at position 2 (middle of "hello")
cy.get("#input-start").shadow().find("input").then($input => {
$input[0].setSelectionRange(2, 2);
});
cy.realPress("ArrowRight");
cy.get("#btn-end").should("not.be.focused");
});

it("ArrowRight at end of input text moves focus to next item", () => {
cy.mount(
<Bar>
<Input id="input-start" slot="startContent" value="hello"></Input>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#input-start").realClick();
cy.get("#input-start").shadow().find("input").then($input => {
$input[0].setSelectionRange(5, 5); // end of "hello"
});
cy.realPress("ArrowRight");
cy.get("#btn-end").should("be.focused");
});

it("Navigation is disabled when accessibleRole is None", () => {
cy.mount(
<Bar accessibleRole="None">
<Button id="btn-start" slot="startContent">Start</Button>
<Button id="btn-end" slot="endContent">End</Button>
</Bar>
);

cy.get("#btn-start").realClick().should("be.focused");
cy.realPress("ArrowRight");
cy.get("#btn-end").should("not.be.focused");
});
});
Loading
Loading