Browse Source

[+Elena] - #87 Add Enzyme and snapshot test

Jordi Coscolla 1 year ago
parent
commit
f7706af35c

+ 117 - 24
apps/atlantis/package-lock.json

@@ -62,9 +62,9 @@
62 62
       }
63 63
     },
64 64
     "@types/node": {
65
-      "version": "8.5.2",
66
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-8.5.2.tgz",
67
-      "integrity": "sha512-KA4GKOpgXnrqEH2eCVhiv2CsxgXGQJgV1X0vsGlh+WCnxbeAE1GT44ZsTU1IN5dEeV/gDupKa7gWo08V5IxWVQ==",
65
+      "version": "10.3.4",
66
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-10.3.4.tgz",
67
+      "integrity": "sha512-YMLlzdeNnAyLrQew39IFRkMacAR5BqKGIEei9ZjdHsIZtv+ZWKYTu1i7QJhetxQ9ReXx8w5f+cixdHZG3zgMQA==",
68 68
       "dev": true
69 69
     },
70 70
     "abab": {
@@ -2756,9 +2756,9 @@
2756 2756
       }
2757 2757
     },
2758 2758
     "domhandler": {
2759
-      "version": "2.4.1",
2760
-      "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.1.tgz",
2761
-      "integrity": "sha1-iS5HAAqZvlW783dP/qBWHYh5wlk=",
2759
+      "version": "2.4.2",
2760
+      "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz",
2761
+      "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==",
2762 2762
       "dev": true,
2763 2763
       "requires": {
2764 2764
         "domelementtype": "1.3.0"
@@ -2896,24 +2896,55 @@
2896 2896
       "dev": true
2897 2897
     },
2898 2898
     "enzyme": {
2899
-      "version": "3.2.0",
2900
-      "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.2.0.tgz",
2901
-      "integrity": "sha512-l0HcjycivXjB4IXkwuRc1K5z8hzWIVZB2b/Y/H2bao9eFTpBz4ACOwAQf44SgG5Nu3d1jF41LasxDgFWZeeysA==",
2899
+      "version": "3.3.0",
2900
+      "resolved": "https://registry.npmjs.org/enzyme/-/enzyme-3.3.0.tgz",
2901
+      "integrity": "sha512-l8csyPyLmtxskTz6pX9W8eDOyH1ckEtDttXk/vlFWCjv00SkjTjtoUrogqp4yEvMyneU9dUJoOLnqFoiHb8IHA==",
2902 2902
       "dev": true,
2903 2903
       "requires": {
2904 2904
         "cheerio": "1.0.0-rc.2",
2905
-        "function.prototype.name": "1.0.3",
2905
+        "function.prototype.name": "1.1.0",
2906 2906
         "has": "1.0.1",
2907
+        "is-boolean-object": "1.0.0",
2908
+        "is-callable": "1.1.3",
2909
+        "is-number-object": "1.0.3",
2910
+        "is-string": "1.0.4",
2907 2911
         "is-subset": "0.1.1",
2908 2912
         "lodash": "4.17.4",
2913
+        "object-inspect": "1.6.0",
2909 2914
         "object-is": "1.0.1",
2910
-        "object.assign": "4.0.4",
2915
+        "object.assign": "4.1.0",
2911 2916
         "object.entries": "1.0.4",
2912 2917
         "object.values": "1.0.4",
2913 2918
         "raf": "3.4.0",
2914 2919
         "rst-selector-parser": "2.2.3"
2915 2920
       }
2916 2921
     },
2922
+    "enzyme-adapter-react-16": {
2923
+      "version": "1.1.1",
2924
+      "resolved": "https://registry.npmjs.org/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.1.1.tgz",
2925
+      "integrity": "sha512-kC8pAtU2Jk3OJ0EG8Y2813dg9Ol0TXi7UNxHzHiWs30Jo/hj7alc//G1YpKUsPP1oKl9X+Lkx+WlGJpPYA+nvw==",
2926
+      "dev": true,
2927
+      "requires": {
2928
+        "enzyme-adapter-utils": "1.3.0",
2929
+        "lodash": "4.17.4",
2930
+        "object.assign": "4.1.0",
2931
+        "object.values": "1.0.4",
2932
+        "prop-types": "15.6.0",
2933
+        "react-reconciler": "0.7.0",
2934
+        "react-test-renderer": "16.4.1"
2935
+      }
2936
+    },
2937
+    "enzyme-adapter-utils": {
2938
+      "version": "1.3.0",
2939
+      "resolved": "https://registry.npmjs.org/enzyme-adapter-utils/-/enzyme-adapter-utils-1.3.0.tgz",
2940
+      "integrity": "sha512-vVXSt6uDv230DIv+ebCG66T1Pm36Kv+m74L1TrF4kaE7e1V7Q/LcxO0QRkajk5cA6R3uu9wJf5h13wOTezTbjA==",
2941
+      "dev": true,
2942
+      "requires": {
2943
+        "lodash": "4.17.4",
2944
+        "object.assign": "4.1.0",
2945
+        "prop-types": "15.6.0"
2946
+      }
2947
+    },
2917 2948
     "errno": {
2918 2949
       "version": "0.1.6",
2919 2950
       "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.6.tgz",
@@ -4332,9 +4363,9 @@
4332 4363
       "dev": true
4333 4364
     },
4334 4365
     "function.prototype.name": {
4335
-      "version": "1.0.3",
4336
-      "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.0.3.tgz",
4337
-      "integrity": "sha512-5EblxZUdioXi2JiMZ9FUbwYj40eQ9MFHyzFLBSPdlRl3SO8l7SLWuAnQ/at/1Wi4hjJwME/C5WpF2ZfAc8nGNw==",
4366
+      "version": "1.1.0",
4367
+      "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.0.tgz",
4368
+      "integrity": "sha512-Bs0VRrTz4ghD8pTmbJQD1mZ8A/mN0ur/jGz+A6FBxPDUPkm1tNfF6bhTYPA7i7aF4lZJVr+OXTNNrnnIl58Wfg==",
4338 4369
       "dev": true,
4339 4370
       "requires": {
4340 4371
         "define-properties": "1.1.2",
@@ -4604,6 +4635,12 @@
4604 4635
       "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz",
4605 4636
       "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo="
4606 4637
     },
4638
+    "has-symbols": {
4639
+      "version": "1.0.0",
4640
+      "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.0.tgz",
4641
+      "integrity": "sha1-uhqPGvKg/DllD1yFA2dwQSIGO0Q=",
4642
+      "dev": true
4643
+    },
4607 4644
     "has-unicode": {
4608 4645
       "version": "2.0.1",
4609 4646
       "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
@@ -4834,7 +4871,7 @@
4834 4871
       "dev": true,
4835 4872
       "requires": {
4836 4873
         "domelementtype": "1.3.0",
4837
-        "domhandler": "2.4.1",
4874
+        "domhandler": "2.4.2",
4838 4875
         "domutils": "1.5.1",
4839 4876
         "entities": "1.1.1",
4840 4877
         "inherits": "2.0.3",
@@ -5099,6 +5136,12 @@
5099 5136
         "binary-extensions": "1.11.0"
5100 5137
       }
5101 5138
     },
5139
+    "is-boolean-object": {
5140
+      "version": "1.0.0",
5141
+      "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.0.0.tgz",
5142
+      "integrity": "sha1-mPiygDBoQhmpXzdc+9iM40Bd/5M=",
5143
+      "dev": true
5144
+    },
5102 5145
     "is-buffer": {
5103 5146
       "version": "1.1.6",
5104 5147
       "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
@@ -5260,6 +5303,12 @@
5260 5303
         "kind-of": "3.2.2"
5261 5304
       }
5262 5305
     },
5306
+    "is-number-object": {
5307
+      "version": "1.0.3",
5308
+      "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.3.tgz",
5309
+      "integrity": "sha1-8mWrian0RQNO9q/xWo8AsA9VF5k=",
5310
+      "dev": true
5311
+    },
5263 5312
     "is-obj": {
5264 5313
       "version": "1.0.1",
5265 5314
       "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-1.0.1.tgz",
@@ -5347,6 +5396,12 @@
5347 5396
       "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
5348 5397
       "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
5349 5398
     },
5399
+    "is-string": {
5400
+      "version": "1.0.4",
5401
+      "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.4.tgz",
5402
+      "integrity": "sha1-zDqbaYV9Yh6WNyWiTK7shzuCbmQ=",
5403
+      "dev": true
5404
+    },
5350 5405
     "is-subset": {
5351 5406
       "version": "0.1.1",
5352 5407
       "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz",
@@ -7435,14 +7490,15 @@
7435 7490
       }
7436 7491
     },
