|
1 | | -import { Dropdown, Option } from "@salt-ds/core"; |
| 1 | +import { Dropdown, FormField, FormFieldLabel, Option } from "@salt-ds/core"; |
2 | 2 | import * as dropdownStories from "@stories/dropdown/dropdown.stories"; |
3 | 3 | import { composeStories } from "@storybook/react-vite"; |
4 | 4 | import { type KeyboardEventHandler, useRef, useState } from "react"; |
@@ -225,6 +225,36 @@ describe("Given a Dropdown", () => { |
225 | 225 | cy.findByRole("combobox").should("have.text", "California"); |
226 | 226 | }); |
227 | 227 |
|
| 228 | + it("should show the empty marker when it is readonly with no selection", () => { |
| 229 | + cy.mount( |
| 230 | + <Dropdown readOnly> |
| 231 | + <Option value="Alabama" /> |
| 232 | + </Dropdown>, |
| 233 | + ); |
| 234 | + |
| 235 | + cy.findByRole("combobox").should("have.text", "—"); |
| 236 | + }); |
| 237 | + |
| 238 | + it("should show the empty marker when it is readonly with a controlled empty value", () => { |
| 239 | + cy.mount( |
| 240 | + <Dropdown readOnly value=""> |
| 241 | + <Option value="Alabama" /> |
| 242 | + </Dropdown>, |
| 243 | + ); |
| 244 | + |
| 245 | + cy.findByRole("combobox").should("have.text", "—"); |
| 246 | + }); |
| 247 | + |
| 248 | + it("should show custom value text rather than the empty marker when it is readonly", () => { |
| 249 | + cy.mount( |
| 250 | + <Dropdown readOnly value="Custom value"> |
| 251 | + <Option value="Alabama" /> |
| 252 | + </Dropdown>, |
| 253 | + ); |
| 254 | + |
| 255 | + cy.findByRole("combobox").should("have.text", "Custom value"); |
| 256 | + }); |
| 257 | + |
228 | 258 | it("should not receive focus via tab if it is disabled", () => { |
229 | 259 | cy.mount( |
230 | 260 | <div> |
@@ -526,4 +556,31 @@ describe("Given a Dropdown", () => { |
526 | 556 | .should("exist") |
527 | 557 | .and("have.attr", "role", "listbox"); |
528 | 558 | }); |
| 559 | + |
| 560 | + describe("validation status", () => { |
| 561 | + it("should use its own validation status when not in a FormField", () => { |
| 562 | + cy.mount( |
| 563 | + <Dropdown validationStatus="warning"> |
| 564 | + <Option value={1}>1</Option> |
| 565 | + </Dropdown>, |
| 566 | + ); |
| 567 | + cy.findByRole("combobox").should("have.class", "saltDropdown-warning"); |
| 568 | + }); |
| 569 | + |
| 570 | + it("should prioritize the FormField validation status over its own", () => { |
| 571 | + cy.mount( |
| 572 | + <FormField validationStatus="error"> |
| 573 | + <FormFieldLabel>Field</FormFieldLabel> |
| 574 | + <Dropdown validationStatus="warning"> |
| 575 | + <Option value={1}>1</Option> |
| 576 | + </Dropdown> |
| 577 | + </FormField>, |
| 578 | + ); |
| 579 | + cy.findByRole("combobox").should("have.class", "saltDropdown-error"); |
| 580 | + cy.findByRole("combobox").should( |
| 581 | + "not.have.class", |
| 582 | + "saltDropdown-warning", |
| 583 | + ); |
| 584 | + }); |
| 585 | + }); |
529 | 586 | }); |
0 commit comments