|
| 1 | +import type UI5Element from "@ui5/webcomponents-base"; |
1 | 2 | import List from "../../src/List.js"; |
2 | 3 | import ListItemStandard from "../../src/ListItemStandard.js"; |
3 | 4 |
|
@@ -256,3 +257,53 @@ describe("List - Wrapping Behavior", () => { |
256 | 257 | .should("not.exist"); |
257 | 258 | }); |
258 | 259 | }); |
| 260 | + |
| 261 | +describe("List - getFocusDomRef Method", () => { |
| 262 | + it("should return undefined when the list is empty", () => { |
| 263 | + cy.mount(<List></List>); |
| 264 | + |
| 265 | + cy.get<List>("[ui5-list]") |
| 266 | + .then(($el) => { |
| 267 | + expect($el[0].getFocusDomRef()).to.be.undefined; |
| 268 | + }); |
| 269 | + }); |
| 270 | + |
| 271 | + it("should return first item if no item was focused before", () => { |
| 272 | + cy.mount( |
| 273 | + <List> |
| 274 | + <ListItemStandard id="item1">Item 1</ListItemStandard> |
| 275 | + <ListItemStandard>Item 2</ListItemStandard> |
| 276 | + <ListItemStandard>Item 3</ListItemStandard> |
| 277 | + </List> |
| 278 | + ); |
| 279 | + |
| 280 | + cy.get<UI5Element>("[ui5-list], #item1") |
| 281 | + .then(($el) => { |
| 282 | + const list = $el[0]; |
| 283 | + const item = $el[1]; |
| 284 | + |
| 285 | + expect(list.getFocusDomRef()).to.equal(item.getFocusDomRef()); |
| 286 | + }); |
| 287 | + }); |
| 288 | + |
| 289 | + it("should return last focused item in the list", () => { |
| 290 | + cy.mount( |
| 291 | + <List> |
| 292 | + <ListItemStandard>Item 1</ListItemStandard> |
| 293 | + <ListItemStandard id="item2">Item 2</ListItemStandard> |
| 294 | + <ListItemStandard>Item 3</ListItemStandard> |
| 295 | + </List> |
| 296 | + ); |
| 297 | + |
| 298 | + cy.get("#item2").click(); |
| 299 | + cy.get("#item2").should("be.focused"); |
| 300 | + |
| 301 | + cy.get<UI5Element>("[ui5-list], #item2") |
| 302 | + .then(($el) => { |
| 303 | + const list = $el[0]; |
| 304 | + const item = $el[1]; |
| 305 | + |
| 306 | + expect(list.getFocusDomRef()).to.equal(item.getFocusDomRef()); |
| 307 | + }); |
| 308 | + }); |
| 309 | +}); |
0 commit comments