7437 7492
     "nearley": {
7438
-      "version": "2.11.0",
7439
-      "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.11.0.tgz",
7440
-      "integrity": "sha512-clqqhEuP0ZCJQ85Xv2I/4o2Gs/fvSR6fCg5ZHVE2c8evWyNk2G++ih4JOO3lMb/k/09x6ihQ2nzKUlB/APCWjg==",
7493
+      "version": "2.13.0",
7494
+      "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.13.0.tgz",
7495
+      "integrity": "sha512-ioYYogSaZhFlCpRizQgY3UT3G1qFXmHGY/5ozoFE3dMfiCRAeJfh+IPE3/eh9gCZvqLhPCWb4bLt7Bqzo+1mLQ==",
7441 7496
       "dev": true,
7442 7497
       "requires": {
7443 7498
         "nomnom": "1.6.2",
7444 7499
         "railroad-diagrams": "1.0.0",
7445
-        "randexp": "0.4.6"
7500
+        "randexp": "0.4.6",
7501
+        "semver": "5.4.1"
7446 7502
       }
7447 7503
     },
7448 7504
     "negotiator": {
@@ -8028,6 +8084,12 @@
8028 8084
         }
8029 8085
       }
8030 8086
     },
8087
+    "object-inspect": {
8088
+      "version": "1.6.0",
8089
+      "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.6.0.tgz",
8090
+      "integrity": "sha512-GJzfBZ6DgDAmnuaM3104jR4s1Myxr3Y3zfIyN4z3UdqN69oSRacNK8UhnobDdC+7J2AHCjGwxQubNJfE70SXXQ==",
8091
+      "dev": true
8092
+    },
8031 8093
     "object-is": {
8032 8094
       "version": "1.0.1",
8033 8095
       "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.0.1.tgz",
@@ -8049,13 +8111,14 @@
8049 8111
       }
