summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-08-08 16:35:56 +0200
committerAndrej Mihajlov <and@mullvad.net>2018-08-08 16:46:07 +0200
commita8f2831cd50e98b1d126b8c3169adcf1ef75b8a2 (patch)
tree05bfd7a9f05456220f11f40329093b127a5b20a2 /test
parentbc75cc52fb405f490f716bec90a7336c9804a98a (diff)
downloadmullvadvpn-a8f2831cd50e98b1d126b8c3169adcf1ef75b8a2.tar.xz
mullvadvpn-a8f2831cd50e98b1d126b8c3169adcf1ef75b8a2.zip
Refine tests
Diffstat (limited to 'test')
-rw-r--r--test/components/Settings.spec.js143
1 files changed, 77 insertions, 66 deletions
diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js
index bfdf458160..a9302a9ea7 100644
--- a/test/components/Settings.spec.js
+++ b/test/components/Settings.spec.js
@@ -8,91 +8,96 @@ import { CloseBarItem } from '../../app/components/NavigationBar';
type SettingsProps = React.ElementProps<typeof Settings>;
describe('components/Settings', () => {
- const makeProps = (mergeProps: $Shape<SettingsProps> = {}): SettingsProps => {
- const defaultProps: SettingsProps = {
- loginState: 'none',
- accountExpiry: null,
- appVersion: '',
- onQuit: () => {},
- onClose: () => {},
- onViewAccount: () => {},
- onViewSupport: () => {},
- onViewAdvancedSettings: () => {},
- onViewPreferences: () => {},
- onExternalLink: (_type) => {},
- updateAccountExpiry: () => Promise.resolve(),
- };
- return Object.assign({}, defaultProps, mergeProps);
+ const defaultProps: SettingsProps = {
+ loginState: 'none',
+ accountExpiry: null,
+ appVersion: '',
+ onQuit: () => {},
+ onClose: () => {},
+ onViewAccount: () => {},
+ onViewSupport: () => {},
+ onViewAdvancedSettings: () => {},
+ onViewPreferences: () => {},
+ onExternalLink: (_type) => {},
+ updateAccountExpiry: () => Promise.resolve(),
};
it('should show quit button when logged out', () => {
- const props = makeProps({
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__quit');
expect(component).to.have.length(1);
});
it('should show quit button when logged in', () => {
- const props = makeProps({
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__quit');
expect(component).to.have.length(1);
});
it('should show external links when logged out', () => {
- const props = makeProps({
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__external_link');
expect(component.length).to.be.above(0);
});
it('should show external links when logged in', () => {
- const props = makeProps({
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__external_link');
expect(component.length).to.be.above(0);
});
it('should show account section when logged in', () => {
- const props = makeProps({
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__account');
expect(component).to.have.length(1);
});
it('should hide account section when logged out', () => {
- const props = makeProps({
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ };
const elements = getComponent(shallow(<Settings {...props} />), 'settings__account');
expect(elements).to.have.length(0);
});
it('should hide account link when not logged in', () => {
- const props = makeProps({
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ };
const elements = getComponent(shallow(<Settings {...props} />), 'settings__view_account');
expect(elements).to.have.length(0);
});
it('should show out-of-time message for unpaid account', () => {
- const props = makeProps({
- accountExpiry: new Date('2001-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2001-01-01').toISOString(),
+ };
const component = getComponent(
shallow(<Settings {...props} />),
'settings__account_paid_until_subtext',
@@ -101,10 +106,11 @@ describe('components/Settings', () => {
});
it('should hide out-of-time message for paid account', () => {
- const props = makeProps({
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ };
const component = getComponent(
shallow(<Settings {...props} />),
'settings__account_paid_until_subtext',
@@ -113,11 +119,12 @@ describe('components/Settings', () => {
});
it('should call close callback', (done) => {
- const props = makeProps({
- onClose: () => done(),
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ onClose: () => done(),
+ };
const component = shallow(<Settings {...props} />)
.find(CloseBarItem)
.dive();
@@ -125,22 +132,23 @@ describe('components/Settings', () => {
});
it('should call quit callback', (done) => {
- const props = makeProps({
- onQuit: () => done(),
-
+ const props = {
+ ...defaultProps,
loginState: 'none',
accountExpiry: null,
- });
+ onQuit: () => done(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__quit');
component.simulate('press');
});
it('should call account callback', (done) => {
- const props = makeProps({
- onViewAccount: () => done(),
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ onViewAccount: () => done(),
+ };
const component = getComponent(
shallow(<Settings {...props} />),
'settings__account_paid_until_button',
@@ -149,45 +157,48 @@ describe('components/Settings', () => {
});
it('should call advanced settings callback', (done) => {
- const props = makeProps({
- onViewAdvancedSettings: () => done(),
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ onViewAdvancedSettings: () => done(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__advanced');
component.simulate('press');
});
it('should call preferences callback', (done) => {
- const props = makeProps({
- onViewPreferences: () => done(),
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ onViewPreferences: () => done(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__preferences');
component.simulate('press');
});
it('should call support callback', (done) => {
- const props = makeProps({
- onViewSupport: () => done(),
- accountExpiry: new Date('2038-01-01').toISOString(),
+ const props = {
+ ...defaultProps,
loginState: 'ok',
- });
+ accountExpiry: new Date('2038-01-01').toISOString(),
+ onViewSupport: () => done(),
+ };
const component = getComponent(shallow(<Settings {...props} />), 'settings__view_support');
component.simulate('press');
});
it('should call external links callback', () => {
const collectedExternalLinkTypes: Array<string> = [];
- const props = makeProps({
+ const props = {
+ ...defaultProps,
+ loginState: 'none',
+ accountExpiry: null,
onExternalLink: (type) => {
collectedExternalLinkTypes.push(type);
},
-
- loginState: 'none',
- accountExpiry: null,
- });
+ };
const container = getComponent(shallow(<Settings {...props} />), 'settings__external_link');
container
.find({ testName: 'settings__external_link' })