Repository: kiwicom/mobile
Pull request #974 (2018-08-09 13:53:52)

Explore airports and destinations - tests


Patch:
diff --git a/.jest.json b/.jest.json
index fa39ec80..116b0d08 100644
--- a/.jest.json
+++ b/.jest.json
@@ -1,7 +1,5 @@
 {
-  "collectCoverage": false,
   "preset": "react-native",
-  "verbose": false,
   "globals": {
     "__DEV__": false
   },
diff --git a/app/MMB/src/scenes/explore/ExploreAirportGroup.js b/app/MMB/src/scenes/explore/ExploreAirportGroup.js
index 382d651a..f8b3f520 100644
--- a/app/MMB/src/scenes/explore/ExploreAirportGroup.js
+++ b/app/MMB/src/scenes/explore/ExploreAirportGroup.js
@@ -17,7 +17,7 @@ const todo = () => {
   console.warn('TODO');
 };
 
-const ExploreAirportGroup = (props: Props) => {
+export const ExploreAirportGroup = (props: Props) => {
   const legs = props.data || [];
   const locations = legs
     .reduce((acc, curr) => {
@@ -26,7 +26,6 @@ const ExploreAirportGroup = (props: Props) => {
       return [...acc, departure, arrival];
     }, [])
     .filter(i => idx(i, _ => _.type) === 'airport');
-
   if (locations.length === 0) {
     return null;
   }
diff --git a/app/MMB/src/scenes/explore/ExploreDestinationsGroup.js b/app/MMB/src/scenes/explore/ExploreDestinationsGroup.js
index e1449363..91b57fe9 100644
--- a/app/MMB/src/scenes/explore/ExploreDestinationsGroup.js
+++ b/app/MMB/src/scenes/explore/ExploreDestinationsGroup.js
@@ -8,7 +8,7 @@ import idx from 'idx';
 import { TextIcon } from '@kiwicom/mobile-shared';
 import uniqBy from 'lodash/uniqBy';
 
-import type { ExploreAirportGroup as TripType } from './__generated__/ExploreAirportGroup.graphql';
+import type { ExportDestinationsGroup as TripType } from './__generated__/ExploreDestinationsGroup.graphql';
 
 type Props = {|
   +data: TripType,
@@ -18,7 +18,7 @@ const todo = () => {
   console.warn('TODO');
 };
 
-const ExploreDestinationsGroup = (props: Props) => {
+export const ExploreDestinationsGroup = (props: Props) => {
   const trips = props.data || [];
 
   const destinations = [


Test patch:
diff --git a/app/MMB/src/scenes/explore/__tests__/ExploreAirportGroup.test.js b/app/MMB/src/scenes/explore/__tests__/ExploreAirportGroup.test.js
new file mode 100644
index 00000000..1dbe2685
--- /dev/null
+++ b/app/MMB/src/scenes/explore/__tests__/ExploreAirportGroup.test.js
@@ -0,0 +1,120 @@
+// @flow
+
+import * as React from 'react';
+import renderer from 'react-test-renderer';
+import { MenuItem } from '@kiwicom/mobile-navigation';
+
+import { ExploreAirportGroup } from '../ExploreAirportGroup';
+
+const ref: any = null;
+const data = [
+  {
+    departure: {
+      airport: {
+        id: '1',
+        type: 'airport',
+        city: { name: 'Las Palmas', code: 'LPA' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '2',
+        type: 'airport',
+        city: { name: 'Dublin', code: 'DUB' },
+      },
+    },
+    id: 'leg_1',
+    $refType: ref,
+  },
+  {
+    departure: {
+      airport: {
+        id: '3',
+        type: 'airport',
+        city: { name: 'Dublin', code: 'DUB' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '4',
+        type: 'airport',
+        city: { name: 'Prague', code: 'PRG' },
+      },
+    },
+    id: 'leg_2',
+    $refType: ref,
+  },
+  {
+    departure: {
+      airport: {
+        id: '5',
+        type: 'airport',
+        city: { name: 'Prague', code: 'DUB' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '6',
+        type: 'station',
+        city: { name: 'Wroclaw', code: '' },
+      },
+    },
+    id: 'leg_3',
+    $refType: ref,
+  },
+];
+
+const dataWithoutAirports = [
+  {
+    departure: {
+      airport: {
+        id: '1',
+        type: 'station',
+        city: { name: 'Prague', code: 'DUB' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '2',
+        type: 'station',
+        city: { name: 'Wroclaw', code: 'WRO' },
+      },
+    },
+    id: 'leg_1',
+    $refType: ref,
+  },
+];
+
+describe('Collect all airports', () => {
+  it('should render 3 airports', () => {
+    const wrapper = renderer.create(<ExploreAirportGroup data={data} />);
+
+    const airports = wrapper.root.findAllByType(MenuItem);
+
+    expect(airports).toHaveLength(3);
+  });
+
+  it('should render 3 airports in order: LPA, DUB, PRG', () => {
+    const wrapper = renderer.create(<ExploreAirportGroup data={data} />);
+
+    const airports = wrapper.root
+      .findAllByType(MenuItem)
+      .map(i => i.props.description)
+      .map(x => x.props.passThrough);
+
+    expect(airports).toEqual(['LPA', 'DUB', 'PRG']);
+  });
+
+  it('should render empty array when airports have type station', () => {
+    const wrapper = renderer.create(
+      <ExploreAirportGroup data={dataWithoutAirports} />,
+    );
+
+    const airports = wrapper.root
+      .findAllByType(MenuItem)
+      .map(i => i.props.description)
+      .map(x => x.props.passThrough);
+
+    expect(airports).toEqual([]);
+  });
+});
diff --git a/app/MMB/src/scenes/explore/__tests__/ExploreDestinationsGroup.test.js b/app/MMB/src/scenes/explore/__tests__/ExploreDestinationsGroup.test.js
new file mode 100644
index 00000000..b9c6efa4
--- /dev/null
+++ b/app/MMB/src/scenes/explore/__tests__/ExploreDestinationsGroup.test.js
@@ -0,0 +1,136 @@
+// @flow
+
+import * as React from 'react';
+import renderer from 'react-test-renderer';
+import { MenuItem } from '@kiwicom/mobile-navigation';
+
+import { ExploreDestinationsGroup } from '../ExploreDestinationsGroup';
+
+const ref: any = null;
+const data = [
+  {
+    departure: {
+      airport: {
+        id: '1',
+        type: 'airport',
+        code: 'LPA',
+        city: { name: 'Las Palmas' },
+        country: { name: 'Spain' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '2',
+        type: 'airport',
+        code: 'DUB',
+        city: { name: 'Dublin' },
+        country: { name: 'Ireland' },
+      },
+    },
+    id: 'leg_1',
+    $refType: ref,
+  },
+  {
+    departure: {
+      airport: {
+        id: '3',
+        type: 'airport',
+        code: 'DUB',
+        city: { name: 'Dublin' },
+        country: { name: 'Ireland' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '4',
+        type: 'airport',
+        code: 'PRG',
+        city: { name: 'Prague' },
+        country: { name: 'Czechia' },
+      },
+    },
+    id: 'leg_2',
+    $refType: ref,
+  },
+  {
+    departure: {
+      airport: {
+        id: '5',
+        type: 'airport',
+        code: 'PRG',
+        city: { name: 'Prague' },
+        country: { name: 'Czechia' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '6',
+        type: 'station',
+        code: 'WRO',
+        city: { name: 'Wroclaw' },
+        country: { name: 'Poland' },
+      },
+    },
+    id: 'leg_3',
+    $refType: ref,
+  },
+];
+
+const dataWithoutAirports = [
+  {
+    departure: {
+      airport: {
+        id: '1',
+        type: 'station',
+        code: 'DUB',
+        city: { name: 'Prague' },
+        country: { name: 'Czechia' },
+      },
+    },
+    arrival: {
+      airport: {
+        id: '2',
+        type: 'station',
+        code: 'WRO',
+        city: { name: 'Wroclaw' },
+        country: { name: 'Poland' },
+      },
+    },
+    id: 'leg_1',
+    $refType: ref,
+  },
+];
+
+describe('Collect all destinations', () => {
+  it('should render 4 destinations', () => {
+    const wrapper = renderer.create(<ExploreDestinationsGroup data={data} />);
+
+    const destinations = wrapper.root.findAllByType(MenuItem);
+
+    expect(destinations).toHaveLength(4);
+  });
+
+  it('should render 4 destinations in order: Spain, Ireland, Czechia, Poland', () => {
+    const wrapper = renderer.create(<ExploreDestinationsGroup data={data} />);
+
+    const destinations = wrapper.root
+      .findAllByType(MenuItem)
+      .map(i => i.props.description)
+      .map(x => x.props.passThrough);
+
+    expect(destinations).toEqual(['Spain', 'Ireland', 'Czechia', 'Poland']);
+  });
+
+  it('should render 2 destination when airports have type station', () => {
+    const wrapper = renderer.create(
+      <ExploreDestinationsGroup data={dataWithoutAirports} />,
+    );
+
+    const airports = wrapper.root
+      .findAllByType(MenuItem)
+      .map(i => i.props.description)
+      .map(x => x.props.passThrough);
+
+    expect(airports).toEqual(['Czechia', 'Poland']);
+  });
+});