Skip to content

Commit 97a8e18

Browse files
committed
chore: add test for delete button and move type before description
1 parent ac14634 commit 97a8e18

2 files changed

Lines changed: 69 additions & 13 deletions

File tree

packages/main/cypress/specs/ListItemCustom.cy.tsx

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
123123
cy.get("#li-custom-ui5")
124124
.shadow()
125125
.find(`#${itemId}-invisibleTextContent`)
126-
.should("have.text", "List Item Click me Button Check option Checkbox Not checked required");
126+
.should("have.text", "List Item Button Click me Checkbox Check option Not checked required");
127127

128128
// Check that aria-labelledby on the internal li element includes the invisibleTextContent span id
129129
cy.get("#li-custom-ui5")
@@ -167,7 +167,7 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
167167
cy.get("#li-custom-ui5-focus")
168168
.shadow()
169169
.find(`#${itemId}-invisibleTextContent`)
170-
.should("have.text", "List Item Click Me Button Check Option Checkbox Not checked");
170+
.should("have.text", "List Item Button Click Me Checkbox Check Option Not checked");
171171

172172
// Check that aria-labelledby on the internal li element includes the invisibleTextContent span id
173173
cy.get("#li-custom-ui5-focus")
@@ -186,7 +186,7 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
186186
cy.get("#li-custom-ui5-focus")
187187
.shadow()
188188
.find(`#${itemId}-invisibleTextContent`)
189-
.should("have.text", "List Item Click Me Button Check Option Checkbox Not checked");
189+
.should("have.text", "List Item Button Click Me Checkbox Check Option Not checked");
190190
});
191191

192192
// Click outside the list to truly remove focus
@@ -230,7 +230,7 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
230230
cy.get("#li-custom-nested")
231231
.shadow()
232232
.find(`#${itemId}-invisibleTextContent`)
233-
.should("have.text", "List Item Container Text Nested Button Button Paragraph outside container");
233+
.should("have.text", "List Item Container Text Button Nested Button Paragraph outside container");
234234

235235
// Check that aria-labelledby on the internal li element includes the invisibleTextContent span id
236236
cy.get("#li-custom-nested")
@@ -270,7 +270,7 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
270270
cy.get("#li-custom-deep-nested")
271271
.shadow()
272272
.find(`#${itemId}-invisibleTextContent`)
273-
.should("have.text", "List Item Deeply Nested Button Button Level 2 Text Nested Checkbox Not checked");
273+
.should("have.text", "List Item Button Deeply Nested Button Level 2 Text Checkbox Nested Not checked");
274274

275275
// Check that aria-labelledby on the internal li element includes the invisibleTextContent span id
276276
cy.get("#li-custom-deep-nested")
@@ -293,6 +293,64 @@ describe("ListItemCustom - _onfocusin and _onfocusout Tests", () => {
293293
});
294294
});
295295

296+
describe("With delete mode and custom delete button", () => {
297+
it("should handle ListItemCustom with delete mode and custom delete button", () => {
298+
// Mount ListItemCustom with delete mode and custom delete button
299+
cy.mount(
300+
<List selectionMode="Delete">
301+
<ListItemCustom id="li-custom-delete">
302+
<div>Delete Mode Item</div>
303+
<Button slot="deleteButton" id="custom-delete-button">
304+
Remove
305+
</Button>
306+
</ListItemCustom>
307+
</List>
308+
);
309+
310+
// Store the component ID
311+
cy.get("#li-custom-delete").invoke("prop", "_id").as("itemId");
312+
313+
// Focus the list item
314+
cy.get("#li-custom-delete").click();
315+
316+
// Verify text content is processed and included in the invisible text
317+
cy.get("@itemId").then(itemId => {
318+
cy.get("#li-custom-delete")
319+
.shadow()
320+
.find(`#${itemId}-invisibleTextContent`)
321+
.should("have.text", "List Item Delete Mode Item Button Remove");
322+
323+
// Check that aria-labelledby on the internal li element includes the invisibleTextContent span id
324+
cy.get("#li-custom-delete")
325+
.shadow()
326+
.find("li[part='native-li']")
327+
.should("have.attr", "aria-labelledby")
328+
.and("include", `${itemId}-invisibleTextContent`);
329+
330+
// Verify that the custom delete button is properly rendered in the shadow DOM
331+
cy.get("#li-custom-delete")
332+
.shadow()
333+
.find("div.ui5-li-deletebtn")
334+
.should("exist")
335+
.and("contain", "Remove");
336+
337+
// Check that clicking the delete button triggers the delete event
338+
cy.get("#custom-delete-button").should("exist");
339+
});
340+
341+
// Remove focus
342+
cy.focused().blur();
343+
344+
// After blur, invisible text content should be cleared
345+
cy.get("@itemId").then(itemId => {
346+
cy.get("#li-custom-delete")
347+
.shadow()
348+
.find(`#${itemId}-invisibleTextContent`)
349+
.should("have.text", "");
350+
});
351+
});
352+
});
353+
296354
describe("Edge cases", () => {
297355
it("should handle empty list item content", () => {
298356
cy.mount(

packages/main/src/ListItemCustom.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,13 @@ class ListItemCustom extends ListItem {
288288
type, description, required, disabled, readonly, children,
289289
} = accessibilityInfo;
290290

291-
// Build text parts starting with description
292291
const textParts: string[] = [];
293292

294-
// Description is the primary content for accessibility
293+
// Add type and description first
294+
if (type) {
295+
textParts.push(type);
296+
}
297+
295298
if (description) {
296299
textParts.push(description);
297300
}
@@ -304,17 +307,12 @@ class ListItemCustom extends ListItem {
304307
.filter(Boolean)
305308
.join(" ");
306309

307-
// Add children text after description but before type
310+
// Add children text after description
308311
if (childrenText) {
309312
textParts.push(childrenText);
310313
}
311314
}
312315

313-
// Type is added after children
314-
if (type) {
315-
textParts.push(type);
316-
}
317-
318316
// Add accessibility states
319317
const states: string[] = [];
320318
if (required) {

0 commit comments

Comments
 (0)