From 0909a306332984643eef400cf2a51772583c2bac Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 4 Dec 2019 18:30:12 -0300 Subject: [PATCH] MM-20682 Unit test for dimissing the status modal before the sidebar (#3664) --- .../settings/settings_sidebar.test.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/components/sidebars/settings/settings_sidebar.test.js diff --git a/app/components/sidebars/settings/settings_sidebar.test.js b/app/components/sidebars/settings/settings_sidebar.test.js new file mode 100644 index 000000000..8dc98a9d6 --- /dev/null +++ b/app/components/sidebars/settings/settings_sidebar.test.js @@ -0,0 +1,57 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react'; +import {shallow} from 'enzyme'; + +import Preferences from 'mattermost-redux/constants/preferences'; + +import SettingsSidebar from './settings_sidebar'; + +jest.mock('react-intl'); + +jest.mock('react-native-vector-icons/MaterialIcons', () => ({ + getImageSource: jest.fn().mockResolvedValue(null), +})); + +describe('SettingsSidebar', () => { + const baseProps = { + actions: { + logout: jest.fn(), + setStatus: jest.fn(), + }, + blurPostTextBox: jest.fn(), + currentUser: {}, + status: 'online', + theme: Preferences.THEMES.default, + }; + + test('Android back button should dismiss status modal first', () => { + const wrapper = shallow(); + + const instance = wrapper.instance(); + + // Mocking the reference the DrawerLayout as the component is not really being mounted + instance.drawerRef = { + closeDrawer: jest.fn(() => { + instance.drawerOpened = false; + }), + }; + + // simulate that the drawer is opened + instance.drawerOpened = true; + + // simulate that the status modal is opened + instance.statusModal = true; + + // this simulates the first tap on the back button that closes the status modal + let backButtonResult = instance.handleAndroidBack(); + expect(backButtonResult).toBe(false); + expect(instance.drawerOpened).toBe(true); + + // this simulates a second tap on the back button that closes the drawer + backButtonResult = instance.handleAndroidBack(); + expect(backButtonResult).toBe(true); + expect(instance.drawerOpened).toBe(false); + }); +});