8050 8112
     },
8051 8113
     "object.assign": {
8052
-      "version": "4.0.4",
8053
-      "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.0.4.tgz",
8054
-      "integrity": "sha1-scnMBE7xuf5jYG/BQau7MuFHMMw=",
8114
+      "version": "4.1.0",
8115
+      "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz",
8116
+      "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==",
8055 8117
       "dev": true,
8056 8118
       "requires": {
8057 8119
         "define-properties": "1.1.2",
8058 8120
         "function-bind": "1.1.1",
8121
+        "has-symbols": "1.0.0",
8059 8122
         "object-keys": "1.0.11"
8060 8123
       }
8061 8124
     },
@@ -8305,7 +8368,7 @@
8305 8368
       "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
8306 8369
       "dev": true,
8307 8370
       "requires": {
8308
-        "@types/node": "8.5.2"
8371
+        "@types/node": "10.3.4"
8309 8372
       }
8310 8373
     },
8311 8374
     "parseurl": {
@@ -9371,6 +9434,24 @@
9371 9434
         "prop-types": "15.6.0"
9372 9435
       }
9373 9436
     },
9437
+    "react-is": {
9438
+      "version": "16.4.1",
9439
+      "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.4.1.tgz",
9440
+      "integrity": "sha512-xpb0PpALlFWNw/q13A+1aHeyJyLYCg0/cCHPUA43zYluZuIPHaHL3k8OBsTgQtxqW0FhyDEMvi8fZ/+7+r4OSQ==",
9441
+      "dev": true
9442
+    },
9443
+    "react-reconciler": {
9444
+      "version": "0.7.0",
9445
+      "resolved": "https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.7.0.tgz",
9446
+      "integrity": "sha512-50JwZ3yNyMS8fchN+jjWEJOH3Oze7UmhxeoJLn2j6f3NjpfCRbcmih83XTWmzqtar/ivd5f7tvQhvvhism2fgg==",
9447
+      "dev": true,
9448
+      "requires": {
9449
+        "fbjs": "0.8.16",
9450
+        "loose-envify": "1.3.1",
9451
+        "object-assign": "4.1.1",
9452
+        "prop-types": "15.6.0"
9453
+      }
9454
+    },
9374 9455
     "react-router-dom": {
9375 9456
       "version": "4.2.2",
9376 9457
       "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-4.2.2.tgz",
@@ -9413,6 +9494,18 @@
9413 9494
         }
9414 9495
       }
9415 9496
     },
