-
Notifications
You must be signed in to change notification settings - Fork 273
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
chore(ui5-table): migrate TableNavigation wdio tests to cypress #10620
Open
nowakdaniel
wants to merge
6
commits into
main
Choose a base branch
from
chore-tablenav-cypress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64e391c
chore(ui5-table): migrate TableNavigation wdio tests to cypress
nowakdaniel e9b9fd9
chore(ui5-table): deleted comment
nowakdaniel 599cf9f
Merge branch 'main' into chore-tablenav-cypress
nowakdaniel c658054
fix: changed *.ts to *.tsx file extension and removed lit-html
nowakdaniel 9f2115f
chore: moved reused alias to beforeEach + removed unused alias
nowakdaniel e8e3c23
chore: new function to minimize repeating code lines
nowakdaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
import Table from "../../src/Table.js"; | ||
import TableHeaderRow from "../../src/TableHeaderRow.js"; | ||
import TableHeaderCell from "../../src/TableHeaderCell.js"; | ||
import TableRow from "../../src/TableRow.js"; | ||
import TableCell from "../../src/TableCell.js"; | ||
import TableGrowing from "../../src/TableGrowing.js"; | ||
|
||
describe("Table - Keyboard Navigation", () => { | ||
beforeEach(() => { | ||
cy.mount( | ||
<> | ||
<input id="before-table1" type="Number" value="0"/> | ||
<Table id="table0"> | ||
<TableGrowing id="growing" type="Button" slot="features"></TableGrowing> | ||
<TableHeaderRow slot="headerRow"> | ||
<TableHeaderCell><a id="row0-link" href="test.html">Link</a></TableHeaderCell> | ||
<TableHeaderCell>Header2</TableHeaderCell> | ||
<TableHeaderCell>Header3</TableHeaderCell> | ||
<TableHeaderCell>Header4</TableHeaderCell> | ||
</TableHeaderRow> | ||
<TableRow> | ||
<TableCell>Row1Cell0</TableCell> | ||
<TableCell><input id="row1-input"/></TableCell> | ||
<TableCell><button id="row1-button">Button 1</button></TableCell> | ||
<TableCell>Row1Cell3</TableCell> | ||
</TableRow> | ||
<TableRow id="interactive-row" interactive> | ||
<TableCell>Row2Cell0</TableCell> | ||
<TableCell><input id="row2-input"/></TableCell> | ||
<TableCell><button id="row2-button">Button 2</button></TableCell> | ||
<TableCell>Row2Cell3</TableCell> | ||
</TableRow> | ||
<TableRow id="notinteractive-row"> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell> Here the table structure is broken. There is only one cell in row 5. </TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
<TableRow> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> <TableCell></TableCell> </TableRow> | ||
</Table> | ||
<input id="after-table1"/> | ||
</> | ||
); | ||
|
||
cy.document().then(doc => { | ||
const table = doc.getElementById("table0"); | ||
const input = doc.getElementById("before-table1"); | ||
table?.addEventListener("ui5-row-click", () => { | ||
if (input instanceof HTMLInputElement) { | ||
input.valueAsNumber++; | ||
} | ||
}); | ||
}); | ||
|
||
cy.get("#table0").children("ui5-table-row").as("rows"); | ||
cy.get("#table0").children("ui5-table-header-row").as("headerRow"); | ||
}); | ||
|
||
function getCell(row: number, cell: number, headerRow: boolean) { | ||
if (headerRow) { | ||
return cy.get("@headerRow").children("ui5-table-header-cell").eq(cell); | ||
} | ||
return cy.get("@rows").eq(row) | ||
.children("ui5-table-cell") | ||
.eq(cell); | ||
} | ||
|
||
function performActions(actions: { element: Cypress.Chainable, click?: string, condition?: string, conditionValue?:string, type?: string, press?: string | string[] }[]) { | ||
actions.forEach(action => { | ||
if (action.click) { | ||
// @ts-ignore | ||
action.element.click(action.click); | ||
} | ||
if (action.condition) { | ||
if (action.conditionValue) { | ||
action.element.wait(0).should(action.condition, action.conditionValue); | ||
} else { | ||
action.element.wait(0).should(action.condition); | ||
} | ||
} | ||
if (action.type) { | ||
action.element.type(action.type); | ||
} | ||
if (action.press) { | ||
// @ts-ignore | ||
action.element.realPress(action.press); | ||
} | ||
}); | ||
} | ||
|
||
it("should navigate on rows", () => { | ||
performActions([ | ||
// left click is needed to focus the row | ||
// otherwise the it would click in the center of the row where an input is | ||
// resulting in a focus on the input instead of the row | ||
{ element: cy.get("@rows").eq(0), click: "left" }, | ||
{ element: cy.get("@rows").eq(0), type: "{leftarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{uparrow}", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow"), type: "{uparrow}", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow"), type: "{downarrow}{downarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(21), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(24), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: cy.get("#growing").shadow().find("#growing-button"), type: "{pageup}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(5), type: "{pageup}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{end}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(24), type: "{end}", condition: "be.focused" }, | ||
{ element: cy.get("#growing").shadow().find("#growing-button"), type: "{home}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{home}", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow"), condition: "be.focused" } | ||
]); | ||
}); | ||
|
||
it("should navigate on cells", () => { | ||
performActions([ | ||
{ element: cy.get("@rows").eq(0), click: "left" }, | ||
{ element: cy.get("@rows").eq(0), type: "{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, false), type: "{leftarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{rightarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 1, false), type: "{home}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, false), type: "{end}", condition: "be.focused" }, | ||
{ element: getCell(0, 3, false), type: "{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 3, false), type: "{end}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{end}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(24), type: "{rightarrow}{rightarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(24, 2, false), type: "{pageup}", condition: "be.focused" }, | ||
{ element: getCell(4, 0, false), type: "{pageup}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, false), type: "{pageup}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, true), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: getCell(19, 0, false), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: getCell(24, 0, false), type: "{pagedown}", condition: "be.focused" }, | ||
{ element: cy.get("#growing").shadow().find("#growing-button"), type: "{home}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{home}", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow"), type: "{downarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, false), type: "{downarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(1, 1, false), type: "{downarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(2, 2, false), type: "{downarrow}{rightarrow}", condition: "be.focused" }, | ||
{ element: getCell(3, 3, false), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: getCell(4, 0, false), condition: "be.focused" } | ||
]); | ||
}); | ||
|
||
it("should handle F2/F7/Enter/Tab/Up/Down", () => { | ||
cy.get("@rows").eq(0).get("#row1-input").as("row1Input"); | ||
cy.get("@rows").eq(1).get("#row2-input").as("row2Input"); | ||
|
||
performActions([ | ||
{ element: cy.get("@rows").eq(0), click: "left" }, | ||
{ element: cy.get("@rows").eq(0), press: "F2", condition: "be.focused" }, | ||
{ element: cy.get("@row1Input"), press: "F2", condition: "be.focused" }, | ||
{ element: getCell(0, 1, false), press: "F2", condition: "be.focused" }, | ||
{ element: cy.get("@row1Input"), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@row1Input").eq(0), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@row1Input").eq(0), type: "{uparrow}", condition: "be.focused" }, | ||
{ element: cy.get("@row1Input").eq(0), press: ["F2", "{uparrow}"], condition: "be.focused" }, | ||
{ element: getCell(0, 1, true), press: "F2", condition: "be.focused" }, | ||
{ element: getCell(0, 1, true), type: "{leftarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, true), type: "{enter}", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow").get("#row0-link"), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 0, false), press: "Tab", condition: "be.focused" }, | ||
{ element: cy.get("#after-table1"), press: ["Shift", "Tab"], condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@row2Input").eq(0), press: "Tab", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1).get("#row2-button"), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1), type: "{uparrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0).get("#row1-button"), type: "{uparrow}", condition: "be.focused" }, | ||
{ element: getCell(0, 2, true), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@headerRow"), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), press: "F7", condition: "be.focused" }, | ||
{ element: getCell(0, 2, false), press: "F7", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(0), type: "{downarrow}", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1), press: "F7", condition: "be.focused" }, | ||
{ element: getCell(1, 2, false), press: ["Shift", "Tab"], condition: "be.focused" }, | ||
{ element: cy.get("#before-table1"), press: "Tab", condition: "be.focused" }, | ||
{ element: cy.get("@rows").eq(1), press: "Tab", condition: "be.focused" } | ||
]); | ||
}); | ||
|
||
it("should should work correctly for interactive rows", () => { | ||
cy.get("@rows").eq(1).get("#row2-button").as("row2Button"); | ||
cy.get("#table0").get("#before-table1").as("input"); | ||
cy.get("@rows").get("#interactive-row").as("row"); | ||
|
||
performActions([ | ||
{ element: cy.get("@row"), click: "left" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "1" }, | ||
{ element: cy.get("@row"), type: "{enter}" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "2" }, | ||
{ element: cy.get("@rows").get("#notinteractive-row"), click: "left" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "2" }, | ||
{ element: cy.get("@row2Button"), click: "left" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "2" }, | ||
{ element: cy.get("@row2Button"), type: "{enter}" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "2" }, | ||
{ element: cy.get("@row2Button"), press: "F7" }, | ||
{ element: cy.get("@row"), condition: "be.focused" }, | ||
{ element: cy.get("@row"), press: "Space" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "2" }, | ||
{ element: cy.get("@row"), type: "{enter}" }, | ||
{ element: cy.get("@input"), condition: "have.value", conditionValue: "3" } | ||
]); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a comment later.
There seemed to be a timing issue which I was able to relove using
wait