MM-22134: Fix StatusBar after Photo-Camera post in landscape mode (#3986)

* Fix StatusBar after Photo-Camera post in landscape mode

* revised tests
This commit is contained in:
ami9000 2020-03-02 08:24:09 -08:00 committed by GitHub
parent 57d991f584
commit 60be3d2783
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 74 additions and 10 deletions

View file

@ -8,6 +8,7 @@ import {
NativeModules,
Platform,
StyleSheet,
StatusBar,
} from 'react-native';
import RNFetchBlob from 'rn-fetch-blob';
import DeviceInfo from 'react-native-device-info';
@ -178,6 +179,7 @@ export default class AttachmentButton extends PureComponent {
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
StatusBar.setHidden(false);
emmProvider.inBackgroundSince = null;
if (response.error || response.didCancel) {
return;
@ -213,6 +215,7 @@ export default class AttachmentButton extends PureComponent {
if (hasPhotoPermission) {
ImagePicker.launchImageLibrary(options, (response) => {
StatusBar.setHidden(false);
emmProvider.inBackgroundSince = null;
if (response.error || response.didCancel) {
return;
@ -527,4 +530,4 @@ const style = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
});
});

View file

@ -5,7 +5,7 @@ import React from 'react';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
import {Alert} from 'react-native';
import {Alert, StatusBar} from 'react-native';
import Preferences from 'mattermost-redux/constants/preferences';
@ -15,7 +15,8 @@ import AttachmentButton from './index';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
launchCamera: jest.fn(),
launchCamera: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
launchImageLibrary: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('AttachmentButton', () => {
@ -104,4 +105,32 @@ describe('AttachmentButton', () => {
expect(Alert.alert).toHaveBeenCalled();
expect(hasPhotoPermission).toBe(false);
});
});
test('should re-enable StatusBar after ImagePicker launchCamera finishes', async () => {
const wrapper = shallow(
<AttachmentButton {...baseProps}/>,
{context: {intl: {formatMessage}}},
);
const instance = wrapper.instance();
jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
jest.spyOn(StatusBar, 'setHidden');
await instance.attachFileFromCamera();
expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
});
test('should re-enable StatusBar after ImagePicker launchImageLibrary finishes', async () => {
const wrapper = shallow(
<AttachmentButton {...baseProps}/>,
{context: {intl: {formatMessage}}},
);
const instance = wrapper.instance();
jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
jest.spyOn(StatusBar, 'setHidden');
await instance.attachFileFromLibrary();
expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
});
});

View file

@ -6,6 +6,7 @@ import {intlShape} from 'react-intl';
import {
Alert,
Platform,
StatusBar,
} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import {ICON_SIZE} from 'app/constants/post_textbox';
@ -93,6 +94,7 @@ export default class AttachmentButton extends PureComponent {
if (hasCameraPermission) {
ImagePicker.launchCamera(options, (response) => {
StatusBar.setHidden(false);
if (response.error || response.didCancel) {
return;
}

View file

@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
import {Alert, Platform} from 'react-native';
import {Alert, Platform, StatusBar} from 'react-native';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
@ -12,7 +12,7 @@ import CameraButton from './camera_button';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
launchCamera: jest.fn(),
launchCamera: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('CameraButton', () => {
@ -100,4 +100,18 @@ describe('CameraButton', () => {
expect(hasPermission).toBe(true);
}
});
});
test('should re-enable StatusBar after ImagePicker launchCamera finishes', async () => {
const wrapper = shallow(
<CameraButton {...baseProps}/>,
{context: {intl: {formatMessage}}},
);
const instance = wrapper.instance();
jest.spyOn(instance, 'hasCameraPermission').mockReturnValue(true);
jest.spyOn(StatusBar, 'setHidden');
await instance.attachFileFromCamera();
expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
});
});

View file

@ -6,6 +6,7 @@ import {intlShape} from 'react-intl';
import {
Alert,
Platform,
StatusBar,
} from 'react-native';
import DeviceInfo from 'react-native-device-info';
import {ICON_SIZE} from 'app/constants/post_textbox';
@ -95,6 +96,7 @@ export default class ImageUploadButton extends PureComponent {
if (hasPhotoPermission) {
ImagePicker.launchImageLibrary(options, (response) => {
StatusBar.setHidden(false);
if (response.error || response.didCancel) {
return;
}

View file

@ -2,7 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
import {Alert, Platform} from 'react-native';
import {Alert, Platform, StatusBar} from 'react-native';
import {shallow} from 'enzyme';
import Permissions from 'react-native-permissions';
@ -12,7 +12,7 @@ import ImageUploadButton from './image_upload_button';
jest.mock('react-intl');
jest.mock('react-native-image-picker', () => ({
launchCamera: jest.fn(),
launchImageLibrary: jest.fn().mockImplementation((options, callback) => callback({didCancel: true})),
}));
describe('ImageUploadButton', () => {
@ -101,4 +101,18 @@ describe('ImageUploadButton', () => {
expect(hasPermission).toBe(true);
}
});
});
test('should re-enable StatusBar after ImagePicker launchImageLibrary finishes', async () => {
const wrapper = shallow(
<ImageUploadButton {...baseProps}/>,
{context: {intl: {formatMessage}}},
);
const instance = wrapper.instance();
jest.spyOn(instance, 'hasPhotoPermission').mockReturnValue(true);
jest.spyOn(StatusBar, 'setHidden');
await instance.attachFileFromLibrary();
expect(StatusBar.setHidden).toHaveBeenCalledWith(false);
});
});