MM-20682 Unit test for dimissing the status modal before the sidebar (#3664)

This commit is contained in:
Elias Nahum 2019-12-04 18:30:12 -03:00 committed by GitHub
parent a0c5ad5c2b
commit 0909a30633
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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(<SettingsSidebar {...baseProps}/>);
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);
});
});