9497
+    "react-test-renderer": {
9498
+      "version": "16.4.1",
9499
+      "resolved": "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.4.1.tgz",
9500
+      "integrity": "sha512-wyyiPxRZOTpKnNIgUBOB6xPLTpIzwcQMIURhZvzUqZzezvHjaGNsDPBhMac5fIY3Jf5NuKxoGvV64zDSOECPPQ==",
9501
+      "dev": true,
9502
+      "requires": {
9503
+        "fbjs": "0.8.16",
9504
+        "object-assign": "4.1.1",
9505
+        "prop-types": "15.6.0",
9506
+        "react-is": "16.4.1"
9507
+      }
9508
+    },
9416 9509
     "read-pkg": {
9417 9510
       "version": "1.1.0",
9418 9511
       "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
@@ -9871,7 +9964,7 @@
9871 9964
       "dev": true,
9872 9965
       "requires": {
9873 9966
         "lodash.flattendeep": "4.4.0",
9874
-        "nearley": "2.11.0"
9967
+        "nearley": "2.13.0"
9875 9968
       }
9876 9969
     },
9877 9970
     "rsvp": {

+ 2 - 1
apps/atlantis/package.json

@@ -34,7 +34,8 @@
34 34
     "chai": "^4.1.2",
35 35
     "copy-webpack-plugin": "^4.3.1",
36 36
     "css-loader": "^0.28.7",
37
-    "enzyme": "^3.2.0",
37
+    "enzyme": "^3.3.0",
38
+    "enzyme-adapter-react-16": "^1.1.1",
38 39
     "html-webpack-plugin": "^2.30.1",
39 40
     "jest": "^23.1.0",
40 41
     "mocha": "^4.0.1",

+ 15 - 1
apps/atlantis/test/Verify.test.js

@@ -1,4 +1,9 @@
1
-const { formUrl } = require('../src/client/components/Verify');
1
+import React from 'react';
2
+import { configure, shallow } from 'enzyme';
3
+import Adapter from 'enzyme-adapter-react-16';
4
+import Verify, { formUrl } from '../src/client/components/Verify';
5
+
6
+configure({ adapter: new Adapter() });
2 7
 
3 8
 const assert = require('assert');
4 9
 
@@ -30,4 +35,13 @@ describe('VerifyComponent', () => {
30 35
       assert.equal(formattedUrl, expectedUrl);
31 36
     });
32 37
   });
38
+
39
+  describe('when rendered', () => {
40
+    it('should match this snapshot', () => {
41
+      const wrapper = shallow(
42
+        <Verify />,
43
+      );
44
+      expect(wrapper.dive()).toMatchSnapshot();
45
+    });
46
+  });
33 47
 });

+ 207 - 0
apps/atlantis/test/__snapshots__/Verify.test.js.snap

