summaryrefslogtreecommitdiffhomepage
path: root/test/components
diff options
context:
space:
mode:
Diffstat (limited to 'test/components')
-rw-r--r--test/components/Account.spec.js75
-rw-r--r--test/components/AccountInput.spec.js183
-rw-r--r--test/components/Connect.spec.js138
-rw-r--r--test/components/Login.spec.js82
-rw-r--r--test/components/Preferences.spec.js29
-rw-r--r--test/components/SelectLocation.spec.js113
-rw-r--r--test/components/Settings.spec.js213
-rw-r--r--test/components/Support.spec.js122
-rw-r--r--test/components/Switch.spec.js128
9 files changed, 0 insertions, 1083 deletions
diff --git a/test/components/Account.spec.js b/test/components/Account.spec.js
deleted file mode 100644
index 703ce3d27f..0000000000
--- a/test/components/Account.spec.js
+++ /dev/null
@@ -1,75 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import Account from '../../app/components/Account';
-import { BackBarItem } from '../../app/components/NavigationBar';
-
-type AccountProps = React.ElementProps<typeof Account>;
-
-describe('components/Account', () => {
- const makeProps = (mergeProps: $Shape<AccountProps>): AccountProps => {
- const defaultProps: AccountProps = {
- accountToken: '1234',
- accountExpiry: new Date('2038-01-01').toISOString(),
- expiryLocale: 'en-US',
- updateAccountExpiry: () => Promise.resolve(),
- onCopyAccountToken: () => {},
- onClose: () => {},
- onLogout: () => {},
- onBuyMore: () => {},
- };
- return {
- ...defaultProps,
- ...mergeProps,
- };
- };
-
- it('should call close callback', (done) => {
- const props = makeProps({
- onClose: () => done(),
- });
- const component = render(props)
- .find(BackBarItem)
- .dive();
- component.simulate('press');
- });
-
- it('should call logout callback', (done) => {
- const props = makeProps({
- onLogout: () => done(),
- });
- const component = getComponent(render(props), 'account__logout');
- component.simulate('press');
- });
-
- it('should call "buy more" callback', (done) => {
- const props = makeProps({
- onBuyMore: () => done(),
- });
- const component = getComponent(render(props), 'account__buymore');
- component.simulate('press');
- });
-
- it('should display "out of time" message when account expired', () => {
- 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);
- });
-
- 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);
- });
-});
-
-function render(props) {
- return shallow(<Account {...props} />);
-}
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
diff --git a/test/components/AccountInput.spec.js b/test/components/AccountInput.spec.js
deleted file mode 100644
index 2f6ead1b45..0000000000
--- a/test/components/AccountInput.spec.js
+++ /dev/null
@@ -1,183 +0,0 @@
-// @flow
-
-import { createKeyEvent } from '../helpers/dom-events';
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import AccountInput from '../../app/components/AccountInput';
-import type { AccountInputProps } from '../../app/components/AccountInput';
-
-describe('components/AccountInput', () => {
- const getInputRef = (component) => {
- const node = getComponent(component, 'AccountInput');
- return node;
- };
-
- const render = (mergeProps: $Shape<AccountInputProps>) => {
- const defaultProps: AccountInputProps = {
- value: '',
- onEnter: null,
- onChange: null,
- };
- const props = Object.assign({}, defaultProps, mergeProps);
- return shallow(<AccountInput {...props} />);
- };
-
- it('should call onEnter', (done) => {
- const component = render({
- onEnter: () => done(),
- });
- keyPress(getInputRef(component), createKeyEvent('Enter'));
- });
-
- it('should call onChange', (done) => {
- const component = render({
- onChange: (val) => {
- expect(val).to.be.equal('1');
- done();
- },
- });
- keyPress(getInputRef(component), createKeyEvent('1'));
- });
-
- it('should format input properly', () => {
- const cases = [
- '1111111111111',
- '1111 1111 1111',
- '1111 1111 111',
- '1111 1111 11',
- '1111 1111 1',
- '1111 1111',
- '1111 111',
- '1111 11',
- '1111 1',
- '1111',
- '111',
- '11',
- '1',
- '',
- ];
-
- for (const value of cases) {
- const component = render({ value });
- expect(getInputRef(component).prop('value')).to.be.equal(value);
- }
- });
-
- it('should remove last character', (done) => {
- const component = render({
- value: '1234',
- onChange: (val) => {
- expect(val).to.be.equal('123');
- done();
- },
- });
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
-
- it('should remove first character', (done) => {
- const component = render({
- value: '1234',
- onChange: (val) => {
- expect(val).to.be.equal('234');
- done();
- },
- });
- component.setState({ selectionRange: [1, 1] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should remove all characters', (done) => {
- const component = render({
- value: '12345678',
- onChange: (val) => {
- expect(val).to.be.empty;
- done();
- },
- });
- component.setState({ selectionRange: [0, 8] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should remove selection', (done) => {
- const component = render({
- value: '1234 5678 9999',
- onChange: (val) => {
- expect(val).to.be.equal('12349999');
- done();
- },
- });
- component.setState({ selectionRange: [4, 8] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
- });
- });
-
- it('should replace selection', (done) => {
- const component = render({
- value: '0000',
- });
-
- component.setState({ selectionRange: [1, 3] }, () => {
- keyPress(getInputRef(component), createKeyEvent('1'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('010');
- expect(component.state().selectionRange).to.deep.equal([2, 2]);
- done();
- });
- });
- });
-
- it('should keep selection in the back', (done) => {
- const component = render({ value: '' });
-
- for (let i = 0; i < 12; i++) {
- keyPress(getInputRef(component), createKeyEvent('1'));
- }
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('111111111111');
- expect(component.state().selectionRange).to.deep.equal([12, 12]);
- done();
- });
- });
-
- it('should advance selection on insertion', (done) => {
- const component = render({
- value: '0000',
- });
- component.setState({ selectionRange: [1, 1] }, () => {
- keyPress(getInputRef(component), createKeyEvent('1'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('01000');
- expect(component.state().selectionRange).to.deep.equal([2, 2]);
- done();
- });
- });
- });
-
- it('should not do anything when nothing to remove', (done) => {
- const component = render({
- value: '0000',
- });
- component.setState({ selectionRange: [0, 0] }, () => {
- keyPress(getInputRef(component), createKeyEvent('Backspace'));
-
- component.setState({}, () => {
- expect(component.state().value).to.be.equal('0000');
- expect(component.state().selectionRange).to.deep.equal([0, 0]);
- done();
- });
- });
- });
-});
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
-
-function keyPress(component, key) {
- component.prop('onKeyPress')(key);
-}
diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js
deleted file mode 100644
index e445b2c788..0000000000
--- a/test/components/Connect.spec.js
+++ /dev/null
@@ -1,138 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-
-import Connect from '../../app/components/Connect';
-
-type ConnectProps = React.ElementProps<typeof Connect>;
-
-describe('components/Connect', () => {
- it('shows unsecured hints when disconnected', () => {
- const component = renderWithProps({
- connection: {
- ...defaultProps.connection,
- status: 'disconnected',
- },
- });
-
- const header = getComponent(component, 'header');
- const securityMessage = getComponent(component, 'networkSecurityMessage');
- const connectButton = getComponent(component, 'secureConnection');
- expect(header.prop('barStyle')).to.equal('error');
- expect(securityMessage.html()).to.contain('UNSECURED');
- expect(connectButton.html()).to.contain('Secure my connection');
- });
-
- it('shows secured hints when connected', () => {
- const component = renderWithProps({
- connection: {
- ...defaultProps.connection,
- status: 'connected',
- },
- });
-
- const header = getComponent(component, 'header');
- const securityMessage = getComponent(component, 'networkSecurityMessage');
- const disconnectButton = getComponent(component, 'disconnect');
- expect(header.prop('barStyle')).to.equal('success');
- expect(securityMessage.html()).to.contain('SECURE ');
- expect(disconnectButton.html()).to.contain('Disconnect');
- });
-
- it('shows the connection location when connecting', () => {
- const component = renderWithProps({
- connection: {
- ...defaultProps.connection,
- status: 'connecting',
- country: 'Norway',
- city: 'Oslo',
- },
- });
- const countryAndCity = getComponent(component, 'location');
- const ipAddr = getComponent(component, 'ipAddress');
-
- expect(countryAndCity.html()).to.contain('Norway');
- expect(countryAndCity.html()).not.to.contain('Oslo');
- expect(ipAddr.length).to.equal(0);
- });
-
- it('shows the connection location when connected', () => {
- const component = renderWithProps({
- connection: {
- ...defaultProps.connection,
- status: 'connected',
- country: 'Norway',
- city: 'Oslo',
- ip: '4.3.2.1',
- },
- });
- const countryAndCity = getComponent(component, 'location');
- const ipAddr = getComponent(component, 'ipAddress');
-
- expect(countryAndCity.html()).to.contain('Norway');
- expect(countryAndCity.html()).to.contain('Oslo');
- expect(ipAddr.html()).to.contain('4.3.2.1');
- });
-
- it('shows the connection location when disconnected', () => {
- const component = renderWithProps({
- connection: {
- ...defaultProps.connection,
- status: 'disconnected',
- country: 'Norway',
- city: 'Oslo',
- ip: '4.3.2.1',
- },
- });
- const countryAndCity = getComponent(component, 'location');
- const ipAddr = getComponent(component, 'ipAddress');
-
- expect(countryAndCity.html()).to.contain('Norway');
- expect(countryAndCity.html()).to.not.contain('Oslo');
- expect(ipAddr.html()).to.contain('4.3.2.1');
- });
-
- it('invokes the onConnect prop', (done) => {
- const component = renderWithProps({
- onConnect: () => done(),
- connection: {
- ...defaultProps.connection,
- status: 'disconnected',
- },
- });
- const connectButton = getComponent(component, 'secureConnection');
-
- connectButton.prop('onPress')();
- });
-});
-
-const defaultProps: ConnectProps = {
- onSettings: () => {},
- onSelectLocation: () => {},
- onConnect: () => {},
- onCopyIP: () => {},
- onDisconnect: () => {},
- onExternalLink: () => {},
- accountExpiry: '',
- selectedRelayName: '',
- connection: {
- status: 'disconnected',
- isOnline: true,
- ip: null,
- latitude: null,
- longitude: null,
- country: null,
- city: null,
- },
- updateAccountExpiry: () => Promise.resolve(),
-};
-
-function renderWithProps(customProps: $Shape<ConnectProps>) {
- const props = { ...defaultProps, ...customProps };
- return shallow(<Connect {...props} />);
-}
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
diff --git a/test/components/Login.spec.js b/test/components/Login.spec.js
deleted file mode 100644
index 2767d37068..0000000000
--- a/test/components/Login.spec.js
+++ /dev/null
@@ -1,82 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import Login from '../../app/components/Login';
-
-describe('components/Login', () => {
- it('does not show the footer when logging in', () => {
- const component = shallow(
- <Login
- {...{
- ...defaultProps,
- loginState: 'logging in',
- }}
- />,
- );
- const visibleFooters = getComponent(component, 'footerVisibility true');
- const invisibleFooters = getComponent(component, 'footerVisibility false');
- expect(visibleFooters.length).to.equal(0);
- expect(invisibleFooters.length).to.equal(1);
- });
-
- it('shows the footer and account input when not logged in', () => {
- const component = shallow(<Login {...defaultProps} />);
- const visibleFooters = getComponent(component, 'footerVisibility true');
- const invisibleFooters = getComponent(component, 'footerVisibility false');
- expect(visibleFooters.length).to.equal(1);
- expect(invisibleFooters.length).to.equal(0);
- expect(getComponent(component, 'AccountInput').length).to.be.above(0);
- });
-
- it('does not show the footer nor account input when logged in', () => {
- const component = shallow(
- <Login
- {...{
- ...defaultProps,
- loginState: 'ok',
- }}
- />,
- );
- const visibleFooters = getComponent(component, 'footerVisibility true');
- const invisibleFooters = getComponent(component, 'footerVisibility false');
- expect(visibleFooters.length).to.equal(0);
- expect(invisibleFooters.length).to.equal(1);
- expect(getComponent(component, 'AccountInput').length).to.equal(0);
- });
-
- it('logs in with the entered account number when clicking the login icon', (done) => {
- const component = shallow(<Login {...defaultProps} />);
- component.setProps({
- accountToken: '1234567890',
- login: (accountToken) => {
- try {
- expect(accountToken).to.equal('1234567890');
- done();
- } catch (e) {
- done(e);
- }
- },
- });
-
- const accountInputButton = getComponent(component, 'account-input-button');
- accountInputButton.simulate('press');
- });
-});
-
-const defaultProps = {
- accountToken: null,
- accountHistory: [],
- loginError: null,
- loginState: 'none',
- openSettings: () => {},
- openExternalLink: (_type) => {},
- login: (_accountToken) => {},
- resetLoginError: () => {},
- updateAccountToken: (_accountToken) => {},
- removeAccountTokenFromHistory: (_accountToken) => Promise.resolve(),
-};
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
diff --git a/test/components/Preferences.spec.js b/test/components/Preferences.spec.js
deleted file mode 100644
index 51be0dc473..0000000000
--- a/test/components/Preferences.spec.js
+++ /dev/null
@@ -1,29 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import Preferences from '../../app/components/Preferences';
-import { BackBarItem } from '../../app/components/NavigationBar';
-
-describe('components/Preferences', () => {
- it('Should call close handler', (done) => {
- const props = makeProps({ onClose: done });
- const component = shallow(<Preferences {...props} />);
- const button = component.find(BackBarItem).dive();
- expect(button).to.have.length(1);
- button.simulate('press');
- });
-});
-
-function makeProps(props) {
- return {
- onClose: () => {},
- setAutoConnect: () => {},
- setAutoStart: (_autoStart) => Promise.resolve(),
- getAutoStart: () => false,
- setAllowLan: () => {},
- allowAutoConnect: false,
- allowLan: false,
- ...props,
- };
-}
diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js
deleted file mode 100644
index 8db9c99602..0000000000
--- a/test/components/SelectLocation.spec.js
+++ /dev/null
@@ -1,113 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import { CloseBarItem } from '../../app/components/NavigationBar';
-import SelectLocation from '../../app/components/SelectLocation';
-
-import type { SettingsReduxState } from '../../app/redux/settings/reducers';
-import type { SelectLocationProps } from '../../app/components/SelectLocation';
-
-describe('components/SelectLocation', () => {
- const state: SettingsReduxState = {
- relaySettings: {
- normal: {
- location: 'any',
- protocol: 'any',
- port: 'any',
- },
- },
- relayLocations: [
- {
- name: 'Sweden',
- code: 'se',
- hasActiveRelays: true,
- cities: [
- {
- name: 'Malmö',
- code: 'mma',
- latitude: 0,
- longitude: 0,
- hasActiveRelays: true,
- },
- {
- name: 'Stockholm',
- code: 'sto',
- latitude: 0,
- longitude: 0,
- hasActiveRelays: true,
- },
- ],
- },
- ],
- autoConnect: false,
- allowLan: false,
- enableIpv6: true,
- };
-
- const makeProps = (
- state: SettingsReduxState,
- mergeProps: $Shape<SelectLocationProps>,
- ): SelectLocationProps => {
- const defaultProps: SelectLocationProps = {
- settings: state,
- onClose: () => {},
- onSelect: (_server) => {},
- };
- return Object.assign({}, defaultProps, mergeProps);
- };
-
- const render = (props: SelectLocationProps) => {
- return shallow(<SelectLocation {...props} />);
- };
-
- it('should call close callback', (done) => {
- const props = makeProps(state, {
- onClose: () => done(),
- });
- const component = render(props)
- .find(CloseBarItem)
- .dive();
- component.simulate('press');
- });
-
- it('should call select callback for country', (done) => {
- const props = makeProps(state, {
- onSelect: (location) => {
- try {
- expect(location).to.deep.equal({
- country: 'se',
- });
- done();
- } catch (e) {
- done(e);
- }
- },
- });
- const elements = getComponent(render(props), 'country');
- expect(elements).to.have.length(1);
- elements.at(0).simulate('press');
- });
-
- it('should call select callback for city', (done) => {
- const props = makeProps(state, {
- onSelect: (location) => {
- try {
- expect(location).to.deep.equal({
- city: ['se', 'mma'],
- });
- done();
- } catch (e) {
- done(e);
- }
- },
- });
- const elements = getComponent(render(props), 'city');
- expect(elements).to.have.length(2);
- elements.at(0).simulate('press');
- });
-});
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js
deleted file mode 100644
index a9302a9ea7..0000000000
--- a/test/components/Settings.spec.js
+++ /dev/null
@@ -1,213 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import { shallow } from 'enzyme';
-import Settings from '../../app/components/Settings';
-import { CloseBarItem } from '../../app/components/NavigationBar';
-
-type SettingsProps = React.ElementProps<typeof Settings>;
-
-describe('components/Settings', () => {
- 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 = {
- ...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 = {
- ...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 = {
- ...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 = {
- ...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 = {
- ...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 = {
- ...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 = {
- ...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 = {
- ...defaultProps,
- loginState: 'ok',
- accountExpiry: new Date('2001-01-01').toISOString(),
- };
- const component = getComponent(
- shallow(<Settings {...props} />),
- 'settings__account_paid_until_subtext',
- );
- expect(component.children().text()).to.equal('OUT OF TIME');
- });
-
- it('should hide out-of-time message for paid account', () => {
- const props = {
- ...defaultProps,
- loginState: 'ok',
- accountExpiry: new Date('2038-01-01').toISOString(),
- };
- const component = getComponent(
- shallow(<Settings {...props} />),
- 'settings__account_paid_until_subtext',
- );
- expect(component.children().text()).not.to.equal('OUT OF TIME');
- });
-
- it('should call close callback', (done) => {
- const props = {
- ...defaultProps,
- loginState: 'none',
- accountExpiry: null,
- onClose: () => done(),
- };
- const component = shallow(<Settings {...props} />)
- .find(CloseBarItem)
- .dive();
- component.simulate('press');
- });
-
- it('should call quit callback', (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 = {
- ...defaultProps,
- loginState: 'ok',
- accountExpiry: new Date('2038-01-01').toISOString(),
- onViewAccount: () => done(),
- };
- const component = getComponent(
- shallow(<Settings {...props} />),
- 'settings__account_paid_until_button',
- );
- component.simulate('press');
- });
-
- it('should call advanced settings callback', (done) => {
- 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 = {
- ...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 = {
- ...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 = {
- ...defaultProps,
- loginState: 'none',
- accountExpiry: null,
- onExternalLink: (type) => {
- collectedExternalLinkTypes.push(type);
- },
- };
- const container = getComponent(shallow(<Settings {...props} />), 'settings__external_link');
- container
- .find({ testName: 'settings__external_link' })
- .forEach((element) => element.simulate('press'));
-
- expect(collectedExternalLinkTypes).to.include.ordered.members(['faq', 'guides']);
- });
-});
-
-function getComponent(container, testName) {
- return container.findWhere((n) => n.prop('testName') === testName);
-}
diff --git a/test/components/Support.spec.js b/test/components/Support.spec.js
deleted file mode 100644
index 23172d3403..0000000000
--- a/test/components/Support.spec.js
+++ /dev/null
@@ -1,122 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import Support from '../../app/components/Support';
-import { shallow } from 'enzyme';
-import type { SupportProps } from '../../app/components/Support';
-import { BackBarItem } from '../../app/components/NavigationBar';
-
-describe('components/Support', () => {
- it('should call close callback', () => {
- const props = makeProps({ onClose: spy() });
- const component = shallow(<Support {...props} />);
-
- const closeButton = component.find(BackBarItem).dive();
- closeButton.simulate('press');
-
- expect(props.onClose).to.have.been.called.once;
- });
-
- it('should call view logs callback', async () => {
- const props = makeProps({ viewLog: spy() });
- const component = shallow(<Support {...props} />);
- const viewButton = component.find({ testName: 'support__view_logs' });
-
- await click(viewButton);
- expect(props.viewLog).to.have.been.called.once;
- });
-
- it('should call send callback when description filled in', async () => {
- const props = makeProps({
- defaultEmail: 'foo',
- defaultMessage: 'abc',
- sendProblemReport: spy((_report) => Promise.resolve()),
- });
- const component = shallow(<Support {...props} />);
- const sendButton = component.find({ testName: 'support__send_logs' });
-
- expect(sendButton.prop('disabled')).to.be.false;
- await click(sendButton);
- expect(props.sendProblemReport).to.have.been.called.once;
- });
-
- it('should not call send callback when description is empty', () => {
- const props = makeProps({ defaultMessage: '' });
- const component = shallow(<Support {...props} />);
- const sendButton = component.find({ testName: 'support__send_logs' });
-
- expect(sendButton.prop('disabled')).to.be.true;
- });
-
- it('should not collect report twice', async () => {
- const props = makeProps({
- collectProblemReport: spy(() => Promise.resolve('/path/to/problem/report')),
- });
- const component = shallow(<Support {...props} />);
- const viewButton = component.find({ testName: 'support__view_logs' });
-
- await Promise.all([click(viewButton), click(viewButton)]);
- expect(props.collectProblemReport).to.have.been.called.once;
- });
-
- it('should collect report on submission', async () => {
- const props = makeProps({
- defaultMessage: '',
- defaultEmail: 'foo',
- collectProblemReport: spy(() => Promise.resolve('/path/to/problem/report')),
- sendProblemReport: spy(() => Promise.resolve()),
- });
- const component = shallow(<Support {...props} />);
- const sendButton = component.find({ testName: 'support__send_logs' });
-
- await click(sendButton);
- expect(props.collectProblemReport).to.have.been.called.once;
- expect(props.sendProblemReport).to.have.been.called.once;
- });
-
- it('should save the report form on change', () => {
- const props = makeProps({
- defaultEmail: 'email@domain',
- defaultMessage: 'test message',
- sendProblemReport: () => Promise.reject(new Error('Simulation')),
- saveReportForm: spy(),
- });
- const component = shallow(<Support {...props} />);
- const input = component.find({ testName: 'support__form_message' });
- input.simulate('changeText', 'new message');
- expect(props.saveReportForm).to.have.been.called.once;
- });
-
- it('should clear the report form upon successful submission', async () => {
- const props = makeProps({
- defaultEmail: 'email@domain',
- defaultMessage: 'test message',
- sendProblemReport: () => Promise.resolve(),
- clearReportForm: spy(),
- });
- const component = shallow(<Support {...props} />);
- const sendButton = component.find({ testName: 'support__send_logs' });
-
- await click(sendButton);
- expect(props.clearReportForm).to.have.been.called.once;
- });
-});
-
-function makeProps(mergeProps: $Shape<SupportProps> = {}): SupportProps {
- const defaultProps: SupportProps = {
- defaultEmail: '',
- defaultMessage: '',
- accountHistory: [],
- onClose: () => {},
- viewLog: (_path) => {},
- collectProblemReport: () => Promise.resolve('/path/to/problem/report'),
- sendProblemReport: (_report) => Promise.resolve(),
- saveReportForm: (_form) => {},
- clearReportForm: () => {},
- };
- return { ...defaultProps, ...mergeProps };
-}
-
-function click(component) {
- return component.prop('onPress')();
-}
diff --git a/test/components/Switch.spec.js b/test/components/Switch.spec.js
deleted file mode 100644
index 44794d9bba..0000000000
--- a/test/components/Switch.spec.js
+++ /dev/null
@@ -1,128 +0,0 @@
-// @flow
-
-import * as React from 'react';
-import ReactDOM from 'react-dom';
-import ReactTestUtils, { Simulate } from 'react-dom/test-utils';
-import Switch from '../../app/components/Switch';
-
-describe('components/Switch', () => {
- let container: ?HTMLElement;
-
- function renderIntoDocument(instance: React.Element<*>): React.Component<*, *> {
- if (container) {
- throw new Error('Unmount previously rendered component first.');
- }
-
- container = document.createElement('div');
- if (!document.documentElement) {
- throw new Error('document.documentElement cannot be null.');
- }
-
- document.documentElement.appendChild(container);
-
- return ReactDOM.render(instance, container);
- }
-
- // unmount container and clean up DOM
- afterEach(() => {
- if (container) {
- ReactDOM.unmountComponentAtNode(container);
- container = null;
- }
- });
-
- it('should switch on', (done) => {
- const onChange = (isOn) => {
- expect(isOn).to.be.true;
- done();
- };
- const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- // 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) => {
- const onChange = (isOn) => {
- expect(isOn).to.be.false;
- done();
- };
- const component = renderIntoDocument(<Switch isOn={true} onChange={onChange} />);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- // 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) => {
- const onChange = (isOn) => {
- expect(isOn).to.be.true;
- done();
- };
- const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
- // 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 }));
- document.dispatchEvent(new MouseEvent('mouseup', { clientX: 150, clientY: 0 }));
- });
-
- it('should handle right to left swipe', (done) => {
- const onChange = (isOn) => {
- expect(isOn).to.be.false;
- done();
- };
- const component = renderIntoDocument(<Switch isOn={true} onChange={onChange} />);
- const domNode = ReactTestUtils.findRenderedDOMComponentWithTag(component, 'input');
-
- // 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 }));
- document.dispatchEvent(new MouseEvent('mouseup', { clientX: 100, clientY: 0 }));
- });
-
- it('should timeout when user holds knob for too long without moving', (done) => {
- const onChange = () => {
- throw new Error('onChange should not be called on timeout.');
- };
-
- const component = renderIntoDocument(<Switch isOn={false} onChange={onChange} />);
-
- 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 {
- // See: https://github.com/facebook/flow/pull/5841
- if (domNode) {
- // should not trigger onChange()
- Simulate.change(domNode);
- }
- done();
- } catch (e) {
- done(e);
- }
- }, 1000);
- });
-});