-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent unnecessary network toasts (#1448)
Signed-off-by: Bryce McMath <[email protected]>
- Loading branch information
1 parent
8dac71d
commit d391221
Showing
7 changed files
with
120 additions
and
121 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
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
61 changes: 61 additions & 0 deletions
61
packages/legacy/core/__tests__/components/NetInfo.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,61 @@ | ||
import { render, waitFor } from '@testing-library/react-native' | ||
import React from 'react' | ||
import Toast from 'react-native-toast-message' | ||
|
||
import mockNetworkContext from '../contexts/network' | ||
import NetInfo from '../../App/components/network/NetInfo' | ||
import toastConfig from '../../App/components/toast/ToastConfig' | ||
import { BasicAppContext } from '../helpers/app' | ||
|
||
// Bifold's top offset for toasts | ||
const topOffset = 15 | ||
|
||
describe('NetInfo Component', () => { | ||
it('should not show toast when internet is reachable', async () => { | ||
mockNetworkContext.assertInternetReachable.mockReturnValue(true) | ||
|
||
const { queryByText } = render( | ||
<BasicAppContext> | ||
<NetInfo /> | ||
<Toast topOffset={topOffset} config={toastConfig} /> | ||
</BasicAppContext> | ||
) | ||
|
||
await waitFor(async () => { | ||
const toast = await queryByText('NetInfo.NoInternetConnectionTitle', { exact: false }) | ||
expect(toast).toBeNull() | ||
}) | ||
}) | ||
|
||
it('should show toast when internet is not reachable', async () => { | ||
mockNetworkContext.assertInternetReachable.mockReturnValue(false) | ||
|
||
const { queryByText } = render( | ||
<BasicAppContext> | ||
<NetInfo /> | ||
<Toast topOffset={topOffset} config={toastConfig} /> | ||
</BasicAppContext> | ||
) | ||
|
||
await waitFor(async () => { | ||
const toast = await queryByText('NetInfo.NoInternetConnectionTitle', { exact: false }) | ||
expect(toast).toBeTruthy() | ||
}) | ||
}) | ||
|
||
it('should not show toast when internet reachability is unknown', async () => { | ||
mockNetworkContext.assertInternetReachable.mockReturnValue(null) | ||
|
||
const { queryByText } = render( | ||
<BasicAppContext> | ||
<NetInfo /> | ||
<Toast topOffset={topOffset} config={toastConfig} /> | ||
</BasicAppContext> | ||
) | ||
|
||
await waitFor(async () => { | ||
const toast = await queryByText('NetInfo.NoInternetConnectionTitle', { exact: false }) | ||
expect(toast).toBeNull() | ||
}) | ||
}) | ||
}) |
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