Skip to content

Commit

Permalink
fix: πŸ› add Reset Form title to SQFormButton if type is 'reset'
Browse files Browse the repository at this point in the history
βœ… Closes: #220
  • Loading branch information
Cody Rose committed May 11, 2021
1 parent 5da4e82 commit 7fdd059
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
15 changes: 13 additions & 2 deletions src/components/SQForm/SQFormButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function SQFormButton({
children,
isDisabled = false,
shouldRequireFieldUpdates = false,
title = 'Form Submission',
title,
type = 'submit',
onClick
}) {
Expand All @@ -33,9 +33,20 @@ function SQFormButton({
}
};

const getTitle = () => {
switch (true) {
case Boolean(title):
return title;
case type === 'reset':
return 'Reset Form';
default:
return 'Form Submission';
}
};

return (
<RoundedButton
title={title}
title={getTitle()}
type={type}
isDisabled={isSQFormButtonDisabled}
onClick={getClickHandler}
Expand Down
16 changes: 12 additions & 4 deletions stories/__tests__/SQFormButton.stories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ describe('SQFormButton Tests', () => {
expect(submitButton).toHaveTextContent('Submit');
});

it('should render a button with a given title', () => {
render(<SQFormButton title="Hello world" />);

const button = screen.getByTitle(/hello world/i);

expect(button).toBeInTheDocument();
});

it('should render a reset button given the type reset', () => {
render(<SQFormButton type="reset" />);

const resetButton = screen.getByRole('button', {
name: /form submission/i
name: /reset form/i
});

expect(resetButton).toBeInTheDocument();
Expand All @@ -37,7 +45,7 @@ describe('SQFormButton Tests', () => {
render(<SQFormButton type="reset" />);

const resetButton = screen.getByRole('button', {
name: /form submission/i
name: /reset form/i
});

expect(resetButton).toBeInTheDocument();
Expand Down Expand Up @@ -127,7 +135,7 @@ describe('SQFormButton Tests', () => {
render(<SQFormButtonWithField type="reset" />);

const resetButton = screen.getByRole('button', {
name: /form submission/i
name: /reset form/i
});
expect(resetButton).toHaveAttribute('type', 'reset');
expect(resetButton).toBeDisabled();
Expand All @@ -142,7 +150,7 @@ describe('SQFormButton Tests', () => {
render(<SQFormButtonWithField type="reset" />);

const resetButton = screen.getByRole('button', {
name: /form submission/i
name: /reset form/i
});
expect(resetButton).toHaveAttribute('type', 'reset');
expect(resetButton).toBeDisabled();
Expand Down

0 comments on commit 7fdd059

Please sign in to comment.