Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(content-answers): retry button (#3451)
* feat(content-answers): retry button * feat(content-answers): feedback * feat(content-answers): feedback * feat(content-answers): lint * feat(content-answers): retry connected * feat(content-answers): feedback * feat(content-answers): feedback --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
85d2521
commit e0976b8
Showing
10 changed files
with
204 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/features/content-answers/ContentAnswersModalFooterActions.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@import '../../styles/variables'; | ||
|
||
.bdl-ContentAnswersModalFooterActions { | ||
position: relative; | ||
top: -$bdl-grid-unit * 4; | ||
display: flex; | ||
padding: $bdl-grid-unit * 3 0 0 0; | ||
} | ||
|
||
.bdl-ContentAnswersModalFooterActions-button { | ||
margin: auto; | ||
|
||
&:not(.bdl-is-disabled):focus { | ||
border: 1px solid #bcbcbc; | ||
box-shadow: 0 0 0 1px $white, 0 0 0 3px $bdl-light-blue; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/features/content-answers/ContentAnswersModalFooterActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
|
||
import { FormattedMessage } from 'react-intl'; | ||
import Button from '../../components/button'; | ||
|
||
import messages from './messages'; | ||
|
||
import './ContentAnswersModalFooterActions.scss'; | ||
|
||
interface Props { | ||
hasError: boolean; | ||
onRetry: Function; | ||
} | ||
|
||
const ContentAnswersModalFooterActions = ({ hasError, onRetry }: Props) => { | ||
const retryButtonRef = React.useRef<HTMLButtonElement | null>(null); | ||
|
||
React.useEffect(() => { | ||
if (retryButtonRef.current && hasError) { | ||
retryButtonRef.current.focus(); | ||
} | ||
}, [retryButtonRef, hasError]); | ||
|
||
if (!hasError) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="bdl-ContentAnswersModalFooterActions" data-testid="content-answers-modal-footer-actions"> | ||
<Button | ||
setRef={(ref: HTMLButtonElement) => { | ||
retryButtonRef.current = ref; | ||
}} | ||
className="bdl-ContentAnswersModalFooterActions-button" | ||
data-testid="content-answers-retry-button" | ||
onClick={onRetry} | ||
size="large" | ||
> | ||
<FormattedMessage {...messages.retryResponse} /> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ContentAnswersModalFooterActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/features/content-answers/__tests__/ContentAnswersModalFooterActions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; | ||
import ContentAnswersModalFooterActions from '../ContentAnswersModalFooterActions'; | ||
|
||
describe('features/content-answers/ContentAnswersModalFooterActions', () => { | ||
const stubs = { | ||
onRetry: jest.fn(), | ||
}; | ||
|
||
const renderComponent = (props = {}) => { | ||
return render(<ContentAnswersModalFooterActions hasError={false} onRetry={stubs.onRetry} {...props} />); | ||
}; | ||
|
||
test('should not show the retry button', () => { | ||
renderComponent(); | ||
const retryButton = screen.queryByTestId('content-answers-retry-button'); | ||
expect(retryButton).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('should show the retry button', async () => { | ||
renderComponent({ hasError: true }); | ||
const retryButton = screen.getByTestId('content-answers-retry-button'); | ||
expect(retryButton).toBeInTheDocument(); | ||
await waitFor(() => { | ||
expect(document.activeElement).toBe(retryButton); | ||
}); | ||
}); | ||
|
||
test('should call the retry response function if the button is clicked', () => { | ||
renderComponent({ hasError: true }); | ||
const retryButton = screen.getByTestId('content-answers-retry-button'); | ||
|
||
fireEvent.click(retryButton); | ||
|
||
expect(stubs.onRetry).toBeCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters