-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/main/prettier-3.4.1
- Loading branch information
Showing
6 changed files
with
206 additions
and
182 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import MultiStepFooter from 'web/components/dialog/multistepfooter'; | ||
import DialogFooter from 'web/components/dialog/twobuttonfooter'; | ||
import PropTypes from 'web/utils/proptypes'; | ||
|
||
const SaveDialogFooter = ({ | ||
multiStep, | ||
isLoading, | ||
prevDisabled, | ||
nextDisabled, | ||
buttonTitle, | ||
currentStep, | ||
setCurrentStep, | ||
onClose, | ||
handleSaveClick, | ||
}) => { | ||
return multiStep > 0 ? ( | ||
<MultiStepFooter | ||
loading={isLoading} | ||
prevDisabled={prevDisabled} | ||
nextDisabled={nextDisabled} | ||
rightButtonTitle={buttonTitle} | ||
onNextButtonClick={() => | ||
setCurrentStep(currentStep < multiStep ? currentStep + 1 : currentStep) | ||
} | ||
onLeftButtonClick={onClose} | ||
onPreviousButtonClick={() => | ||
setCurrentStep(currentStep > 0 ? currentStep - 1 : currentStep) | ||
} | ||
onRightButtonClick={handleSaveClick} | ||
/> | ||
) : ( | ||
<DialogFooter | ||
isLoading={isLoading} | ||
rightButtonTitle={buttonTitle} | ||
onLeftButtonClick={onClose} | ||
onRightButtonClick={handleSaveClick} | ||
/> | ||
); | ||
}; | ||
|
||
SaveDialogFooter.propTypes = { | ||
multiStep: PropTypes.number.isRequired, | ||
isLoading: PropTypes.bool.isRequired, | ||
prevDisabled: PropTypes.bool.isRequired, | ||
nextDisabled: PropTypes.bool.isRequired, | ||
buttonTitle: PropTypes.string.isRequired, | ||
currentStep: PropTypes.number.isRequired, | ||
setCurrentStep: PropTypes.func.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
handleSaveClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default SaveDialogFooter; |
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,59 @@ | ||
/* SPDX-FileCopyrightText: 2024 Greenbone AG | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import {describe, test, expect, testing} from '@gsa/testing'; | ||
|
||
import {render, fireEvent, screen} from 'web/utils/testing'; | ||
import SaveDialogFooter from '../SaveDialogFooter'; | ||
|
||
describe('SaveDialogFooter', () => { | ||
const defaultProps = { | ||
multiStep: 0, | ||
isLoading: false, | ||
prevDisabled: false, | ||
nextDisabled: false, | ||
buttonTitle: 'Save', | ||
currentStep: 0, | ||
setCurrentStep: testing.fn(), | ||
onClose: testing.fn(), | ||
handleSaveClick: testing.fn(), | ||
}; | ||
|
||
test('renders DialogFooter when multiStep is 0', () => { | ||
render(<SaveDialogFooter {...defaultProps} />); | ||
expect(screen.getByText('Save')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders MultiStepFooter when multiStep is greater than 0', () => { | ||
render(<SaveDialogFooter {...defaultProps} multiStep={3} />); | ||
expect(screen.getByText('Save')).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls setCurrentStep with incremented value on next button click in MultiStepFooter', () => { | ||
render(<SaveDialogFooter {...defaultProps} multiStep={3} />); | ||
fireEvent.click(screen.getByTestId('dialog-next-button')); | ||
expect(defaultProps.setCurrentStep).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
test('calls setCurrentStep with decremented value on previous button click in MultiStepFooter', () => { | ||
render( | ||
<SaveDialogFooter {...defaultProps} multiStep={3} currentStep={2} />, | ||
); | ||
fireEvent.click(screen.getByTestId('dialog-previous-button')); | ||
expect(defaultProps.setCurrentStep).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
test('calls onClose when left button is clicked', () => { | ||
render(<SaveDialogFooter {...defaultProps} />); | ||
fireEvent.click(screen.getByText('Cancel')); | ||
expect(defaultProps.onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
test('calls handleSaveClick when right button is clicked', () => { | ||
render(<SaveDialogFooter {...defaultProps} />); | ||
fireEvent.click(screen.getByText('Save')); | ||
expect(defaultProps.handleSaveClick).toHaveBeenCalled(); | ||
}); | ||
}); |
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
Oops, something went wrong.