diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 15:07:37 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-08-15 17:39:38 +0200 |
| commit | 71592249b2dd669b6f24f37bfb7b0f4e43b74998 (patch) | |
| tree | a6097dc7e5d94d06e99c65fdfe160e824395f50c /test | |
| parent | e84e87f4ce5a8c242f756566cdc6fb59a45f7bea (diff) | |
| download | mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.tar.xz mullvadvpn-71592249b2dd669b6f24f37bfb7b0f4e43b74998.zip | |
Add workspaces
Diffstat (limited to 'test')
| -rw-r--r-- | test/.eslintrc | 13 | ||||
| -rw-r--r-- | test/components/Account.spec.js | 75 | ||||
| -rw-r--r-- | test/components/AccountInput.spec.js | 183 | ||||
| -rw-r--r-- | test/components/Connect.spec.js | 138 | ||||
| -rw-r--r-- | test/components/Login.spec.js | 82 | ||||
| -rw-r--r-- | test/components/Preferences.spec.js | 29 | ||||
| -rw-r--r-- | test/components/SelectLocation.spec.js | 113 | ||||
| -rw-r--r-- | test/components/Settings.spec.js | 213 | ||||
| -rw-r--r-- | test/components/Support.spec.js | 122 | ||||
| -rw-r--r-- | test/components/Switch.spec.js | 128 | ||||
| -rw-r--r-- | test/helpers/dom-events.js | 22 | ||||
| -rw-r--r-- | test/jsonrpc-transport.spec.js | 103 | ||||
| -rw-r--r-- | test/keyframe-animation.spec.js | 268 | ||||
| -rw-r--r-- | test/relay-settings-builder.spec.js | 146 | ||||
| -rw-r--r-- | test/setup/main.js | 4 | ||||
| -rw-r--r-- | test/setup/renderer.js | 15 | ||||
| -rw-r--r-- | test/transition-rule.spec.js | 57 |
17 files changed, 0 insertions, 1711 deletions
diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 00c8d44bb9..0000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rules": { - "no-unused-expressions" : "off", - "react/no-render-return-value": "off" - }, - "env": { - "mocha": true - }, - "globals": { - "expect": true, - "spy": true - } -}
\ No newline at end of file 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); - }); -}); diff --git a/test/helpers/dom-events.js b/test/helpers/dom-events.js deleted file mode 100644 index 2d8b4be3cf..0000000000 --- a/test/helpers/dom-events.js +++ /dev/null @@ -1,22 +0,0 @@ -// @flow -const keycodes = { - '1': { which: 49, keyCode: 49 }, - '2': { which: 50, keyCode: 50 }, - '3': { which: 51, keyCode: 51 }, - '4': { which: 52, keyCode: 52 }, - '5': { which: 53, keyCode: 53 }, - '6': { which: 54, keyCode: 54 }, - '7': { which: 55, keyCode: 55 }, - '8': { which: 56, keyCode: 56 }, - '9': { which: 57, keyCode: 57 }, - '0': { which: 48, keyCode: 48 }, - Tab: { which: 9, keyCode: 9 }, - Enter: { which: 13, keyCode: 13 }, - Backspace: { which: 8, keyCode: 8 }, -}; - -export type Keycode = $Keys<typeof keycodes>; - -export function createKeyEvent(key: Keycode): Object { - return Object.assign({}, { key }, keycodes[key], { preventDefault: () => {} }); //preventDefault is needed to mock key events for onKeyPress in AccountInput -} diff --git a/test/jsonrpc-transport.spec.js b/test/jsonrpc-transport.spec.js deleted file mode 100644 index ca66514192..0000000000 --- a/test/jsonrpc-transport.spec.js +++ /dev/null @@ -1,103 +0,0 @@ -// @flow - -import jsonrpc from 'jsonrpc-lite'; -import { Server, WebSocket as MockWebSocket } from 'mock-socket'; -import JsonRpcTransport, { TimeOutError } from '../app/lib/jsonrpc-transport'; - -describe('JSON RPC transport', () => { - const WEBSOCKET_URL = 'ws://localhost:8080'; - let server: Server, transport: JsonRpcTransport; - - beforeEach(() => { - server = new Server(WEBSOCKET_URL); - transport = new JsonRpcTransport((url) => new MockWebSocket(url)); - }); - - afterEach(() => { - server.close(); - }); - - it('should reject failed jsonrpc requests', async () => { - server.on('connection', (socket) => { - socket.on('message', (msg) => { - const { payload } = jsonrpc.parse(msg); - if (payload.method === 'invalid-method') { - socket.send( - JSON.stringify( - jsonrpc.error(payload.id, new jsonrpc.JsonRpcError('Method not found', -32601)), - ), - ); - } - }); - }); - - await transport.connect(WEBSOCKET_URL); - const sendPromise = transport.send('invalid-method'); - - return expect(sendPromise).to.eventually.be.rejectedWith('Method not found'); - }); - - it('should route reply to correct promise', async () => { - server.on('connection', (socket) => { - socket.on('message', (msg) => { - const { payload } = jsonrpc.parse(msg); - if (payload.method === 'a message') { - socket.send(JSON.stringify(jsonrpc.success(payload.id, 'a reply'))); - } - }); - }); - - await transport.connect(WEBSOCKET_URL); - - const decoyPromise = transport.send('a decoy', [], 100); - const messagePromise = transport.send('a message', [], 100); - - return Promise.all([ - expect(messagePromise).to.eventually.be.equal('a reply'), - expect(decoyPromise).to.eventually.be.rejectedWith(TimeOutError), - ]); - }); - - it('should timeout if no response is returned', async () => { - await transport.connect(WEBSOCKET_URL); - const sendPromise = transport.send('timeout-message', {}, 1); - - return expect(sendPromise).to.eventually.be.rejectedWith(TimeOutError, 'Request timed out'); - }); - - it('should route notifications', async () => { - server.on('connection', (socket) => { - socket.on('message', (msg) => { - const { payload } = jsonrpc.parse(msg); - if (payload.method === 'event_subscribe') { - socket.send(JSON.stringify(jsonrpc.success(payload.id, 1))); - } - }); - }); - - await transport.connect(WEBSOCKET_URL); - - const eventPromiseHelper = (() => { - let borrowedResolve: ?(mixed) => void; - const promise = new Promise((resolve) => (borrowedResolve = resolve)); - /* Flow does not understand that the body of Promise runs immediately. - see https://github.com/facebook/flow/issues/6711 */ - if (!borrowedResolve) { - throw new Error(); - } - return { - resolve: borrowedResolve, - promise, - }; - })(); - - await transport.subscribe('event', eventPromiseHelper.resolve); - - server.emit( - 'message', - JSON.stringify(jsonrpc.notification('event', { subscription: 1, result: 'beacon' })), - ); - - return expect(eventPromiseHelper.promise).to.eventually.be.equal('beacon'); - }); -}); diff --git a/test/keyframe-animation.spec.js b/test/keyframe-animation.spec.js deleted file mode 100644 index 08a177ea79..0000000000 --- a/test/keyframe-animation.spec.js +++ /dev/null @@ -1,268 +0,0 @@ -// @flow - -import KeyframeAnimation from '../app/lib/keyframe-animation'; -import { nativeImage } from 'electron'; - -describe('lib/keyframe-animation', function() { - this.timeout(1000); - - const newAnimation = () => { - const images = [1, 2, 3, 4, 5].map(() => nativeImage.createEmpty()); - const animation = new KeyframeAnimation(images); - animation.speed = 1; - return animation; - }; - - it('should play sequence', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]); - expect(animation._currentFrame).to.be.equal(4); - done(); - }; - - animation.play(); - }); - - it('should play one frame', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([3]); - expect(animation._currentFrame).to.be.equal(3); - done(); - }; - - animation.play({ startFrame: 3, endFrame: 3 }); - }); - - it('should play sequence with custom frames', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([2, 3, 4]); - expect(animation._currentFrame).to.be.equal(4); - done(); - }; - - animation.play({ - startFrame: 2, - endFrame: 4, - }); - }); - - it('should play sequence with custom frames in reverse', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([4, 3, 2]); - expect(animation._currentFrame).to.be.equal(2); - done(); - }; - - animation.reverse = true; - animation.play({ - startFrame: 4, - endFrame: 2, - }); - }); - - it('should begin from current state starting below range', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([0, 1, 2, 3, 4]); - expect(animation._currentFrame).to.be.equal(4); - done(); - }; - - animation._currentFrame = 0; - animation._isFirstRun = false; - - animation.play({ - beginFromCurrentState: true, - startFrame: 3, - endFrame: 4, - }); - }); - - it('should begin from current state starting below range reverse', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([0, 1, 2, 3]); - expect(animation._currentFrame).to.be.equal(3); - done(); - }; - - animation._currentFrame = 0; - animation._isFirstRun = false; - animation.reverse = true; - - animation.play({ - beginFromCurrentState: true, - startFrame: 3, - endFrame: 4, - }); - }); - - it('should begin from current state starting above range', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([4, 3, 2]); - expect(animation._currentFrame).to.be.equal(2); - done(); - }; - - animation._currentFrame = 4; - animation._isFirstRun = false; - - animation.play({ - beginFromCurrentState: true, - startFrame: 1, - endFrame: 2, - }); - }); - - it('should begin from current state starting above range reverse', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([4, 3, 2, 1]); - expect(animation._currentFrame).to.be.equal(1); - done(); - }; - - animation._currentFrame = 4; - animation._isFirstRun = false; - animation.reverse = true; - - animation.play({ - beginFromCurrentState: true, - startFrame: 1, - endFrame: 3, - }); - }); - - it('should play sequence in reverse', (done) => { - const seq = []; - const animation = newAnimation(); - animation.onFrame = () => { - seq.push(animation._currentFrame); - }; - animation.onFinish = () => { - expect(seq).to.be.deep.equal([4, 3, 2, 1, 0]); - expect(animation._currentFrame).to.be.equal(0); - done(); - }; - - animation.reverse = true; - animation.play(); - }); - - it('should play sequence on repeat', (done) => { - const seq = []; - const animation = newAnimation(); - const expectedFrames = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]; - - animation.onFrame = () => { - if (seq.length === expectedFrames.length) { - animation.stop(); - expect(seq).to.be.deep.equal(expectedFrames); - done(); - } else { - seq.push(animation._currentFrame); - } - }; - - animation.repeat = true; - animation.play(); - }); - - it('should play sequence on repeat in reverse', (done) => { - const seq = []; - const animation = newAnimation(); - const expectedFrames = [4, 3, 2, 1, 0, 4, 3, 2, 1, 0]; - - animation.onFrame = () => { - if (seq.length === expectedFrames.length) { - animation.stop(); - expect(seq).to.be.deep.equal(expectedFrames); - done(); - } else { - seq.push(animation._currentFrame); - } - }; - - animation.repeat = true; - animation.reverse = true; - animation.play(); - }); - - it('should alternate sequence', (done) => { - const seq = []; - const animation = newAnimation(); - const expectedFrames = [0, 1, 2, 3, 4, 3, 2, 1, 0]; - - animation.onFrame = () => { - if (seq.length === expectedFrames.length) { - animation.stop(); - expect(seq).to.be.deep.equal(expectedFrames); - done(); - } else { - seq.push(animation._currentFrame); - } - }; - - animation.repeat = true; - animation.alternate = true; - animation.play(); - }); - - it('should alternate reverse sequence', (done) => { - const seq = []; - const animation = newAnimation(); - const expectedFrames = [4, 3, 2, 1, 0, 1, 2, 3, 4]; - - animation.onFrame = () => { - if (seq.length === expectedFrames.length) { - animation.stop(); - expect(seq).to.be.deep.equal(expectedFrames); - done(); - } else { - seq.push(animation._currentFrame); - } - }; - - animation.repeat = true; - animation.reverse = true; - animation.alternate = true; - animation.play(); - }); -}); diff --git a/test/relay-settings-builder.spec.js b/test/relay-settings-builder.spec.js deleted file mode 100644 index ace01a978c..0000000000 --- a/test/relay-settings-builder.spec.js +++ /dev/null @@ -1,146 +0,0 @@ -// @flow - -import RelaySettingsBuilder from '../app/lib/relay-settings-builder'; - -describe('Relay settings builder', () => { - it('should set location to any', () => { - expect( - RelaySettingsBuilder.normal() - .location.any() - .build(), - ).to.deep.equal({ - normal: { - location: 'any', - }, - }); - }); - - it('should bound location to city', () => { - expect( - RelaySettingsBuilder.normal() - .location.city('se', 'mma') - .build(), - ).to.deep.equal({ - normal: { - location: { - only: { - city: ['se', 'mma'], - }, - }, - }, - }); - }); - - it('should bound location to country', () => { - expect( - RelaySettingsBuilder.normal() - .location.country('se') - .build(), - ).to.deep.equal({ - normal: { - location: { - only: { country: 'se' }, - }, - }, - }); - }); - - it('should set openvpn settings to any', () => { - expect( - RelaySettingsBuilder.normal() - .tunnel.openvpn((openvpn) => { - openvpn.port.any().protocol.any(); - }) - .build(), - ).to.deep.equal({ - normal: { - tunnel: { - only: { - openvpn: { - port: 'any', - protocol: 'any', - }, - }, - }, - }, - }); - }); - - it('should set openvpn settings to exact values', () => { - expect( - RelaySettingsBuilder.normal() - .tunnel.openvpn((openvpn) => { - openvpn.port.exact(80).protocol.exact('tcp'); - }) - .build(), - ).to.deep.equal({ - normal: { - tunnel: { - only: { - openvpn: { - port: { only: 80 }, - protocol: { only: 'tcp' }, - }, - }, - }, - }, - }); - }); - - it('should set location from raw RelayLocation', () => { - expect( - RelaySettingsBuilder.normal() - .location.fromRaw('any') - .build(), - ).to.deep.equal({ - normal: { - location: 'any', - }, - }); - - expect( - RelaySettingsBuilder.normal() - .location.fromRaw({ country: 'se' }) - .build(), - ).to.deep.equal({ - normal: { - location: { - only: { country: 'se' }, - }, - }, - }); - - expect( - RelaySettingsBuilder.normal() - .location.fromRaw({ city: ['se', 'mma'] }) - .build(), - ).to.deep.equal({ - normal: { - location: { - only: { city: ['se', 'mma'] }, - }, - }, - }); - }); - - it('should set custom endpoint settings', () => { - expect( - RelaySettingsBuilder.custom() - .host('se2.mullvad.net') - .tunnel.openvpn((openvpn) => { - openvpn.port(80).protocol('tcp'); - }) - .build(), - ).to.deep.equal({ - custom_tunnel_endpoint: { - host: 'se2.mullvad.net', - tunnel: { - openvpn: { - port: 80, - protocol: 'tcp', - }, - }, - }, - }); - }); -}); diff --git a/test/setup/main.js b/test/setup/main.js deleted file mode 100644 index dd458a30b6..0000000000 --- a/test/setup/main.js +++ /dev/null @@ -1,4 +0,0 @@ -const log = require('electron-log'); - -log.transports.console.level = false; -log.transports.file.level = false; diff --git a/test/setup/renderer.js b/test/setup/renderer.js deleted file mode 100644 index a1bd11a4d8..0000000000 --- a/test/setup/renderer.js +++ /dev/null @@ -1,15 +0,0 @@ -const Enzyme = require('enzyme'); -const Adapter = require('enzyme-adapter-react-16'); -const chai = require('chai'); -const spies = require('chai-spies'); -const chaiAsPromised = require('chai-as-promised'); - -chai.use(spies); -chai.use(chaiAsPromised); - -Enzyme.configure({ - adapter: new Adapter(), -}); - -global.expect = chai.expect; -global.spy = chai.spy; diff --git a/test/transition-rule.spec.js b/test/transition-rule.spec.js deleted file mode 100644 index f36c44182e..0000000000 --- a/test/transition-rule.spec.js +++ /dev/null @@ -1,57 +0,0 @@ -// @flow - -import TransitionRule from '../app/lib/transition-rule'; - -describe('TransitionRule', () => { - const testTransition = { - forward: { name: 'forward', duration: 0.25 }, - backward: { name: 'backward', duration: 0.25 }, - }; - - it('should match wildcard rule', () => { - const rule = new TransitionRule(null, '/route', testTransition); - - expect(rule.match(null, '/route')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - - expect(rule.match('/somewhere', '/route')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - }); - - it('should match wildcard rule reversion', () => { - const rule = new TransitionRule(null, '/route', testTransition); - - expect(rule.match('/route', '/other')).to.deep.equal({ - direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 }, - }); - }); - - it('should match exact rule', () => { - const rule = new TransitionRule('/route1', '/route2', testTransition); - - expect(rule.match('/other', '/route1')).to.be.null; - expect(rule.match('/other', '/route2')).to.be.null; - - expect(rule.match('/route1', '/route2')).to.deep.equal({ - direction: 'forward', - descriptor: { name: 'forward', duration: 0.25 }, - }); - }); - - it('should match exact rule reversion', () => { - const rule = new TransitionRule('/route1', '/route2', testTransition); - - expect(rule.match('/route1', '/other')).to.be.null; - expect(rule.match('/route2', '/other')).to.be.null; - - expect(rule.match('/route2', '/route1')).to.deep.equal({ - direction: 'backward', - descriptor: { name: 'backward', duration: 0.25 }, - }); - }); -}); |
