-
-
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.
update account connect and account permissions with snapshot testing
- Loading branch information
Showing
4 changed files
with
1,000 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
app/components/Views/AccountConnect/AccountConnect.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,78 @@ | ||
import React from 'react'; | ||
import renderWithProvider, { | ||
DeepPartial, | ||
} from '../../../util/test/renderWithProvider'; | ||
import AccountConnect from './AccountConnect'; | ||
import { backgroundState } from '../../../util/test/initial-root-state'; | ||
import { RootState } from '../../../reducers'; | ||
|
||
const mockedNavigate = jest.fn(); | ||
const mockedTrackEvent = jest.fn(); | ||
|
||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useNavigation: () => ({ | ||
navigate: mockedNavigate, | ||
}), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../components/hooks/useMetrics', () => ({ | ||
useMetrics: () => ({ | ||
trackEvent: mockedTrackEvent, | ||
}), | ||
})); | ||
|
||
jest.mock('react-native-safe-area-context', () => { | ||
const inset = { top: 0, right: 0, bottom: 0, left: 0 }; | ||
const frame = { width: 0, height: 0, x: 0, y: 0 }; | ||
return { | ||
SafeAreaProvider: jest.fn().mockImplementation(({ children }) => children), | ||
SafeAreaConsumer: jest | ||
.fn() | ||
.mockImplementation(({ children }) => children(inset)), | ||
useSafeAreaInsets: jest.fn().mockImplementation(() => inset), | ||
useSafeAreaFrame: jest.fn().mockImplementation(() => frame), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../core/Engine', () => ({ | ||
context: { | ||
PhishingController: { | ||
maybeUpdateState: jest.fn(), | ||
test: jest.fn((url: string) => { | ||
if (url === 'phishing.com') return { result: true }; | ||
return { result: false }; | ||
}), | ||
}, | ||
}, | ||
})); | ||
|
||
const mockInitialState: DeepPartial<RootState> = { | ||
settings: {}, | ||
engine: { | ||
backgroundState: { | ||
...backgroundState, | ||
}, | ||
}, | ||
}; | ||
|
||
describe('AccountConnect', () => { | ||
it('renders correctly', () => { | ||
const { toJSON } = renderWithProvider( | ||
<AccountConnect | ||
route={{ | ||
params: { | ||
hostInfo: { metadata: { origin: 'test' } }, | ||
permissionRequestId: 'test', | ||
}, | ||
}} | ||
/>, | ||
{ state: mockInitialState }, | ||
); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.