Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable share button on Export screen if no log data #275

Merged
merged 2 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions app/views/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TouchableOpacity,
BackHandler,
} from 'react-native';
import PropTypes from 'prop-types';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import RNFetchBlob from 'rn-fetch-blob';
import Share from 'react-native-share';
Expand All @@ -23,8 +24,9 @@ import languages from './../locales/languages';
const width = Dimensions.get('window').width;
const base64 = RNFetchBlob.base64;

function ExportScreen() {
function ExportScreen({ shareButtonDisabled }) {
const [pointStats, setPointStats] = useState(false);
const [buttonDisabled, setButtonDisabled] = useState(shareButtonDisabled);
const { navigate } = useNavigation();

function handleBackPress() {
Expand All @@ -37,6 +39,7 @@ function ExportScreen() {
const locationData = new LocationData();
locationData.getPointStats().then(pointStats => {
setPointStats(pointStats);
setButtonDisabled(pointStats.pointCount === 0);
});
return () => {};
}, []),
Expand All @@ -54,7 +57,7 @@ function ExportScreen() {
navigate('LocationTrackingScreen', {});
}

async function OnShare() {
async function onShare() {
try {
let locationData = await new LocationData().getLocationData();

Expand Down Expand Up @@ -124,8 +127,20 @@ function ExportScreen() {
<Text style={styles.sectionDescription}>
{languages.t('label.export_para_2')}
</Text>
<TouchableOpacity style={styles.buttonTouchable} onPress={OnShare}>
<Text style={styles.buttonText}>{languages.t('label.share')}</Text>
<TouchableOpacity
disabled={buttonDisabled}
onPress={onShare}
style={[
styles.buttonTouchable,
buttonDisabled && styles.buttonDisabled,
]}>
<Text
style={[
styles.buttonText,
buttonDisabled && styles.buttonDisabled,
]}>
{languages.t('label.share')}
</Text>
</TouchableOpacity>
<Text style={[styles.sectionDescription, { marginTop: 36 }]}>
{languages.t('label.data_covers')}{' '}
Expand Down Expand Up @@ -192,6 +207,9 @@ const styles = StyleSheet.create({
textAlign: 'center',
color: '#ffffff',
},
buttonDisabled: {
opacity: 0.7,
},
mainText: {
fontSize: 18,
lineHeight: 24,
Expand All @@ -206,7 +224,6 @@ const styles = StyleSheet.create({
textAlignVertical: 'center',
padding: 20,
},

headerContainer: {
flexDirection: 'row',
height: 60,
Expand All @@ -232,4 +249,12 @@ const styles = StyleSheet.create({
},
});

ExportScreen.propTypes = {
shareButtonDisabled: PropTypes.bool,
};

ExportScreen.defaultProps = {
shareButtonDisabled: true,
};

export default ExportScreen;
32 changes: 25 additions & 7 deletions app/views/__tests__/Export.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import 'react-native';
import { TouchableOpacity } from 'react-native';
import React from 'react';
import renderer from 'react-test-renderer';
import renderer, { create } from 'react-test-renderer';
import Export from '../Export';

it('renders correctly', () => {
const tree = renderer
.create(<Export />)
.toJSON();
expect(tree).toMatchSnapshot();
describe('<Export />', () => {
it('renders correctly', () => {
const tree = renderer
.create(<Export />)
.toJSON();
expect(tree).toMatchSnapshot();
});

describe('Share button', () => {
it('should be disabled if not data is in the log', () => {
const component = create(<Export />);
const instance = component.root;
const shareButton = instance.findAllByType(TouchableOpacity)[1];
expect(shareButton.props.disabled).toBeTruthy();
});

it('should be disabled if not data is in the log', () => {
const component = create(<Export shareButtonDisabled={false} />);
const instance = component.root;
const shareButton = instance.findAllByType(TouchableOpacity)[1];
expect(shareButton.props.disabled).toBeFalsy();
});
})
});
25 changes: 15 additions & 10 deletions app/views/__tests__/__snapshots__/Export.spec.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders correctly 1`] = `
exports[`<Export /> renders correctly 1`] = `
<RCTSafeAreaView
emulateUnlessSupported={true}
style={
Expand Down Expand Up @@ -126,21 +126,26 @@ exports[`renders correctly 1`] = `
"height": 52,
"justifyContent": "center",
"marginTop": 30,
"opacity": 1,
"opacity": 0.7,
"width": 589.9499999999999,
}
}
>
<Text
style={
Object {
"color": "#ffffff",
"fontFamily": "OpenSans-Bold",
"fontSize": 14,
"letterSpacing": 0,
"lineHeight": 19,
"textAlign": "center",
}
Array [
Object {
"color": "#ffffff",
"fontFamily": "OpenSans-Bold",
"fontSize": 14,
"letterSpacing": 0,
"lineHeight": 19,
"textAlign": "center",
},
Object {
"opacity": 0.7,
},
]
}
>
SHARE
Expand Down
1 change: 0 additions & 1 deletion jestSetupFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jest.mock('react-native-popup-menu', () => ({
MenuOption: 'MenuOption',
MenuTrigger: 'MenuTrigger',
}));

jest.mock('@react-navigation/native', () => {
return {
createAppContainer: jest
Expand Down
Loading