-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: ota update modal #24175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+414
−239
Merged
feat: ota update modal #24175
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
adb6275
feat: ota update modal
weitingsun 0ba1915
refactor OTA update modal
weitingsun a203661
test version 7.62.90
weitingsun c8f126c
[skip ci] Bump version number to 3310
metamaskbot b4c1792
revert version and build number
weitingsun 40444aa
change feature flag to useSelector
weitingsun c17d45a
Merge branch 'main' into wsun/ota-update-modal
weitingsun a714db7
update build number
weitingsun e49e344
revert build number
weitingsun a4c94b2
move OTA update to Nav/Main
weitingsun d0e4deb
change version
weitingsun 4adbe59
remove dup useMetrics mock
weitingsun a2efb12
[skip ci] Bump version number to 3315
metamaskbot 977ca4f
debug Android
weitingsun 228b1ea
Merge branch 'wsun/ota-update-modal' of github.com:MetaMask/metamask-…
weitingsun f97a0f2
[skip ci] Bump version number to 3319
metamaskbot c1d7041
exit the app for Android users
weitingsun 57b3987
Merge branch 'wsun/ota-update-modal' of github.com:MetaMask/metamask-…
weitingsun 670eb90
[skip ci] Bump version number to 3322
metamaskbot e9105b3
revert testing code
weitingsun b39207a
Merge branch 'wsun/ota-update-modal' of github.com:MetaMask/metamask-…
weitingsun b7c04fc
Merge branch 'main' into wsun/ota-update-modal
weitingsun 78ab060
Merge branch 'main' into wsun/ota-update-modal
weitingsun 26b43ed
Merge branch 'main' into wsun/ota-update-modal
weitingsun 32c36ea
change OTA update modal textcopy on Android
weitingsun 50f7b8f
Merge branch 'main' into wsun/ota-update-modal
weitingsun 880c8e9
fix blank line issue
weitingsun bedde63
Merge branch 'wsun/ota-update-modal' of github.com:MetaMask/metamask-…
weitingsun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
161 changes: 161 additions & 0 deletions
161
app/components/UI/OTAUpdatesModal/OTAUpdatesModal.test.tsx
This file contains hidden or 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,161 @@ | ||
| import React from 'react'; | ||
| import { render, fireEvent, waitFor } from '@testing-library/react-native'; | ||
| import { Platform } from 'react-native'; | ||
| import { reloadAsync } from 'expo-updates'; | ||
| import OTAUpdatesModal from './OTAUpdatesModal'; | ||
| import Logger from '../../../util/Logger'; | ||
| import { MetaMetricsEvents } from '../../../core/Analytics'; | ||
|
|
||
| jest.mock( | ||
| '../../../component-library/components/BottomSheets/BottomSheet', | ||
| () => { | ||
| const { View } = jest.requireActual('react-native'); | ||
| const { forwardRef, useImperativeHandle } = jest.requireActual('react'); | ||
|
|
||
| const MockBottomSheet = forwardRef( | ||
| (props: { children: React.ReactNode }, ref: React.Ref<unknown>) => { | ||
| useImperativeHandle(ref, () => ({ | ||
| onOpenBottomSheet: jest.fn(), | ||
| onCloseBottomSheet: jest.fn((callback?: () => void) => { | ||
| if (callback) callback(); | ||
| }), | ||
| })); | ||
|
|
||
| return ( | ||
| <View testID="bottom-sheet" {...props}> | ||
| {props.children} | ||
| </View> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| __esModule: true, | ||
| default: MockBottomSheet, | ||
| }; | ||
| }, | ||
| ); | ||
|
|
||
| jest.mock('expo-updates', () => ({ | ||
| reloadAsync: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../../../util/metrics', () => ({ | ||
| __esModule: true, | ||
| default: jest.fn().mockReturnValue({}), | ||
| })); | ||
|
|
||
| jest.mock('../../../util/Logger', () => ({ | ||
| log: jest.fn(), | ||
| error: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock( | ||
| '../../../component-library/components/HeaderBase', | ||
| () => | ||
| function HeaderBaseMock({ children }: { children: React.ReactNode }) { | ||
| // eslint-disable-next-line react/jsx-no-useless-fragment | ||
| return <>{children}</>; | ||
| }, | ||
| ); | ||
|
|
||
| const mockReloadAsync = reloadAsync as jest.MockedFunction<typeof reloadAsync>; | ||
| const mockLoggerError = Logger.error as jest.MockedFunction< | ||
| typeof Logger.error | ||
| >; | ||
|
|
||
| interface MockEventBuilder { | ||
| addProperties: jest.Mock; | ||
| build: jest.Mock; | ||
| } | ||
|
|
||
| const mockCreateEventBuilder = jest.fn((event: string): MockEventBuilder => { | ||
| const builder: MockEventBuilder = { | ||
| addProperties: jest.fn(), | ||
| build: jest.fn(), | ||
| }; | ||
|
|
||
| builder.addProperties.mockReturnValue(builder); | ||
| builder.build.mockReturnValue({ event }); | ||
|
|
||
| return builder; | ||
| }); | ||
|
|
||
| const mockTrackEvent = jest.fn(); | ||
|
|
||
| jest.mock('../../hooks/useMetrics', () => ({ | ||
| useMetrics: () => ({ | ||
| trackEvent: mockTrackEvent, | ||
| createEventBuilder: mockCreateEventBuilder, | ||
| }), | ||
| })); | ||
|
|
||
| describe('OTAUpdatesModal', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (Platform as unknown as { OS: string }).OS = 'ios'; | ||
| }); | ||
|
|
||
| it('tracks view event on mount', () => { | ||
| render(<OTAUpdatesModal />); | ||
|
|
||
| expect(mockTrackEvent).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| event: MetaMetricsEvents.OTA_UPDATES_MODAL_VIEWED, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('tracks primary action when primary button is pressed', async () => { | ||
| const { getByText } = render(<OTAUpdatesModal />); | ||
|
|
||
| fireEvent.press(getByText('Reload')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockTrackEvent).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| event: MetaMetricsEvents.OTA_UPDATES_MODAL_PRIMARY_ACTION_CLICKED, | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it('reloads app when reload button is pressed on iOS', async () => { | ||
| const { getByText } = render(<OTAUpdatesModal />); | ||
|
|
||
| fireEvent.press(getByText('Reload')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockReloadAsync).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
|
|
||
| it('does not reload app when reload button is pressed on Android', async () => { | ||
| (Platform as unknown as { OS: string }).OS = 'android'; | ||
|
|
||
| const { getByText } = render(<OTAUpdatesModal />); | ||
|
|
||
| fireEvent.press(getByText('Got it')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockReloadAsync).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('logs error when reloadAsync throws', async () => { | ||
| const reloadError = new Error('Reload failed'); | ||
|
|
||
| mockReloadAsync.mockRejectedValueOnce(reloadError); | ||
|
|
||
| const { getByText } = render(<OTAUpdatesModal />); | ||
|
|
||
| fireEvent.press(getByText('Reload')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockLoggerError).toHaveBeenCalledWith( | ||
| reloadError, | ||
| 'OTA Updates: Error reloading app after modal reload pressed', | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
weitingsun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.