-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR cherry picks 23d311c --------- Co-authored-by: Nico MASSART <NicolasMassart@users.noreply.github.com>
- Loading branch information
1 parent
101f932
commit a3e4340
Showing
16 changed files
with
962 additions
and
95 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 |
---|---|---|
@@ -1 +1 @@ | ||
20.12.2 | ||
20.17.0 |
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
73 changes: 73 additions & 0 deletions
73
app/components/Views/ChangeInSimulationModal/ChangeInSimulationModal.test.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,73 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react-native'; | ||
|
||
import renderWithProvider, { | ||
DeepPartial, | ||
} from '../../../util/test/renderWithProvider'; | ||
import { backgroundState } from '../../../util/test/initial-root-state'; | ||
import ChangeInSimulationModal, { | ||
PROCEED_BUTTON_TEST_ID, | ||
REJECT_BUTTON_TEST_ID, | ||
} from './ChangeInSimulationModal'; | ||
import { RootState } from '../../../reducers'; | ||
|
||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useDispatch: () => jest.fn(), | ||
})); | ||
|
||
jest.mock( | ||
'../../../component-library/components/BottomSheets/BottomSheet', | ||
() => | ||
({ children }: { children: React.ReactElement }) => | ||
<>{children}</>, | ||
); | ||
|
||
const NAVIGATION_PARAMS_MOCK = { | ||
params: { | ||
onProceed: jest.fn(), | ||
onReject: jest.fn(), | ||
}, | ||
}; | ||
|
||
const mockInitialState: DeepPartial<RootState> = { | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('ChangeInSimulationModal', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('render matches snapshot', () => { | ||
const { toJSON } = renderWithProvider( | ||
<ChangeInSimulationModal route={NAVIGATION_PARAMS_MOCK} />, | ||
{ | ||
state: mockInitialState, | ||
}, | ||
); | ||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('calls onProceed and onReject callbacks', () => { | ||
const mockOnReject = jest.fn(); | ||
const mockOnProceed = jest.fn(); | ||
const wrapper = renderWithProvider( | ||
<ChangeInSimulationModal | ||
route={{ params: { onProceed: mockOnProceed, onReject: mockOnReject } }} | ||
/>, | ||
{ | ||
state: mockInitialState, | ||
}, | ||
); | ||
fireEvent.press(wrapper.getByTestId(PROCEED_BUTTON_TEST_ID)); | ||
expect(mockOnProceed).toHaveBeenCalledTimes(1); | ||
|
||
fireEvent.press(wrapper.getByTestId(REJECT_BUTTON_TEST_ID)); | ||
expect(mockOnReject).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
93 changes: 93 additions & 0 deletions
93
app/components/Views/ChangeInSimulationModal/ChangeInSimulationModal.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,93 @@ | ||
import React, { useCallback, useRef } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { strings } from '../../../../locales/i18n'; | ||
import BottomSheet, { | ||
BottomSheetRef, | ||
} from '../../../component-library/components/BottomSheets/BottomSheet'; | ||
import Button from '../../../component-library/components/Buttons/Button/Button'; | ||
import Icon, { | ||
IconSize, | ||
IconName, | ||
IconColor, | ||
} from '../../../component-library/components/Icons/Icon'; | ||
import { | ||
ButtonSize, | ||
ButtonVariants, | ||
ButtonWidthTypes, | ||
} from '../../../component-library/components/Buttons/Button'; | ||
import SheetHeader from '../../../component-library/components/Sheet/SheetHeader'; | ||
import Text from '../../../component-library/components/Texts/Text'; | ||
|
||
export const PROCEED_BUTTON_TEST_ID = 'proceed-button'; | ||
export const REJECT_BUTTON_TEST_ID = 'reject-button'; | ||
|
||
const createStyles = () => | ||
StyleSheet.create({ | ||
buttonsWrapper: { | ||
alignSelf: 'stretch', | ||
flexDirection: 'column', | ||
gap: 16, | ||
paddingTop: 24, | ||
}, | ||
wrapper: { | ||
alignItems: 'center', | ||
padding: 16, | ||
}, | ||
description: { | ||
textAlign: 'center', | ||
}, | ||
}); | ||
|
||
const ChangeInSimulationModal = ({ | ||
route, | ||
}: { | ||
route: { params: { onProceed: () => void; onReject: () => void } }; | ||
}) => { | ||
const styles = createStyles(); | ||
const sheetRef = useRef<BottomSheetRef>(null); | ||
const { onProceed, onReject } = route.params; | ||
|
||
const handleProceed = useCallback(() => { | ||
sheetRef.current?.onCloseBottomSheet(); | ||
onProceed(); | ||
}, [onProceed, sheetRef]); | ||
|
||
const handleReject = useCallback(() => { | ||
sheetRef.current?.onCloseBottomSheet(); | ||
onReject(); | ||
}, [onReject, sheetRef]); | ||
|
||
return ( | ||
<BottomSheet ref={sheetRef}> | ||
<View style={styles.wrapper}> | ||
<Icon | ||
color={IconColor.Error} | ||
name={IconName.Warning} | ||
size={IconSize.Xl} | ||
/> | ||
<SheetHeader title={strings('change_in_simulation_modal.title')} /> | ||
<Text>{strings('change_in_simulation_modal.description')}</Text> | ||
<View style={styles.buttonsWrapper}> | ||
<Button | ||
label={strings('change_in_simulation_modal.reject')} | ||
onPress={handleReject} | ||
size={ButtonSize.Lg} | ||
testID={REJECT_BUTTON_TEST_ID} | ||
variant={ButtonVariants.Primary} | ||
width={ButtonWidthTypes.Full} | ||
/> | ||
<Button | ||
label={strings('change_in_simulation_modal.proceed')} | ||
onPress={handleProceed} | ||
size={ButtonSize.Lg} | ||
testID={PROCEED_BUTTON_TEST_ID} | ||
variant={ButtonVariants.Secondary} | ||
width={ButtonWidthTypes.Full} | ||
/> | ||
</View> | ||
</View> | ||
</BottomSheet> | ||
); | ||
}; | ||
|
||
export default ChangeInSimulationModal; |
170 changes: 170 additions & 0 deletions
170
...ponents/Views/ChangeInSimulationModal/__snapshots__/ChangeInSimulationModal.test.tsx.snap
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,170 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ChangeInSimulationModal render matches snapshot 1`] = ` | ||
<View | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"padding": 16, | ||
} | ||
} | ||
> | ||
<SvgMock | ||
color="#d73847" | ||
height={32} | ||
name="Warning" | ||
style={ | ||
{ | ||
"height": 32, | ||
"width": 32, | ||
} | ||
} | ||
width={32} | ||
/> | ||
<View | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"backgroundColor": "#ffffff", | ||
"flexDirection": "row", | ||
"height": 32, | ||
"justifyContent": "space-between", | ||
"margin": 16, | ||
} | ||
} | ||
> | ||
<View | ||
style={ | ||
{ | ||
"flex": 1, | ||
} | ||
} | ||
/> | ||
<Text | ||
accessibilityRole="text" | ||
style={ | ||
{ | ||
"color": "#141618", | ||
"fontFamily": "EuclidCircularB-Bold", | ||
"fontSize": 18, | ||
"fontWeight": "700", | ||
"letterSpacing": 0, | ||
"lineHeight": 24, | ||
} | ||
} | ||
> | ||
Results have changed | ||
</Text> | ||
<View | ||
style={ | ||
{ | ||
"alignItems": "flex-end", | ||
"flex": 1, | ||
} | ||
} | ||
/> | ||
</View> | ||
<Text | ||
accessibilityRole="text" | ||
style={ | ||
{ | ||
"color": "#141618", | ||
"fontFamily": "EuclidCircularB-Regular", | ||
"fontSize": 14, | ||
"fontWeight": "400", | ||
"letterSpacing": 0, | ||
"lineHeight": 22, | ||
} | ||
} | ||
> | ||
Estimated changes for this transaction have been updated. Review them closely before proceeding. | ||
</Text> | ||
<View | ||
style={ | ||
{ | ||
"alignSelf": "stretch", | ||
"flexDirection": "column", | ||
"gap": 16, | ||
"paddingTop": 24, | ||
} | ||
} | ||
> | ||
<TouchableOpacity | ||
accessibilityRole="button" | ||
accessible={true} | ||
activeOpacity={1} | ||
onPress={[Function]} | ||
onPressIn={[Function]} | ||
onPressOut={[Function]} | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"alignSelf": "stretch", | ||
"backgroundColor": "#0376c9", | ||
"borderRadius": 24, | ||
"flexDirection": "row", | ||
"height": 48, | ||
"justifyContent": "center", | ||
"paddingHorizontal": 16, | ||
} | ||
} | ||
testID="reject-button" | ||
> | ||
<Text | ||
accessibilityRole="text" | ||
style={ | ||
{ | ||
"color": "#ffffff", | ||
"fontFamily": "EuclidCircularB-Regular", | ||
"fontSize": 14, | ||
"fontWeight": "400", | ||
"letterSpacing": 0, | ||
"lineHeight": 22, | ||
} | ||
} | ||
> | ||
Reject the transaction | ||
</Text> | ||
</TouchableOpacity> | ||
<TouchableOpacity | ||
accessibilityRole="button" | ||
accessible={true} | ||
activeOpacity={1} | ||
onPress={[Function]} | ||
onPressIn={[Function]} | ||
onPressOut={[Function]} | ||
style={ | ||
{ | ||
"alignItems": "center", | ||
"alignSelf": "stretch", | ||
"backgroundColor": "transparent", | ||
"borderColor": "#0376c9", | ||
"borderRadius": 24, | ||
"borderWidth": 1, | ||
"flexDirection": "row", | ||
"height": 48, | ||
"justifyContent": "center", | ||
"paddingHorizontal": 16, | ||
} | ||
} | ||
testID="proceed-button" | ||
> | ||
<Text | ||
accessibilityRole="text" | ||
style={ | ||
{ | ||
"color": "#0376c9", | ||
"fontFamily": "EuclidCircularB-Regular", | ||
"fontSize": 14, | ||
"fontWeight": "400", | ||
"letterSpacing": 0, | ||
"lineHeight": 22, | ||
} | ||
} | ||
> | ||
Proceed | ||
</Text> | ||
</TouchableOpacity> | ||
</View> | ||
</View> | ||
`; |
Oops, something went wrong.