diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-19 16:51:33 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-19 16:51:33 +0100 |
| commit | 8b146934260739ae609791a1fb676d48ceb954c0 (patch) | |
| tree | f81f73db8cf38f95c534f48a75db48856c4a4c67 /test/components | |
| parent | 383a48638198accef99e987cd3297283ed25398b (diff) | |
| parent | ef955341235725d355416815c93df18423d433d5 (diff) | |
| download | mullvadvpn-8b146934260739ae609791a1fb676d48ceb954c0.tar.xz mullvadvpn-8b146934260739ae609791a1fb676d48ceb954c0.zip | |
Merge branch 'dynamic-relay-list'
Diffstat (limited to 'test/components')
| -rw-r--r-- | test/components/Connect.spec.js | 68 | ||||
| -rw-r--r-- | test/components/SelectLocation.spec.js | 46 | ||||
| -rw-r--r-- | test/components/Settings.spec.js | 1 |
3 files changed, 71 insertions, 44 deletions
diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js index 748dd25761..4fcc3c6f60 100644 --- a/test/components/Connect.spec.js +++ b/test/components/Connect.spec.js @@ -14,7 +14,7 @@ describe('components/Connect', () => { it('shows unsecured hints when disconnected', () => { const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'disconnected', } }); @@ -31,7 +31,7 @@ describe('components/Connect', () => { it('shows secured hints when connected', () => { const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'connected', } }); @@ -48,7 +48,7 @@ describe('components/Connect', () => { it('shows the connection location when connecting', () => { const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'connecting', country: 'Norway', city: 'Oslo', @@ -65,7 +65,7 @@ describe('components/Connect', () => { it('shows the connection location when connected', () => { const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'connected', country: 'Norway', city: 'Oslo', @@ -83,7 +83,7 @@ describe('components/Connect', () => { it('shows the connection location when disconnected', () => { const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'disconnected', country: 'Norway', city: 'Oslo', @@ -99,22 +99,13 @@ describe('components/Connect', () => { }); it('shows the country name in the location switcher', () => { - const servers = [{ - address: '1.2.3.4', - name: 'Sweden - Malmö', - city: 'Malmö', - country: 'Sweden', - country_code: 'se', - city_code: 'mma', - location: [0, 0] - }]; - const component = renderWithProps({ connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'disconnected', }, settings: { + ...defaultProps.settings, relaySettings: { normal: { location: { city: ['se', 'mma'] }, @@ -123,27 +114,17 @@ describe('components/Connect', () => { } }, }, - getServerInfo: (location) => { - return servers.find((server) => { - if(location.city) { - const [country_code, city_code] = location.city; - return (server.city_code === city_code && - server.country_code === country_code); - } - return false; - }); - }, }); const locationSwitcher = component.find('.connect__server'); - expect(locationSwitcher.text()).to.contain(servers[0].name); + expect(locationSwitcher.text()).to.contain('Malmö'); }); it('invokes the onConnect prop', (done) => { const component = renderWithProps({ onConnect: () => done(), connection: { - ...defaultConnection, + ...defaultProps.connection, status: 'disconnected', } }); @@ -153,16 +134,6 @@ describe('components/Connect', () => { }); }); - -const defaultConnection = { - status: 'disconnected', - isOnline: true, - clientIp: null, - location: null, - country: null, - city: null, -}; - const defaultProps: ConnectProps = { onSettings: () => {}, onSelectLocation: () => {}, @@ -170,7 +141,6 @@ const defaultProps: ConnectProps = { onCopyIP: () => {}, onDisconnect: () => {}, onExternalLink: () => {}, - getServerInfo: _ => null, accountExpiry: '', settings: { relaySettings: { @@ -180,8 +150,26 @@ const defaultProps: ConnectProps = { port: 'any', } }, + relayLocations: [{ + name: 'Sweden', + code: 'se', + hasActiveRelays: true, + cities: [{ + name: 'Malmö', + code: 'mma', + hasActiveRelays: true, + position: [0, 0], + }] + }], + }, + connection: { + status: 'disconnected', + isOnline: true, + clientIp: null, + location: null, + country: null, + city: null, }, - connection: defaultConnection, }; function renderWithProps(customProps: $Shape<ConnectProps>) { diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js index 439edc1865..1abdf515d9 100644 --- a/test/components/SelectLocation.spec.js +++ b/test/components/SelectLocation.spec.js @@ -17,6 +17,17 @@ describe('components/SelectLocation', () => { port: 'any', } }, + relayLocations: [{ + name: 'Sweden', + code: 'se', + hasActiveRelays: true, + cities: [{ + name: 'Malmö', + code: 'mma', + position: [0, 0], + hasActiveRelays: true, + }], + }], }; const makeProps = (state: SettingsReduxState, mergeProps: $Shape<SelectLocationProps>): SelectLocationProps => { @@ -42,13 +53,40 @@ describe('components/SelectLocation', () => { Simulate.click(domNode); }); - it('should call select callback', (done) => { + it('should call select callback for country', (done) => { const props = makeProps(state, { - onSelect: (_server) => done() + onSelect: (location) => { + try { + expect(location).to.deep.equal({ + country: 'se' + }); + done(); + } catch(e) { + done(e); + } + } }); const elements = ReactTestUtils.scryRenderedDOMComponentsWithClass(render(props), 'select-location__cell'); - expect(elements).to.have.length.greaterThan(1); - Simulate.click(elements[1]); + expect(elements).to.have.length(1); + Simulate.click(elements[0]); + }); + + 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 = ReactTestUtils.scryRenderedDOMComponentsWithClass(render(props), 'select-location__sub-cell'); + expect(elements).to.have.length(1); + Simulate.click(elements[0]); }); }); diff --git a/test/components/Settings.spec.js b/test/components/Settings.spec.js index 31a5fa09a9..cc38c54616 100644 --- a/test/components/Settings.spec.js +++ b/test/components/Settings.spec.js @@ -42,6 +42,7 @@ describe('components/Settings', () => { port: 1301, }, }, + relayLocations: [], }; const makeProps = (anAccountState: AccountReduxState, aSettingsState: SettingsReduxState, mergeProps: $Shape<SettingsProps> = {}): SettingsProps => { |
