summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2018-02-21 10:45:11 +0100
committerAndrej Mihajlov <and@mullvad.net>2018-02-21 10:45:11 +0100
commitde737c54c413f96c35b4e9bc6280fc7d26e4fa83 (patch)
tree0cf470c59b4c7c8a6327e64610f68f5facd78d6d /test
parentae9c255b3ecdec341090c932db6cb261147a7382 (diff)
parent1214138633bcca19a1b96622400f3fbcf4044bd9 (diff)
downloadmullvadvpn-de737c54c413f96c35b4e9bc6280fc7d26e4fa83.tar.xz
mullvadvpn-de737c54c413f96c35b4e9bc6280fc7d26e4fa83.zip
Merge branch 'update-flow'
Diffstat (limited to 'test')
-rw-r--r--test/autologin.spec.js2
-rw-r--r--test/components/Accordion.spec.js6
-rw-r--r--test/components/AccountInput.spec.js10
-rw-r--r--test/components/SelectLocation.spec.js9
-rw-r--r--test/components/Switch.spec.js49
-rw-r--r--test/helpers/IpcChain.js27
-rw-r--r--test/helpers/ipc-helpers.js2
-rw-r--r--test/mocks/ipc.js10
8 files changed, 68 insertions, 47 deletions
diff --git a/test/autologin.spec.js b/test/autologin.spec.js
index 5821166eff..c8fd6c170c 100644
--- a/test/autologin.spec.js
+++ b/test/autologin.spec.js
@@ -63,7 +63,7 @@ describe('autologin', () => {
it('should mark the state as not logged in if no account is set', () => {
const { store, backend, mockIpc } = setupBackendAndStore();
- mockIpc.getAccount = () => new Promise(r => r(null));
+ mockIpc.getAccount = () => Promise.resolve(null);
return backend.autologin()
.catch( () => {}) // ignore errors
diff --git a/test/components/Accordion.spec.js b/test/components/Accordion.spec.js
index 2357e27dfc..1ef4d2871e 100644
--- a/test/components/Accordion.spec.js
+++ b/test/components/Accordion.spec.js
@@ -2,17 +2,15 @@
/* eslint react/no-find-dom-node: off */
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactDOM from 'react-dom';
import Accordion from '../../app/components/Accordion';
-import type { AccordionProps } from '../../app/components/Accordion';
-
describe('components/Accordion', () => {
let container: ?HTMLElement;
- function renderIntoDocument(instance: React.Element<AccordionProps>) {
+ function renderIntoDocument(instance) {
if(!container) {
container = document.createElement('div');
if(!document.documentElement) {
diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js
index ee73323950..701a1c243e 100644
--- a/test/components/AccountInput.spec.js
+++ b/test/components/AccountInput.spec.js
@@ -1,15 +1,19 @@
// @flow
import { expect } from 'chai';
import { createKeyEvent } from '../helpers/dom-events';
-import React from 'react';
+import * as React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import AccountInput from '../../app/components/AccountInput';
import type { AccountInputProps } from '../../app/components/AccountInput';
describe('components/AccountInput', () => {
- const getInputRef = (component: AccountInput): HTMLInputElement => {
- return ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ const getInputRef = (component) => {
+ const node = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ if(!(node instanceof HTMLInputElement)) {
+ throw new Error('Node is expected to be an instance of HTMLInputElement');
+ }
+ return node;
};
const render = (mergeProps: $Shape<AccountInputProps>) => {
diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js
index eb72b03c57..59a8dc9770 100644
--- a/test/components/SelectLocation.spec.js
+++ b/test/components/SelectLocation.spec.js
@@ -1,7 +1,7 @@
// @flow
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import SelectLocation from '../../app/components/SelectLocation';
@@ -47,7 +47,7 @@ describe('components/SelectLocation', () => {
return Object.assign({}, defaultProps, mergeProps);
};
- const render = (props: SelectLocationProps): SelectLocation => {
+ const render = (props: SelectLocationProps) => {
return ReactTestUtils.renderIntoDocument(
<SelectLocation { ...props } />
);
@@ -58,7 +58,10 @@ describe('components/SelectLocation', () => {
onClose: () => done()
});
const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'select-location__close');
- Simulate.click(domNode);
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.click(domNode);
+ }
});
it('should call select callback for country', (done) => {
diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js
index db7fe8d8c4..eaac6dc08c 100644
--- a/test/components/Switch.spec.js
+++ b/test/components/Switch.spec.js
@@ -1,7 +1,7 @@
// @flow
import { expect } from 'chai';
-import React from 'react';
+import * as React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
import Switch from '../../app/components/Switch';
@@ -10,7 +10,7 @@ describe('components/Switch', () => {
let container: ?HTMLElement;
- function renderIntoDocument(instance: React.Element<*>): React.Component<*, *, *> {
+ function renderIntoDocument(instance: React.Element<*>): React.Component<*, *> {
if(container) {
throw new Error('Unmount previously rendered component first.');
}
@@ -42,10 +42,12 @@ describe('components/Switch', () => {
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
- Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
- Simulate.change(domNode, { target: { checked: true } });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
+ Simulate.change(domNode, { target: { checked: true } });
+ }
});
it('should switch off', (done) => {
@@ -57,10 +59,12 @@ describe('components/Switch', () => {
<Switch isOn={ true } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
- Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
- Simulate.change(domNode, { target: { checked: false } });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ Simulate.mouseUp(domNode, { clientX: 100, clientY: 0 });
+ Simulate.change(domNode, { target: { checked: false } });
+ }
});
it('should handle left to right swipe', (done) => {
@@ -72,8 +76,10 @@ describe('components/Switch', () => {
<Switch isOn={ false } onChange={ onChange } />
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ }
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 150, clientY: 0 }));
@@ -90,7 +96,10 @@ describe('components/Switch', () => {
);
const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- Simulate.mouseDown(domNode, { clientX: 150, clientY: 0 });
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 150, clientY: 0 });
+ }
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mousemove', { clientX: 100, clientY: 0 }));
@@ -105,17 +114,23 @@ describe('components/Switch', () => {
const component = renderIntoDocument(
<Switch isOn={ false } onChange={ onChange } />
);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ Simulate.mouseDown(domNode, { clientX: 100, clientY: 0 });
+ }
setTimeout(() => {
// Switch listens to events on document
document.dispatchEvent(new MouseEvent('mouseup', { clientX: 100, clientY: 0 }));
try {
- // should not trigger onChange()
- Simulate.change(domNode);
+ // See: https://github.com/facebook/flow/pull/5841
+ if(domNode) {
+ // should not trigger onChange()
+ Simulate.change(domNode);
+ }
done();
} catch(e) {
done(e);
diff --git a/test/helpers/IpcChain.js b/test/helpers/IpcChain.js
index a62626a6a6..4e3ddea79e 100644
--- a/test/helpers/IpcChain.js
+++ b/test/helpers/IpcChain.js
@@ -7,7 +7,7 @@ export class IpcChain {
_expectedCalls: Array<string>;
_recordedCalls: Array<string>;
_mockIpc: {};
- _done: (*) => void;
+ _done: (?Error) => void;
_aborted: boolean;
constructor(mockIpc: {}) {
@@ -17,28 +17,29 @@ export class IpcChain {
this._aborted = false;
}
- require(ipcCall: string): StepBuilder {
+ require<R>(ipcCall: string): StepBuilder<R> {
this._expectedCalls.push(ipcCall);
return new StepBuilder(ipcCall, this._addStep.bind(this));
}
- _addStep(step: StepBuilder) {
+ _addStep<R>(step: StepBuilder<R>) {
const me = this;
this._mockIpc[step.ipcCall] = function() {
return new Promise(r => me._stepPromiseCallback(step, r, arguments));
};
}
- _stepPromiseCallback(step, resolve, args) {
+ _stepPromiseCallback<R>(step: StepBuilder<R>, resolve: (?R) => void, args: Array<mixed>) {
if (this._aborted) {
return;
}
this._registerCall(step.ipcCall);
- if (step.inputValidation) {
+ const inputValidation = step.inputValidation;
+ if (inputValidation) {
const failedInputValidation = failFast(() => {
- step.inputValidation(...args);
+ inputValidation(...args);
}, this._done);
if (failedInputValidation) {
@@ -77,23 +78,23 @@ export class IpcChain {
}
}
-class StepBuilder {
+class StepBuilder<R> {
ipcCall: string;
- inputValidation: () => void;
- returnValue: *;
- _cb: (StepBuilder) => void;
+ inputValidation: ?() => void;
+ returnValue: ?R;
+ _cb: (StepBuilder<R>) => void;
- constructor(ipcCall: string, cb: (StepBuilder)=> void) {
+ constructor(ipcCall: string, cb: (StepBuilder<R>) => void) {
this.ipcCall = ipcCall;
this._cb = cb;
}
- withInputValidation(iv: () => void): StepBuilder {
+ withInputValidation(iv: () => void): this {
this.inputValidation = iv;
return this;
}
- withReturnValue(rv: *): StepBuilder {
+ withReturnValue(rv: R): this {
this.returnValue = rv;
return this;
}
diff --git a/test/helpers/ipc-helpers.js b/test/helpers/ipc-helpers.js
index 2a2dd1e6b8..3f8307ccf3 100644
--- a/test/helpers/ipc-helpers.js
+++ b/test/helpers/ipc-helpers.js
@@ -6,7 +6,7 @@ import configureStore from '../../app/redux/store';
import { createMemoryHistory } from 'history';
import { mockStore } from '../mocks/redux';
-type DoneCallback = (?mixed) => void;
+type DoneCallback = (?Error) => void;
type Check = () => void;
export function setupIpcAndStore() {
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index 2ba32ecf2f..900e149c33 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -1,13 +1,13 @@
// @flow
-import type { IpcFacade, BackendState } from '../../app/lib/ipc-facade';
+import type { IpcFacade, AccountToken, AccountData, BackendState } from '../../app/lib/ipc-facade';
interface MockIpc {
sendNewState: (BackendState) => void;
killWebSocket: () => void;
- -getAccountData: *;
- -connect: *;
- -getAccount: *;
- -authenticate: *;
+ -getAccountData: (AccountToken) => Promise<AccountData>;
+ -connect: () => Promise<void>;
+ -getAccount: () => Promise<?AccountToken>;
+ -authenticate: (string) => Promise<void>;
}
export function newMockIpc() {