summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-26 13:08:59 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-26 13:08:59 -0300
commit2763b0b706ee21bdb781a5b9cda9b37dc1e021cd (patch)
tree44b1a12fddf41192299eef910b87a58aeecb6e80
parentfc7802aca100b542a0e53bcd81eb3b64ba27c6fd (diff)
parent0bbfd2894a9399f8d8b971697e533f0a8553f2da (diff)
downloadmullvadvpn-2763b0b706ee21bdb781a5b9cda9b37dc1e021cd.tar.xz
mullvadvpn-2763b0b706ee21bdb781a5b9cda9b37dc1e021cd.zip
Merge branch 'change-missing-account-expiry-text'
-rw-r--r--gui/packages/desktop/src/renderer/components/Account.js50
-rw-r--r--gui/packages/desktop/src/renderer/components/Connect.js2
-rw-r--r--gui/packages/desktop/test/components/Account.spec.js16
3 files changed, 45 insertions, 23 deletions
diff --git a/gui/packages/desktop/src/renderer/components/Account.js b/gui/packages/desktop/src/renderer/components/Account.js
index 83ab3721cb..bdfaec893e 100644
--- a/gui/packages/desktop/src/renderer/components/Account.js
+++ b/gui/packages/desktop/src/renderer/components/Account.js
@@ -14,7 +14,7 @@ import type { AccountToken } from '../lib/daemon-rpc';
type Props = {
accountToken: AccountToken,
- accountExpiry: string,
+ accountExpiry: ?string,
expiryLocale: string,
onLogout: () => void,
onClose: () => void,
@@ -51,16 +51,6 @@ export default class Account extends Component<Props, State> {
}
render() {
- const expiry = moment(this.props.accountExpiry);
- const isOutOfTime = expiry.isSameOrBefore(moment());
- const formattedExpiry = expiry.toDate().toLocaleString(this.props.expiryLocale, {
- day: 'numeric',
- month: 'long',
- year: 'numeric',
- hour: 'numeric',
- minute: 'numeric',
- });
-
return (
<Layout>
<Container>
@@ -89,13 +79,11 @@ export default class Account extends Component<Props, State> {
<View style={styles.account__row}>
<Text style={styles.account__row_label}>Paid until</Text>
- {isOutOfTime ? (
- <Text style={styles.account__out_of_time} testName="account__out_of_time">
- {'OUT OF TIME'}
- </Text>
- ) : (
- <Text style={styles.account__row_value}>{formattedExpiry}</Text>
- )}
+ <FormattedAccountExpiry
+ expiry={this.props.accountExpiry}
+ locale={this.props.accountExpiryLocale}
+ testName="account__expiry"
+ />
</View>
<View style={styles.account__footer}>
@@ -121,3 +109,29 @@ export default class Account extends Component<Props, State> {
);
}
}
+
+const FormattedAccountExpiry = (props) => {
+ if (!props.expiry) {
+ return <Text style={styles.account__row_value}>{'Currently unavailable'}</Text>;
+ }
+
+ const expiry = moment(props.expiry);
+
+ if (expiry.isSameOrBefore(moment())) {
+ return <Text style={styles.account__out_of_time}>{'OUT OF TIME'}</Text>;
+ }
+
+ const formatOptions = {
+ day: 'numeric',
+ month: 'long',
+ year: 'numeric',
+ hour: 'numeric',
+ minute: 'numeric',
+ };
+
+ return (
+ <Text style={styles.account__row_value}>
+ {expiry.toDate().toLocaleString(props.locale, formatOptions)}
+ </Text>
+ );
+};
diff --git a/gui/packages/desktop/src/renderer/components/Connect.js b/gui/packages/desktop/src/renderer/components/Connect.js
index 8e29cedfb6..ef5fb2e3a7 100644
--- a/gui/packages/desktop/src/renderer/components/Connect.js
+++ b/gui/packages/desktop/src/renderer/components/Connect.js
@@ -19,7 +19,7 @@ import type { ConnectionReduxState } from '../redux/connection/reducers';
type Props = {
connection: ConnectionReduxState,
- accountExpiry: string,
+ accountExpiry: ?string,
selectedRelayName: string,
onSettings: () => void,
onSelectLocation: () => void,
diff --git a/gui/packages/desktop/test/components/Account.spec.js b/gui/packages/desktop/test/components/Account.spec.js
index 34c7b5ddf4..4813f3d20e 100644
--- a/gui/packages/desktop/test/components/Account.spec.js
+++ b/gui/packages/desktop/test/components/Account.spec.js
@@ -54,14 +54,22 @@ describe('components/Account', () => {
const props = makeProps({
accountExpiry: new Date('2001-01-01').toISOString(),
});
- const component = getComponent(render(props), 'account__out_of_time');
- expect(component).to.have.length(1);
+ const component = getComponent(render(props), 'account__expiry');
+ expect(component.dive().html()).to.contain('OUT OF TIME');
});
it('should not display "out of time" message when account is active', () => {
const props = makeProps({});
- const component = getComponent(render(props), 'account__out_of_time');
- expect(component).to.have.length(0);
+ const component = getComponent(render(props), 'account__expiry');
+ expect(component.dive().html()).to.not.contain('OUT OF TIME');
+ });
+
+ it('should not display "unavailable" message when account expiry is missing', () => {
+ const props = makeProps({
+ accountExpiry: null,
+ });
+ const component = getComponent(render(props), 'account__expiry');
+ expect(component.dive().html()).to.contain('Currently unavailable');
});
});