Browse Source

[+Jordi] - #87 Add behavior to skip attributes summary page if attributes already verified

Elena Cristina Raffay Iglesias 1 year ago
parent
commit
9424f55ac7
2 changed files with 53 additions and 15 deletions
  1. 20 10
      apps/wallet/screens/Home.js
  2. 33 5
      apps/wallet/test/components/Home.test.js

+ 20 - 10
apps/wallet/screens/Home.js

@@ -19,7 +19,7 @@ const decodeLogo = require('../assets/images/decode-hexagon.png');
19 19
 class Home extends React.Component {
20 20
   constructor(props) {
21 21
     super(props);
22
-    this.goToNextPage = this.goToNextPage.bind(this);
22
+    this.validatePinCode = this.validatePinCode.bind(this);
23 23
   }
24 24
 
25 25
   componentWillMount() {
@@ -27,17 +27,27 @@ class Home extends React.Component {
27 27
     this.props.initializeState().then(() => {});
28 28
   }
29 29
 
30
+  goToPetition() {
31
+    const isAttributeVerified = this.props.attributes.list.length > 0;
32
+    if (isAttributeVerified) {
33
+      this.props.goToPetitionSummary(this.props.petitionLink);
34
+    } else {
35
+      this.props.goToAttributesSummary(this.props.petitionLink);
36
+    }
37
+  }
38
+
30 39
   goToNextPage() {
40
+    if (this.props.petitionLink) {
41
+      this.goToPetition();
42
+    } else {
43
+      this.props.goQRScannerIntro();
44
+    }
45
+  }
46
+
47
+  validatePinCode() {
31 48
     return this.props.doAuthorize(this.props.pinCode).then((action) => {
32 49
       if (action.pinCorrect) {
33
-        const isAttributeVerified = this.props.attributes.list.length > 0;
34
-        if (this.props.petitionLink && !isAttributeVerified) {
35
-          this.props.goToAttributesSummary(this.props.petitionLink);
36
-        } else if (this.props.petitionLink) {
37
-          this.props.goToPetitionSummary(this.props.petitionLink);
38
-        } else {
39
-          this.props.goQRScannerIntro();
40
-        }
50
+        this.goToNextPage();
41 51
       } else {
42 52
         alert('Incorrect pin code'); // eslint-disable-line
43 53
       }
@@ -69,7 +79,7 @@ class Home extends React.Component {
69 79
           <View style={{ flexDirection: 'row' }}>
70 80
             <Button
71 81
               name="Sign In"
72
-              onPress={this.goToNextPage}
82
+              onPress={this.validatePinCode}
73 83
               style={{
74 84
                 width: 150,
75 85
                 alignItems: 'center',

+ 33 - 5
apps/wallet/test/components/Home.test.js

@@ -9,10 +9,11 @@ Enzyme.configure({ adapter: new Adapter() });
9 9
 
10 10
 const mockStore = configureStore([thunk]);
11 11
 
12
-describe('goToNextPage', () => {
12
+describe('validatePinCode', () => {
13 13
   const somePetitionLink = 'http://city-counsil.com';
14 14
   const alertMock = jest.fn();
15 15
   const goToAttributesSummaryMock = jest.fn();
16
+  const goToPetitionSummaryMock = jest.fn();
16 17
   const goQRScannerIntroMock = jest.fn();
17 18
 
18 19
   beforeEach(() => {
@@ -47,7 +48,7 @@ describe('goToNextPage', () => {
47 48
         doAuthorize: doAuthorizeMock,
48 49
       };
49 50
 
50
-      await homeComponent.goToNextPage();
51
+      await homeComponent.validatePinCode();
51 52
 
52 53
       expect(alertMock).toBeCalled();
53 54
       expect(goToAttributesSummaryMock).not.toBeCalled();
@@ -79,12 +80,12 @@ describe('goToNextPage', () => {
79 80
         doAuthorize: doAuthorizeMock,
80 81
       };
81 82
 
82
-      await homeComponent.goToNextPage();
83
+      await homeComponent.validatePinCode();
83 84
 
84 85
       expect(goQRScannerIntroMock).toBeCalled();
85 86
     });
86 87
 
87
-    it('should call goToAttributesSummary if there is a petitionLink and ', async () => {
88
+    it('should call goToAttributesSummary if there is a petitionLink and the required attribute is not verified', async () => {
88 89
       const initialState = {
89 90
         petitionLink: {
90 91
           petitionLink: somePetitionLink,
@@ -105,9 +106,36 @@ describe('goToNextPage', () => {
105 106
         doAuthorize: doAuthorizeMock,
106 107
       };
107 108
 
108
-      await homeComponent.goToNextPage();
109
+      await homeComponent.validatePinCode();
109 110
 
110 111
       expect(goToAttributesSummaryMock).toBeCalledWith(somePetitionLink);
111 112
     });
113
+
114
+    it('should call goToPetitionSummary if there is a petitionLink and the required attribute is verified', async () => {
115
+      const initialState = {
116
+        petitionLink: {
117
+          petitionLink: somePetitionLink,
118
+        },
119
+        authorization: {},
120
+        attributes: {
121
+          list: [{}],
122
+        },
123
+      };
124
+      const wrapper = shallow(
125
+        <Home />,
126
+        { context: { store: mockStore(initialState) } },
127
+      );
128
+      const homeComponent = wrapper.dive().instance();
129
+      homeComponent.props = {
130
+        ...homeComponent.props,
131
+        goToAttributesSummary: goToAttributesSummaryMock,
132
+        goToPetitionSummary: goToPetitionSummaryMock,
133
+        doAuthorize: doAuthorizeMock,
134
+      };
135
+
136
+      await homeComponent.validatePinCode();
137
+
138
+      expect(goToPetitionSummaryMock).toBeCalledWith(somePetitionLink);
139
+    });
112 140
   });
113 141
 });