Repository: kiwicom/mobile
Pull request #676 (2018-05-30 08:42:06)

MMB: Hide visa information for past trips


Patch:
diff --git a/app/MMB/src/scenes/passenger/visa/VisaInformation.js b/app/MMB/src/scenes/passenger/visa/VisaInformation.js
index 37f03f44..035ef43a 100644
--- a/app/MMB/src/scenes/passenger/visa/VisaInformation.js
+++ b/app/MMB/src/scenes/passenger/visa/VisaInformation.js
@@ -8,15 +8,21 @@ import VisaRequired from './VisaRequired';
 import VisaOk from './VisaOk';
 import VisaWarning from './VisaWarning';
 import type { VisaInformation_visa as VisaType } from './__generated__/VisaInformation_visa.graphql';
+import ManageMyBookingContext from '../../../context/BookingDetailContext';
 
-type Props = {|
-  visa: VisaType,
+type PropsWithContext = {|
+  ...Props,
+  +isPastBooking: boolean,
 |};
 
-const VisaInformation = (props: Props) => {
+export const VisaInformation = (props: PropsWithContext) => {
   const requiredIn = idx(props.visa, _ => _.visaInformation.requiredIn) || [];
   const warningIn = idx(props.visa, _ => _.visaInformation.warningIn) || [];
 
+  if (props.isPastBooking) {
+    return null;
+  }
+
   if (requiredIn.length === 0 && warningIn.length === 0) {
     return <VisaOk />;
   }
@@ -33,8 +39,20 @@ const VisaInformation = (props: Props) => {
   );
 };
 
+type Props = {|
+  +visa: VisaType,
+|};
+
+const VisaInformationWithContext = (props: Props) => (
+  <ManageMyBookingContext.Consumer>
+    {({ isPastBooking }) => (
+      <VisaInformation {...props} isPastBooking={isPastBooking} />
+    )}
+  </ManageMyBookingContext.Consumer>
+);
+
 export default createFragmentContainer(
-  VisaInformation,
+  VisaInformationWithContext,
   graphql`
     fragment VisaInformation_visa on Passenger {
       visaInformation {


Test patch:
diff --git a/app/MMB/src/scenes/passenger/__tests__/__snapshots__/Passenger.test.js.snap b/app/MMB/src/scenes/passenger/__tests__/__snapshots__/Passenger.test.js.snap
index 0a2c901b..47399967 100644
--- a/app/MMB/src/scenes/passenger/__tests__/__snapshots__/Passenger.test.js.snap
+++ b/app/MMB/src/scenes/passenger/__tests__/__snapshots__/Passenger.test.js.snap
@@ -73,7 +73,7 @@ exports[`renders 1`] = `
         }
       />
     </Row>
-    <Relay(VisaInformation)
+    <Relay(VisaInformationWithContext)
       visa={
         Object {
           "birthday": "1984-05-10T00:00:00.000Z",
diff --git a/app/MMB/src/scenes/passenger/visa/__tests__/VisaInformation.test.js b/app/MMB/src/scenes/passenger/visa/__tests__/VisaInformation.test.js
new file mode 100644
index 00000000..a697905a
--- /dev/null
+++ b/app/MMB/src/scenes/passenger/visa/__tests__/VisaInformation.test.js
@@ -0,0 +1,65 @@
+// @flow
+
+import * as React from 'react';
+import renderer from 'react-test-renderer';
+
+import { VisaInformation } from '../VisaInformation';
+import VisaOk from '../VisaOk';
+import VisaRequired from '../VisaRequired';
+import VisaWarning from '../VisaWarning';
+
+const defaultProps = {
+  visa: {
+    visaInformation: {
+      requiredIn: [],
+      warningIn: [],
+    },
+    isPastBooking: false,
+  },
+};
+
+describe('VisaInformation', () => {
+  it('renders null for past bookings', () => {
+    const props = {
+      ...defaultProps,
+      isPastBooking: true,
+    };
+    // $FlowRelayIssue: https://github.com/facebook/relay/issues/2394
+    const wrapper = renderer.create(<VisaInformation {...props} />);
+
+    expect(wrapper.toTree().rendered).toBe(null);
+  });
+
+  it('renders visa ok when requiredIn and warningIn contains no elements', () => {
+    // $FlowRelayIssue: https://github.com/facebook/relay/issues/2394
+    const wrapper = renderer.create(<VisaInformation {...defaultProps} />);
+
+    expect(wrapper.root.findByType(VisaOk)).toBeDefined();
+    expect(() => {
+      wrapper.root.findByType(VisaRequired);
+    }).toThrow();
+    expect(() => {
+      wrapper.root.findByType(VisaWarning);
+    }).toThrow();
+  });
+
+  it('renders visa warning and visa required when they contain elements', () => {
+    const props = {
+      ...defaultProps,
+      visa: {
+        visaInformation: {
+          requiredIn: [{ name: 'Norway' }],
+          warningIn: [{ name: 'Sweden' }],
+        },
+      },
+    };
+    // $FlowRelayIssue: https://github.com/facebook/relay/issues/2394
+    const wrapper = renderer.create(<VisaInformation {...props} />);
+
+    expect(wrapper.root.findByType(VisaRequired)).toBeDefined();
+    expect(wrapper.root.findByType(VisaWarning)).toBeDefined();
+    expect(() => {
+      wrapper.root.findByType(VisaOk);
+    }).toThrow();
+  });
+});