Skip to content

Commit

Permalink
Merge pull request #92 from rcpch/mbarton/form-submit-gradient-labels…
Browse files Browse the repository at this point in the history
…-button

Make sure the gradient labels button doesn't auto-submit a parent form
  • Loading branch information
mbarton authored Jul 15, 2024
2 parents 632e32b + 07a9f5f commit e55501b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/CentileChart/CentileChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1175,4 +1175,36 @@ describe("Tests relating to negative settings on the zoom button", () => {
render(<CentileChart {...props} />);
expect(screen.queryByTestId('resetzoom-button')).not.toBeInTheDocument();
})
})

describe("Tests relating to the gradient labels button", () => {
let props: CentileChartProps;
const midparentalHeight: MidParentalHeightObject = {}

beforeEach(() => {
props = {
chartsVersion: "7.0.0",
reference: "uk-who",
title: "Term Girl",
subtitle: "Now over 4 years with advanced bone age",
measurementMethod: "height",
sex: 'female',
childMeasurements: termGirlWithSingleHeightMeasurementAndBoneAgeAndEvent,
midParentalHeightData: midparentalHeight,
enableZoom: true,
styles: monochromeStyles,
enableExport: false,
exportChartCallback: ()=>null,
clinicianFocus: false
};
});

it("should not trigger form submission when gradient labels clicked", () => {
const onSubmit = jest.fn();
render(<form onSubmit={onSubmit}>
<CentileChart {...props} />
</form>);
fireEvent.click(screen.getByTestId('gradient-labels-button'));
expect(onSubmit).not.toHaveBeenCalled();
});
})
3 changes: 2 additions & 1 deletion src/SubComponents/StyledGradientLabelsButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components';
import { CommonButton } from './CommonButton';

export const StyledGradientLabelsButton = styled.button<{
export const StyledGradientLabelsButton = styled(CommonButton)<{
$color?: string,
size?: number
}>`
Expand Down

0 comments on commit e55501b

Please sign in to comment.