@@ -0,0 +1,207 @@
1
+// Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+exports[`VerifyComponent when rendered should match this snapshot 1`] = `
4
+ShallowWrapper {
5
+  "length": 1,
6
+  Symbol(enzyme.__root__): [Circular],
7
+  Symbol(enzyme.__unrendered__): <styled.div>
8
+    <HeaderComponent />
9
+    <styled.div>
10
+      Climate change petition
11
+    </styled.div>
12
+    <styled.div>
13
+      To confirm your redisency enter your NIF or NIE.
14
+    </styled.div>
15
+    <styled.input
16
+      type="text"
17
+    />
18
+    <styled.button
19
+      onClick={[Function]}
20
+    >
21
+      Next
22
+    </styled.button>
23
+  </styled.div>,
24
+  Symbol(enzyme.__renderer__): Object {
25
+    "batchedUpdates": [Function],
26
+    "getNode": [Function],
27
+    "render": [Function],
28
+    "simulateEvent": [Function],
29
+    "unmount": [Function],
30
+  },
31
+  Symbol(enzyme.__node__): Object {
32
+    "instance": null,
33
+    "key": undefined,
34
+    "nodeType": "host",
35
+    "props": Object {
36
+      "children": Array [
37
+        <HeaderComponent />,
38
+        <styled.div>
39
+          Climate change petition
40
+        </styled.div>,
41
+        <styled.div>
42
+          To confirm your redisency enter your NIF or NIE.
43
+        </styled.div>,
44
+        <styled.input
45
+          type="text"
46
+        />,
47
+        <styled.button
48
+          onClick={[Function]}
49
+        >
50
+          Next
51
+        </styled.button>,
52
+      ],
53
+      "className": "sc-htpNat iriqgp",
54
+    },
55
+    "ref": null,
56
+    "rendered": Array [
57
+      Object {
58
+        "instance": null,
59
+        "key": undefined,
60
+        "nodeType": "function",
61
+        "props": Object {},
62
+        "ref": null,
63
+        "rendered": null,
64
+        "type": [Function],
65
+      },
66
+      Object {
67
+        "instance": null,
68
+        "key": undefined,
69
+        "nodeType": "class",
70
+        "props": Object {
71
+          "children": "Climate change petition",
72
+        },
73
+        "ref": null,
74
+        "rendered": "Climate change petition",
75
+        "type": [Function],
76
+      },
77
+      Object {
78
+        "instance": null,
79
+        "key": undefined,
80
+        "nodeType": "class",
81
+        "props": Object {
82
+          "children": "To confirm your redisency enter your NIF or NIE.",
83
+        },
84
+        "ref": null,
85
+        "rendered": "To confirm your redisency enter your NIF or NIE.",
86
+        "type": [Function],
87
+      },
88
+      Object {
89
+        "instance": null,
90
+        "key": undefined,
91
+        "nodeType": "class",
92
+        "props": Object {
93
+          "type": "text",
94
+        },
95
+        "ref": null,
96
+        "rendered": null,
97
+        "type": [Function],
98
+      },
99
+      Object {
100
+        "instance": null,
101
+        "key": undefined,
102
+        "nodeType": "class",
103
+        "props": Object {
104
+          "children": "Next",
105
+          "onClick": [Function],
106
+        },
107
+        "ref": null,
108
+        "rendered": "Next",
109
+        "type": [Function],
110
+      },
111
+    ],
112
+    "type": "div",
113
+  },
114
+  Symbol(enzyme.__nodes__): Array [
115
+    Object {
116
+      "instance": null,
117
+      "key": undefined,
118
+      "nodeType": "host",
119
+      "props": Object {
120
+        "children": Array [
121
+          <HeaderComponent />,
122
+          <styled.div>
123
+            Climate change petition
124
+          </styled.div>,
125
+          <styled.div>
126
+            To confirm your redisency enter your NIF or NIE.
127
+          </styled.div>,
128
+          <styled.input
129
+            type="text"
130
+          />,
131
+          <styled.button
132
+            onClick={[Function]}
133
+          >
134
+            Next
135
+          </styled.button>,
136
+        ],
137
+        "className": "sc-htpNat iriqgp",
138
+      },
139
+      "ref": null,
140
+      "rendered": Array [
141
+        Object {
142
+          "instance": null,
143
+          "key": undefined,
144
+          "nodeType": "function",
145
+          "props": Object {},
146
+          "ref": null,
147
+          "rendered": null,
148
+          "type": [Function],
149
+        },
150
+        Object {
151
+          "instance": null,
152
+          "key": undefined,
153
+          "nodeType": "class",
154
+          "props": Object {
155
+            "children": "Climate change petition",
156
+          },
157
+          "ref": null,
158
+          "rendered": "Climate change petition",
159
+          "type": [Function],
160
+        },
161
+        Object {
162
+          "instance": null,
163
+          "key": undefined,
164
+          "nodeType": "class",
165
+          "props": Object {
166
+            "children": "To confirm your redisency enter your NIF or NIE.",
167
+          },
168
+          "ref": null,
169
+          "rendered": "To confirm your redisency enter your NIF or NIE.",
170
+          "type": [Function],
171
+        },
172
+        Object {
173
+          "instance": null,
174
+          "key": undefined,
175
+          "nodeType": "class",
176
+          "props": Object {
177
+            "type": "text",
178
+          },
179
+          "ref": null,
180
+          "rendered": null,
181
+          "type": [Function],
182
+        },
183
+        Object {
184
+          "instance": null,
185
+          "key": undefined,
186
+          "nodeType": "class",
187
+          "props": Object {
188
+            "children": "Next",
189
+            "onClick": [Function],
190
+          },
191
+          "ref": null,
192
+          "rendered": "Next",
193
+          "type": [Function],
194
+        },
195
+      ],
196
+      "type": "div",
197
+    },
198
+  ],
199
+  Symbol(enzyme.__options__): Object {
200
+    "adapter": ReactSixteenAdapter {
201
+      "options": Object {
202
+        "enableComponentDidUpdateOnSetState": true,
203
+      },
204
+    },
205
+  },
206
+}
207
+`;