From 9a79c5405d3c1199b91bb387093b762966bd9985 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Tue, 29 Mar 2022 02:51:33 -0400 Subject: [PATCH] Add SettingsScreen test --- jest.setup.js | 4 + screens/__tests__/SettingsScreen.test.js | 47 ++ .../__snapshots__/SettingsScreen.test.js.snap | 745 ++++++++++++++++++ 3 files changed, 796 insertions(+) create mode 100644 screens/__tests__/SettingsScreen.test.js create mode 100644 screens/__tests__/__snapshots__/SettingsScreen.test.js.snap diff --git a/jest.setup.js b/jest.setup.js index 4c49ab9..6b17417 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -4,6 +4,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +/* AsyncStorage Mock */ +import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock'; +jest.mock('@react-native-async-storage/async-storage', () => mockAsyncStorage); + /* Fetch and AbortController Mocks */ import { enableFetchMocks } from 'jest-fetch-mock'; import { AbortController } from 'node-abort-controller'; diff --git a/screens/__tests__/SettingsScreen.test.js b/screens/__tests__/SettingsScreen.test.js new file mode 100644 index 0000000..6030e06 --- /dev/null +++ b/screens/__tests__/SettingsScreen.test.js @@ -0,0 +1,47 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { NavigationContainer } from '@react-navigation/native'; +import { render } from '@testing-library/react-native'; +import React from 'react'; +import { Platform } from 'react-native'; +import { ThemeProvider } from 'react-native-elements'; + +import '../../i18n'; +import { useStores } from '../../hooks/useStores'; +import SettingsScreen from '../SettingsScreen'; + +// Mock Platform to allow testing platform specific code +jest.mock('react-native/Libraries/Utilities/Platform'); +// Button fails to render in some cases so it needs mocked +jest.mock('react-native-elements/dist/buttons/Button', () => 'Button'); + +jest.mock('../../hooks/useStores'); +useStores.mockImplementation(() => ({ + rootStore: { + serverStore: { + fetchInfo: jest.fn(), + servers: [] + }, + settingStore: {} + } +})); + +describe('SettingsScreen', () => { + it('should render correctly', () => { + Platform.Version = '13'; + + const { toJSON } = render( + + + + + + ); + + expect(toJSON()).toMatchSnapshot(); + }); +}); diff --git a/screens/__tests__/__snapshots__/SettingsScreen.test.js.snap b/screens/__tests__/__snapshots__/SettingsScreen.test.js.snap new file mode 100644 index 0000000..1ce28cb --- /dev/null +++ b/screens/__tests__/__snapshots__/SettingsScreen.test.js.snap @@ -0,0 +1,745 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SettingsScreen should render correctly 1`] = ` + + + + + + + + + + + + +