Skip to content

Commit

Permalink
Disable toggle fields unselect (#2557)
Browse files Browse the repository at this point in the history
* fix: prevent unselecting value

* task: update tests
  • Loading branch information
finnar-bin authored Feb 20, 2024
1 parent d787814 commit f092322
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
17 changes: 4 additions & 13 deletions cypress/e2e/content/content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,17 @@ describe("Content Specs", () => {
.contains("Yes")
.should("have.class", "Mui-selected");

// Click the "Yes" button again to deselect it
cy.get("#12-575f7c-trw1w3 button").contains("Yes").click();

// Check if neither "Yes" nor "No" buttons have the ".Mui-selected" class
cy.get("#12-575f7c-trw1w3 button")
.contains("Yes")
.should("not.have.class", "Mui-selected");
cy.get("#12-575f7c-trw1w3 button")
.contains("No")
.should("not.have.class", "Mui-selected");

// Click the "No" button to select it
cy.get("#12-575f7c-trw1w3 button").contains("No").click();

// Check if the "No" button has the ".Mui-selected" class
cy.get("#12-575f7c-trw1w3 button")
.contains("No")
.should("have.class", "Mui-selected");
});

// Click the "No" button again to deselect it
it("Yes/No Field: Does not allow user to deselect value", () => {
// Click the "No" button to deselect it
cy.get("#12-575f7c-trw1w3 button").contains("No").click();

// Check again if neither "Yes" nor "No" buttons have the ".Mui-selected" class
Expand All @@ -178,7 +169,7 @@ describe("Content Specs", () => {
.should("not.have.class", "Mui-selected");
cy.get("#12-575f7c-trw1w3 button")
.contains("No")
.should("not.have.class", "Mui-selected");
.should("have.class", "Mui-selected");
});

// TODO: Need to confirm toggling of value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ export const Field = ({
size="small"
value={value}
exclusive
onChange={(_, val) => onChange(val, name)}
onChange={(_, val) => {
if (val !== null) {
onChange(val, name);
}
}}
>
<ToggleButton
value={0}
Expand Down

0 comments on commit f092322

Please sign in to comment.