Skip to content

Commit

Permalink
chore(switch): fix missing coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
damienrobson-sage committed Oct 21, 2024
1 parent ae5adef commit 26bf78c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/__internal__/label/label.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface StyledLabelProps {

const StyledLabel = styled.label<StyledLabelProps>`
${({ isDarkBackground }) =>
isDarkBackground &&
css`
color: ${isDarkBackground
? "var(--colorsUtilityYang100)"
Expand Down
9 changes: 9 additions & 0 deletions src/components/switch/__internal__/switch-slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,12 @@ test("renders with dark background styles when `isDarkBackground` is true", () =

expect(switchPanel).toHaveStyleRule("color: black");
});

// coverage
test("renders with dark background styles when `isDarkBackground` is true and checked is true", () => {
render(<SwitchSlider isDarkBackground checked />);

const switchPanel = screen.getByTestId("slider");

expect(switchPanel).toHaveStyleRule("color: white");
});
1 change: 1 addition & 0 deletions src/components/switch/switch.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export const Switch = React.forwardRef(
<StyledHintText
data-role="hint-text"
id={inputHintId.current}
isDarkBackground={isDarkBackground}
>
{labelHelp}
</StyledHintText>
Expand Down
17 changes: 17 additions & 0 deletions src/components/switch/switch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,20 @@ export const NewValidationInlineWithDarkModeAndError: Story = () => {
};
NewValidationInlineWithDarkModeAndError.storyName =
"New Validation - Inline with dark background support and error";

export const NewValidationInlineWithDarkModeAndHintText: Story = () => {
return (
<Box m={2} padding={3} backgroundColor="#000000">
<CarbonProvider validationRedesignOptIn>
<Switch
label="Example switch (error state)"
labelInline
isDarkBackground
labelHelp="A helpful hint for the user"
/>
</CarbonProvider>
</Box>
);
};
NewValidationInlineWithDarkModeAndHintText.storyName =
"New Validation - Inline with dark background support and hint text";
104 changes: 104 additions & 0 deletions src/components/switch/switch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,107 @@ test("renders correctly with inputWidth set to numerical value of between 0 and

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with labelInline and new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch labelInline />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with reverse flag set under erroneous state and new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch reverse error="error" />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with no reverse flag set under erroneous state and new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch reverse={false} error="error" />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with reverse flag not set and new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch reverse={false} />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with hint text and dark background in new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch labelHelp="hint text" isDarkBackground />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with hint text in new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch labelHelp="hint text" />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with inline label and field help in new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch labelInline fieldHelp="Field help" />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

// coverage
test("renders correctly with inline label, dark background and field help in new validation", () => {
render(
<CarbonProvider validationRedesignOptIn>
<Switch labelInline fieldHelp="Field help" isDarkBackground />
</CarbonProvider>
);

const switchElement = screen.getByRole("switch");

expect(switchElement).toHaveStyleRule("width: 50%");
});

0 comments on commit 26bf78c

Please sign in to comment.