1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

more tests

This commit is contained in:
Matthias Kretschmann 2019-04-30 19:19:28 +02:00
parent 30d6679eb2
commit 9bdfca4be4
Signed by: m
GPG Key ID: 606EEEF3C479A91F
68 changed files with 2037 additions and 2436 deletions

View File

@ -0,0 +1,31 @@
const userMock = {
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
account: '',
web3: {},
ocean: {},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: jest.fn(),
unlockAccounts: jest.fn(),
message: ''
}
const userMockConnected = {
isLogged: true,
isLoading: false,
isWeb3: true,
isNile: true,
account: '0xxxxxx',
web3: {},
ocean: {},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: jest.fn(),
unlockAccounts: jest.fn(),
message: ''
}
export { userMock, userMockConnected }

108
client/package-lock.json generated
View File

@ -1242,14 +1242,14 @@
"integrity": "sha512-p2n505t2K0zD1ZvGPhI6EsSviEVLCB7BYowhf/ONmVaWED138PaG4Z9nY6YuHU383uOoIWT+Lq3dLkFzDzstXw==" "integrity": "sha512-p2n505t2K0zD1ZvGPhI6EsSviEVLCB7BYowhf/ONmVaWED138PaG4Z9nY6YuHU383uOoIWT+Lq3dLkFzDzstXw=="
}, },
"@oceanprotocol/keeper-contracts": { "@oceanprotocol/keeper-contracts": {
"version": "0.9.1", "version": "0.9.7",
"resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.9.1.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/keeper-contracts/-/keeper-contracts-0.9.7.tgz",
"integrity": "sha512-c1LvaH+e1tzow0gZLwSWe19ap+DrZuNmZfxBdwEVEPQXarI0jTXa5qVDoiBow8kBWaqSIUgFAzQOJW8rKdlS1A==" "integrity": "sha512-nOpbSE/BG+tQBfLXZ/EqSOvUPzOuot84vHxjAfEU8K3v4eOnqFJVo+oyB7KlcF87wBJXDmi/Ir9qHY4c0Saipg=="
}, },
"@oceanprotocol/squid": { "@oceanprotocol/squid": {
"version": "0.5.7", "version": "0.5.8",
"resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.7.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.8.tgz",
"integrity": "sha512-q2rdlVT4n0IW8FcTrE9sfyl8lC0moAKJillUSfWadZHjdaVikBTS3iiPiKn8RIvfBL4j3RxlVHdGQdEl8rIDfA==", "integrity": "sha512-1hEOA5rF8qsLF6uSMVBAN4c6Licn2FCGdWLCHpZ6ePzyA2/3RXxhreUE/0mcTkmdITwlx1rCFFO+rYhDqgyPVQ==",
"requires": { "requires": {
"@oceanprotocol/keeper-contracts": "^0.9.1", "@oceanprotocol/keeper-contracts": "^0.9.1",
"bignumber.js": "^8.1.1", "bignumber.js": "^8.1.1",
@ -1606,6 +1606,16 @@
"resolved": "https://registry.npmjs.org/@oceanprotocol/typographies/-/typographies-0.1.0.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/typographies/-/typographies-0.1.0.tgz",
"integrity": "sha512-kMsZsqvzpz9KzVbVZzllwhPoIC3zbqsdRrClagZL/C2PHzgLrKGC1kYn3gPt0RMIFg9ZjrwieKaxlgIK9i9zzg==" "integrity": "sha512-kMsZsqvzpz9KzVbVZzllwhPoIC3zbqsdRrClagZL/C2PHzgLrKGC1kYn3gPt0RMIFg9ZjrwieKaxlgIK9i9zzg=="
}, },
"@react-mock/state": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/@react-mock/state/-/state-0.1.8.tgz",
"integrity": "sha512-oX16w3FKhfF2+nQE+C4frrfVddzwhF4YEYxF8frXzboEDZsxCRpFuQC0za3T59ZxI4ygBarBqDrhYzipGsD9TQ==",
"dev": true,
"requires": {
"@babel/runtime": "^7.1.2",
"lodash": "^4.17.11"
}
},
"@sheerun/mutationobserver-shim": { "@sheerun/mutationobserver-shim": {
"version": "0.3.2", "version": "0.3.2",
"resolved": "https://registry.npmjs.org/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz", "resolved": "https://registry.npmjs.org/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz",
@ -1900,9 +1910,9 @@
"dev": true "dev": true
}, },
"@types/jest": { "@types/jest": {
"version": "24.0.11", "version": "24.0.12",
"resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.11.tgz", "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.12.tgz",
"integrity": "sha512-2kLuPC5FDnWIDvaJBzsGTBQaBbnDweznicvK7UGYzlIJP4RJR2a4A/ByLUXEyEgag6jz8eHdlWExGDtH3EYUXQ==", "integrity": "sha512-60sjqMhat7i7XntZckcSGV8iREJyXXI6yFHZkSZvCPUeOnEJ/VP1rU/WpEWQ56mvoh8NhC+sfKAuJRTyGtCOow==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/jest-diff": "*" "@types/jest-diff": "*"
@ -1932,9 +1942,9 @@
"dev": true "dev": true
}, },
"@types/react": { "@types/react": {
"version": "16.8.14", "version": "16.8.15",
"resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.14.tgz", "resolved": "https://registry.npmjs.org/@types/react/-/react-16.8.15.tgz",
"integrity": "sha512-26tFVJ1omGmzIdFTFmnC5zhz1GTaqCjxgUxV4KzWvsybF42P7/j4RBn6UeO3KbHPXqKWZszMXMoI65xIWm954A==", "integrity": "sha512-dMhzw1rWK+wwJWvPp5Pk12ksSrm/z/C/+lOQbMZ7YfDQYnJ02bc0wtg4EJD9qrFhuxFrf/ywNgwTboucobJqQg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/prop-types": "*", "@types/prop-types": "*",
@ -2009,9 +2019,9 @@
} }
}, },
"@types/react-transition-group": { "@types/react-transition-group": {
"version": "2.9.0", "version": "2.9.1",
"resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-2.9.0.tgz", "resolved": "https://registry.npmjs.org/@types/react-transition-group/-/react-transition-group-2.9.1.tgz",
"integrity": "sha512-hP7vUaZMVSWKxo133P8U51U6UZ7+pbY+eAQb8+p6SZ2rB1rj3mOTDgTzhhi+R2SCB4S+sWekAAGoxdiZPG0ReQ==", "integrity": "sha512-1usq4DRUVBFnxc9KGJAlJO9EpQrLZGDDEC8wDOn2+2ODSyudYo8FiIzPDRaX/hfQjHqGeeoNaNdA2bj0l35hZQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/react": "*" "@types/react": "*"
@ -5145,7 +5155,8 @@
"deep-equal": { "deep-equal": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=" "integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=",
"dev": true
}, },
"deep-is": { "deep-is": {
"version": "0.1.3", "version": "0.1.3",
@ -5439,15 +5450,15 @@
} }
}, },
"dom-testing-library": { "dom-testing-library": {
"version": "3.19.3", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/dom-testing-library/-/dom-testing-library-3.19.3.tgz", "resolved": "https://registry.npmjs.org/dom-testing-library/-/dom-testing-library-4.0.1.tgz",
"integrity": "sha512-oiI+oq91iO/Vpp+pt8PqfqLfBK074FH0eprhoFNvBCvJOk7vL4ozbe/yj/kEEGR6kiT4F3MAam19AX1fdGFjrA==", "integrity": "sha512-Yr0yWlpI2QdTDEgPEk0TEekwP4VyZlJpl9E7nKP2FCKni44cb1jzjsy9KX6hBDsNA7EVlPpq9DHzO2eoEaqDZg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/runtime": "^7.3.4", "@babel/runtime": "^7.4.3",
"@sheerun/mutationobserver-shim": "^0.3.2", "@sheerun/mutationobserver-shim": "^0.3.2",
"pretty-format": "^24.5.0", "pretty-format": "^24.7.0",
"wait-for-expect": "^1.1.0" "wait-for-expect": "^1.1.1"
} }
}, },
"dom-walk": { "dom-walk": {
@ -8810,9 +8821,9 @@
} }
}, },
"jest-dom": { "jest-dom": {
"version": "3.1.3", "version": "3.1.4",
"resolved": "https://registry.npmjs.org/jest-dom/-/jest-dom-3.1.3.tgz", "resolved": "https://registry.npmjs.org/jest-dom/-/jest-dom-3.1.4.tgz",
"integrity": "sha512-V9LdySiA74/spcAKEG3FRMRKnisKlcYr3EeCNYI4n7CWNE7uYg5WoBUHeGXirjWjRYLLZ5vx8rUaR/6x6o75oQ==", "integrity": "sha512-ruIRHoRVnqPRt/HSS2aFukfhTpjEoq1I6PkYptKK5U2EeRm1eeOXG7BFiaMncTaGu4COSoCF84oLHj02+J5VDg==",
"dev": true, "dev": true,
"requires": { "requires": {
"chalk": "^2.4.1", "chalk": "^2.4.1",
@ -10984,9 +10995,9 @@
} }
}, },
"node-fetch": { "node-fetch": {
"version": "2.3.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.3.0.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.5.0.tgz",
"integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==" "integrity": "sha512-YuZKluhWGJwCcUu4RlZstdAxr8bFfOVHakc1mplwHkk8J+tqM1Y5yraYvIUpeX8aY7+crCwiELJq7Vl0o0LWXw=="
}, },
"node-forge": { "node-forge": {
"version": "0.7.5", "version": "0.7.5",
@ -13049,9 +13060,9 @@
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
}, },
"query-string": { "query-string": {
"version": "6.4.2", "version": "6.5.0",
"resolved": "https://registry.npmjs.org/query-string/-/query-string-6.4.2.tgz", "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.5.0.tgz",
"integrity": "sha512-DfJqAen17LfLA3rQ+H5S4uXphrF+ANU1lT2ijds4V/Tj4gZxA3gx5/tg1bz7kYCmwna7LyJNCYqO7jNRzo3aLw==", "integrity": "sha512-TYC4hDjZSvVxLMEucDMySkuAS9UIzSbAiYGyA9GWCjLKB8fQpviFbjd20fD7uejCDxZS+ftSdBKE6DS+xucJFg==",
"requires": { "requires": {
"decode-uri-component": "^0.2.0", "decode-uri-component": "^0.2.0",
"split-on-first": "^1.0.0", "split-on-first": "^1.0.0",
@ -13178,9 +13189,9 @@
} }
}, },
"react-datepicker": { "react-datepicker": {
"version": "2.4.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/react-datepicker/-/react-datepicker-2.4.0.tgz", "resolved": "https://registry.npmjs.org/react-datepicker/-/react-datepicker-2.5.0.tgz",
"integrity": "sha512-ZOY7oYmZt+jeSFGj4NHNdCg7WzzIljPui98lGRd7YHNPO3B8Re4WVNALktp/x+mz1ofNO+TPzodMLMXzqjAUnw==", "integrity": "sha512-X8D+5CqumSUwoq/x5d8O0neYDRmPmwVcyCktVbs5juXV4s73beV6sMf87hM6lxMSanWeB+jpx8waxJcPqsmCIg==",
"requires": { "requires": {
"classnames": "^2.2.5", "classnames": "^2.2.5",
"date-fns": "^2.0.0-alpha.23", "date-fns": "^2.0.0-alpha.23",
@ -13359,19 +13370,24 @@
"integrity": "sha512-O9JRum1Zq/qCPFH5qVEvDDrVun8Jv9vbHtZXCR1EuRj9sKg1xJTlHxBzU6AkCzpvxRLuiY4OKImy3cDLQ+UTdg==", "integrity": "sha512-O9JRum1Zq/qCPFH5qVEvDDrVun8Jv9vbHtZXCR1EuRj9sKg1xJTlHxBzU6AkCzpvxRLuiY4OKImy3cDLQ+UTdg==",
"dev": true "dev": true
}, },
"react-fast-compare": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-2.0.4.tgz",
"integrity": "sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw=="
},
"react-ga": { "react-ga": {
"version": "2.5.7", "version": "2.5.7",
"resolved": "https://registry.npmjs.org/react-ga/-/react-ga-2.5.7.tgz", "resolved": "https://registry.npmjs.org/react-ga/-/react-ga-2.5.7.tgz",
"integrity": "sha512-UmATFaZpEQDO96KFjB5FRLcT6hFcwaxOmAJZnjrSiFN/msTqylq9G+z5Z8TYzN/dbamDTiWf92m6MnXXJkAivQ==" "integrity": "sha512-UmATFaZpEQDO96KFjB5FRLcT6hFcwaxOmAJZnjrSiFN/msTqylq9G+z5Z8TYzN/dbamDTiWf92m6MnXXJkAivQ=="
}, },
"react-helmet": { "react-helmet": {
"version": "5.2.0", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/react-helmet/-/react-helmet-5.2.0.tgz", "resolved": "https://registry.npmjs.org/react-helmet/-/react-helmet-5.2.1.tgz",
"integrity": "sha1-qBgR3yExOm1VxfBYxK66XW89l6c=", "integrity": "sha512-CnwD822LU8NDBnjCpZ4ySh8L6HYyngViTZLfBBb3NjtrpN8m49clH8hidHouq20I51Y6TpCTISCBbqiY5GamwA==",
"requires": { "requires": {
"deep-equal": "^1.0.1",
"object-assign": "^4.1.1", "object-assign": "^4.1.1",
"prop-types": "^15.5.4", "prop-types": "^15.5.4",
"react-fast-compare": "^2.0.2",
"react-side-effect": "^1.1.0" "react-side-effect": "^1.1.0"
} }
}, },
@ -13568,13 +13584,13 @@
} }
}, },
"react-testing-library": { "react-testing-library": {
"version": "6.1.2", "version": "7.0.0",
"resolved": "https://registry.npmjs.org/react-testing-library/-/react-testing-library-6.1.2.tgz", "resolved": "https://registry.npmjs.org/react-testing-library/-/react-testing-library-7.0.0.tgz",
"integrity": "sha512-z69lhRDGe7u/NOjDCeFRoe1cB5ckJ4656n0tj/Fdcr6OoBUu7q9DBw0ftR7v5i3GRpdSWelnvl+feZFOyXyxwg==", "integrity": "sha512-8SHqwG+uhN9VhAgNVkVa3f7VjTw/L5CIaoAxKmy+EZuDQ6O+VsfcpRAyUw3MDL1h8S/gGrEiazmHBVL/uXsftA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/runtime": "^7.4.2", "@babel/runtime": "^7.4.3",
"dom-testing-library": "^3.19.0" "dom-testing-library": "^4.0.0"
} }
}, },
"react-transition-group": { "react-transition-group": {
@ -15826,9 +15842,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.4.4", "version": "3.4.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.4.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
"integrity": "sha512-xt5RsIRCEaf6+j9AyOBgvVuAec0i92rgCaS3S+UVf5Z/vF2Hvtsw08wtUTJqp4djwznoAgjSxeCcU4r+CcDBJA==", "integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==",
"dev": true "dev": true
}, },
"ua-parser-js": { "ua-parser-js": {

View File

@ -6,14 +6,14 @@
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts --max_old_space_size=4096 build", "build": "react-scripts --max_old_space_size=4096 build",
"test": "react-scripts test --coverage", "test": "react-scripts test --coverage --watchAll=false",
"test:watch": "react-scripts test --coverage --watch", "test:watch": "react-scripts test --coverage",
"eject": "react-scripts eject", "eject": "react-scripts eject",
"coverage": "cat coverage/lcov.info | codacy-coverage --token 8801f827fe1144ffa85cd7da94f2bbf7" "coverage": "cat coverage/lcov.info | codacy-coverage --token 8801f827fe1144ffa85cd7da94f2bbf7"
}, },
"dependencies": { "dependencies": {
"@oceanprotocol/art": "^2.2.0", "@oceanprotocol/art": "^2.2.0",
"@oceanprotocol/squid": "^0.5.7", "@oceanprotocol/squid": "^0.5.8",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"ethereum-blockies": "MyEtherWallet/blockies", "ethereum-blockies": "MyEtherWallet/blockies",
@ -21,14 +21,14 @@
"history": "^4.9.0", "history": "^4.9.0",
"is-url": "^1.2.4", "is-url": "^1.2.4",
"moment": "^2.24.0", "moment": "^2.24.0",
"query-string": "^6.4.2", "query-string": "^6.5.0",
"react": "^16.8.6", "react": "^16.8.6",
"react-datepicker": "^2.3.0", "react-datepicker": "^2.5.0",
"react-dom": "^16.8.6", "react-dom": "^16.8.6",
"react-dotdotdot": "^1.2.3", "react-dotdotdot": "^1.3.0",
"react-ga": "^2.5.7", "react-ga": "^2.5.7",
"react-helmet": "^5.2.0", "react-helmet": "^5.2.1",
"react-markdown": "^4.0.6", "react-markdown": "^4.0.8",
"react-moment": "^0.9.2", "react-moment": "^0.9.2",
"react-paginate": "^6.3.0", "react-paginate": "^6.3.0",
"react-popper": "^1.3.3", "react-popper": "^1.3.3",
@ -38,24 +38,25 @@
"web3": "1.0.0-beta.37" "web3": "1.0.0-beta.37"
}, },
"devDependencies": { "devDependencies": {
"@react-mock/state": "^0.1.8",
"@types/classnames": "^2.2.7", "@types/classnames": "^2.2.7",
"@types/filesize": "^4.1.0", "@types/filesize": "^4.1.0",
"@types/is-url": "^1.2.28", "@types/is-url": "^1.2.28",
"@types/jest": "^24.0.11", "@types/jest": "^24.0.12",
"@types/react": "^16.8.13", "@types/react": "^16.8.15",
"@types/react-datepicker": "^2.2.1", "@types/react-datepicker": "^2.3.0",
"@types/react-dom": "^16.8.3", "@types/react-dom": "^16.8.4",
"@types/react-dotdotdot": "^1.2.0", "@types/react-dotdotdot": "^1.2.0",
"@types/react-helmet": "^5.0.8", "@types/react-helmet": "^5.0.8",
"@types/react-paginate": "^6.2.1", "@types/react-paginate": "^6.2.1",
"@types/react-router-dom": "^4.3.1", "@types/react-router-dom": "^4.3.2",
"@types/react-transition-group": "^2.8.0", "@types/react-transition-group": "^2.9.1",
"@types/web3": "^1.0.18", "@types/web3": "^1.0.18",
"jest-dom": "^3.1.3", "jest-dom": "^3.1.4",
"node-sass": "^4.12.0", "node-sass": "^4.12.0",
"react-scripts": "^3.0.0", "react-scripts": "^3.0.0",
"react-testing-library": "^6.1.2", "react-testing-library": "^7.0.0",
"typescript": "^3.4.3" "typescript": "^3.4.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -66,5 +67,11 @@
"not dead", "not dead",
"not ie <= 11", "not ie <= 11",
"not op_mini all" "not op_mini all"
] ],
"jest": {
"collectCoverageFrom": [
"src/**/*.{ts,tsx}",
"!src/serviceWorker.ts"
]
}
} }

View File

@ -1,10 +1,25 @@
import React from 'react' import React from 'react'
import { render } from 'react-testing-library' import { render } from 'react-testing-library'
import App from './App' import App from './App'
import { User } from './context'
import { userMock } from '../__mocks__/user-mock'
describe('App', () => { describe('App', () => {
it('should be able to run tests', () => {
expect(1 + 2).toEqual(3)
})
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render(<App />) const { container } = render(<App />)
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()
}) })
it('renders loading state', () => {
const { container } = render(
<User.Provider value={{ ...userMock, isLoading: true }}>
<App />
</User.Provider>
)
expect(container.querySelector('.spinner')).toBeInTheDocument()
})
}) })

View File

@ -4,7 +4,6 @@ import Header from './components/organisms/Header'
import Footer from './components/organisms/Footer' import Footer from './components/organisms/Footer'
import Spinner from './components/atoms/Spinner' import Spinner from './components/atoms/Spinner'
import { User } from './context' import { User } from './context'
import UserProvider from './context/UserProvider'
import Routes from './Routes' import Routes from './Routes'
import './styles/global.scss' import './styles/global.scss'
import styles from './App.module.scss' import styles from './App.module.scss'
@ -12,33 +11,27 @@ import styles from './App.module.scss'
export default class App extends Component { export default class App extends Component {
public render() { public render() {
return ( return (
<UserProvider> <div className={styles.app}>
<div className={styles.app}> <Router>
<Router> <>
<> <Header />
<Header />
<main className={styles.main}> <main className={styles.main}>
<User.Consumer> {this.context.isLoading ? (
{states => <div className={styles.loader}>
states.isLoading ? ( <Spinner message={this.context.message} />
<div className={styles.loader}> </div>
<Spinner ) : (
message={states.message} <Routes />
/> )}
</div> </main>
) : (
<Routes />
)
}
</User.Consumer>
</main>
<Footer /> <Footer />
</> </>
</Router> </Router>
</div> </div>
</UserProvider>
) )
} }
} }
App.contextType = User

View File

@ -0,0 +1,15 @@
import React from 'react'
import { BrowserRouter as Router } from 'react-router-dom'
import { render } from 'react-testing-library'
import Routes from './Routes'
describe('Routes', () => {
it('renders without crashing', () => {
const { container } = render(
<Router>
<Routes />
</Router>
)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -0,0 +1,28 @@
import React from 'react'
import { render } from 'react-testing-library'
import { toDataUrl } from 'ethereum-blockies'
import Account from './Account'
describe('Account', () => {
it('renders without crashing', () => {
const { container } = render(<Account account={'0xxxxxxxxxxxxxxx'} />)
expect(container.firstChild).toBeInTheDocument()
})
it('outputs empty state without account', () => {
const { container } = render(<Account account={''} />)
expect(container.firstChild).toHaveTextContent('No account selected')
})
it('outputs blockie img', () => {
const account = '0xxxxxxxxxxxxxxx'
const blockies = toDataUrl(account)
const { container } = render(<Account account={account} />)
expect(container.querySelector('.blockies')).toBeInTheDocument()
expect(container.querySelector('.blockies')).toHaveAttribute(
'src',
blockies
)
})
})

View File

@ -4,7 +4,7 @@ import { toDataUrl } from 'ethereum-blockies'
import styles from './Account.module.scss' import styles from './Account.module.scss'
const Account = ({ account }: { account: string }) => { const Account = ({ account }: { account: string }) => {
const blockies = toDataUrl(account) const blockies = account && toDataUrl(account)
return account && blockies ? ( return account && blockies ? (
<div className={styles.account}> <div className={styles.account}>

View File

@ -1,16 +1,13 @@
import React from 'react' import React from 'react'
import { render } from 'react-testing-library' import { render } from 'react-testing-library'
import slugify from 'slugify'
import CategoryImage from './CategoryImage' import CategoryImage from './CategoryImage'
import formPublish from '../../data/form-publish.json' import formPublish from '../../data/form-publish.json'
describe('CategoryImage', () => { describe('CategoryImage', () => {
it('renders fallback image', () => { it('renders fallback image', () => {
const { container, getByTestId } = render( const { container } = render(<CategoryImage category={''} />)
<CategoryImage data-testid="image" category={''} />
)
expect(container.firstChild).toBeInTheDocument() expect(container.firstChild).toBeInTheDocument()
expect(getByTestId('image').style.backgroundImage).toMatch( expect(container.firstChild.style.backgroundImage).toMatch(
/jellyfish-back/ /jellyfish-back/
) )
}) })
@ -21,13 +18,8 @@ describe('CategoryImage', () => {
: [] : []
options.map((category: string) => { options.map((category: string) => {
const { getByTestId } = render( const { container } = render(<CategoryImage category={category} />)
<CategoryImage data-testid="image" category={category} /> expect(container.firstChild).toBeInTheDocument()
)
expect(getByTestId('image')).toBeInTheDocument()
// expect(getByTestId('image').style.backgroundImage).toMatch(
// slugify(category, { lower: true })
// )
}) })
}) })
}) })

View File

@ -148,7 +148,6 @@ export default class CategoryImage extends PureComponent<{ category: string }> {
style={{ style={{
backgroundImage: `url(${image})` backgroundImage: `url(${image})`
}} }}
{...this.props}
/> />
) )
} }

View File

@ -0,0 +1,29 @@
import React from 'react'
import { render } from 'react-testing-library'
import Form from './Form'
describe('Form', () => {
it('renders without crashing', () => {
const { container } = render(<Form>Hello</Form>)
expect(container.firstChild).toBeInTheDocument()
})
it('renders title & description when set', () => {
const { container } = render(
<Form title="Hello Title" description="Hello Description">
Hello
</Form>
)
expect(container.querySelector('.formTitle')).toHaveTextContent(
'Hello Title'
)
expect(container.querySelector('.formDescription')).toHaveTextContent(
'Hello Description'
)
})
it('can switch to minimal', () => {
const { container } = render(<Form minimal>Hello</Form>)
expect(container.firstChild).toHaveClass('formMinimal')
})
})

View File

@ -0,0 +1,90 @@
import React from 'react'
import { render } from 'react-testing-library'
import Input from './Input'
describe('Input', () => {
it('renders default without crashing', () => {
const { container } = render(<Input name="my-input" label="My Input" />)
expect(container.firstChild).toBeInTheDocument()
expect(container.querySelector('.label')).toHaveTextContent('My Input')
expect(container.querySelector('.input')).toHaveAttribute(
'id',
'my-input'
)
})
it('renders as text input by default', () => {
const { container } = render(<Input name="my-input" label="My Input" />)
expect(container.querySelector('.input')).toHaveAttribute(
'type',
'text'
)
})
it('renders search', () => {
const { container } = render(
<Input name="my-input" label="My Input" type="search" />
)
expect(container.querySelector('.input')).toHaveAttribute(
'type',
'search'
)
expect(container.querySelector('label + div')).toHaveClass(
'inputWrapSearch'
)
})
it('renders select', () => {
const { container } = render(
<Input
name="my-input"
label="My Input"
type="select"
options={['hello', 'hello2']}
/>
)
expect(container.querySelector('select')).toBeInTheDocument()
})
it('renders textarea', () => {
const { container } = render(
<Input name="my-input" label="My Input" type="textarea" rows={40} />
)
expect(container.querySelector('textarea')).toBeInTheDocument()
})
it('renders radios', () => {
const { container } = render(
<Input
name="my-input"
label="My Input"
type="radio"
options={['hello', 'hello2']}
/>
)
expect(container.querySelector('input[type=radio]')).toBeInTheDocument()
})
it('renders checkboxes', () => {
const { container } = render(
<Input
name="my-input"
label="My Input"
type="checkbox"
options={['hello', 'hello2']}
/>
)
expect(
container.querySelector('input[type=checkbox]')
).toBeInTheDocument()
})
it('renders date picker', () => {
const { container } = render(
<Input name="my-input" label="My Input" type="date" />
)
expect(
container.querySelector('.react-datepicker-wrapper')
).toBeInTheDocument()
})
})

View File

@ -60,9 +60,8 @@ export default class Input extends PureComponent<InputProps, InputState> {
} }
private handleDateChange = (date: Date) => { private handleDateChange = (date: Date) => {
this.setState({ this.setState({ dateCreated: date })
dateCreated: date
})
const event = { const event = {
currentTarget: { currentTarget: {
name: 'dateCreated', name: 'dateCreated',
@ -80,7 +79,8 @@ export default class Input extends PureComponent<InputProps, InputState> {
name, name,
required, required,
onChange, onChange,
value value,
rows
} = this.props } = this.props
const wrapClass = this.inputWrapClasses() const wrapClass = this.inputWrapClasses()
@ -119,7 +119,7 @@ export default class Input extends PureComponent<InputProps, InputState> {
className={styles.input} className={styles.input}
onFocus={this.toggleFocus} onFocus={this.toggleFocus}
onBlur={this.toggleFocus} onBlur={this.toggleFocus}
{...this.props} rows={rows}
/> />
</div> </div>
) )
@ -174,6 +174,7 @@ export default class Input extends PureComponent<InputProps, InputState> {
<InputGroup> <InputGroup>
<input <input
id={name} id={name}
type={type || 'text'}
className={styles.input} className={styles.input}
onFocus={this.toggleFocus} onFocus={this.toggleFocus}
onBlur={this.toggleFocus} onBlur={this.toggleFocus}
@ -184,6 +185,7 @@ export default class Input extends PureComponent<InputProps, InputState> {
) : ( ) : (
<input <input
id={name} id={name}
type={type || 'text'}
className={styles.input} className={styles.input}
onFocus={this.toggleFocus} onFocus={this.toggleFocus}
onBlur={this.toggleFocus} onBlur={this.toggleFocus}

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import InputGroup from './InputGroup'
describe('InputGroup', () => {
it('renders without crashing', () => {
const { container } = render(<InputGroup>Hello</InputGroup>)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -0,0 +1,20 @@
import React from 'react'
import { render } from 'react-testing-library'
import Label from './Label'
describe('Label', () => {
it('renders without crashing', () => {
const { container } = render(<Label htmlFor="hello">Hello</Label>)
expect(container.firstChild).toBeInTheDocument()
})
it('renders required state', () => {
const { container } = render(
<Label required htmlFor="hello">
Hello
</Label>
)
expect(container.firstChild).toHaveAttribute('title', 'Required')
expect(container.firstChild).toHaveClass('required')
})
})

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import Row from './Row'
describe('Row', () => {
it('renders without crashing', () => {
const { container } = render(<Row>Hello</Row>)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import Markdown from './Markdown'
describe('Markdown', () => {
it('renders without crashing', () => {
const { container } = render(<Markdown text={'#hello'} />)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -1,7 +1,7 @@
import React from 'react' import React from 'react'
import ReactMarkdown from 'react-markdown' import ReactMarkdown from 'react-markdown'
const Description = ({ const Markdown = ({
text, text,
className className
}: { }: {
@ -15,4 +15,4 @@ const Description = ({
return <ReactMarkdown source={textCleaned} className={className} /> return <ReactMarkdown source={textCleaned} className={className} />
} }
export default Description export default Markdown

View File

@ -0,0 +1,49 @@
import React from 'react'
import { render } from 'react-testing-library'
import Popover from './Popover'
import { userMock, userMockConnected } from '../../../../__mocks__/user-mock'
import { User } from '../../../context'
describe('Popover', () => {
it('renders without crashing', () => {
const { container } = render(
<User.Provider value={userMock}>
<Popover forwardedRef={() => null} style={{}} />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders connected without crashing', () => {
const { container } = render(
<User.Provider value={userMockConnected}>
<Popover forwardedRef={() => null} style={{}} />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders correct network', () => {
const { container } = render(
<User.Provider value={{ ...userMockConnected, network: 'Nile' }}>
<Popover forwardedRef={() => null} style={{}} />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveTextContent('Connected to Nile')
})
it('renders with wrong network', () => {
const { container } = render(
<User.Provider
value={{ ...userMockConnected, isNile: false, network: '1' }}
>
<Popover forwardedRef={() => null} style={{}} />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
expect(container.firstChild).toHaveTextContent(
'Please connect to Custom RPC'
)
})
})

View File

@ -9,6 +9,7 @@ export default class Popover extends PureComponent<{
}> { }> {
public render() { public render() {
const { account, balance, network, isWeb3, isNile } = this.context const { account, balance, network, isWeb3, isNile } = this.context
return ( return (
<div <div
className={styles.popover} className={styles.popover}

View File

@ -0,0 +1,20 @@
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import AccountStatus from '.'
describe('AccountStatus', () => {
it('renders without crashing', () => {
const { container } = render(<AccountStatus />)
expect(container.firstChild).toBeInTheDocument()
})
it('togglePopover fires', () => {
const { container } = render(<AccountStatus />)
const indicator = container.querySelector('.statusIndicator')
indicator && fireEvent.mouseOver(indicator)
expect(container.querySelector('.popover')).toBeInTheDocument()
indicator && fireEvent.mouseOut(indicator)
})
})

View File

@ -19,7 +19,7 @@ export default class AccountStatus extends PureComponent<
isPopoverOpen: false isPopoverOpen: false
} }
public togglePopover() { private togglePopover() {
this.setState(prevState => ({ this.setState(prevState => ({
isPopoverOpen: !prevState.isPopoverOpen isPopoverOpen: !prevState.isPopoverOpen
})) }))

View File

@ -2,7 +2,7 @@ import React from 'react'
import { render } from 'react-testing-library' import { render } from 'react-testing-library'
import Pagination from './Pagination' import Pagination from './Pagination'
describe('Button', () => { describe('Pagination', () => {
it('renders without crashing', () => { it('renders without crashing', () => {
const { container } = render( const { container } = render(
<Pagination <Pagination

View File

@ -8,25 +8,19 @@ import styles from './Header.module.scss'
import menu from '../../data/menu.json' import menu from '../../data/menu.json'
import meta from '../../data/meta.json' import meta from '../../data/meta.json'
const MenuItem = ({ item, isWeb3 }: { item: any; isWeb3: boolean }) => { const MenuItem = ({ item }: { item: any }) => (
if (item.web3 && !isWeb3) return null <NavLink
to={item.link}
return ( className={styles.link}
<NavLink activeClassName={styles.linkActive}
to={item.link} exact
className={styles.link} >
activeClassName={styles.linkActive} {item.title}
exact </NavLink>
> )
{item.title}
</NavLink>
)
}
export default class Header extends PureComponent { export default class Header extends PureComponent {
public render() { public render() {
const { isWeb3 } = this.context
return ( return (
<header className={styles.header}> <header className={styles.header}>
<div className={styles.headerContent}> <div className={styles.headerContent}>
@ -37,11 +31,7 @@ export default class Header extends PureComponent {
<nav className={styles.headerMenu}> <nav className={styles.headerMenu}>
{menu.map(item => ( {menu.map(item => (
<MenuItem <MenuItem key={item.title} item={item} />
key={item.title}
item={item}
isWeb3={isWeb3}
/>
))} ))}
<AccountStatus className={styles.accountStatus} /> <AccountStatus className={styles.accountStatus} />
</nav> </nav>

View File

@ -1,11 +1,62 @@
import React from 'react' import React from 'react'
import { render } from 'react-testing-library' import { render, fireEvent } from 'react-testing-library'
import Web3message from './Web3message' import Web3message from './Web3message'
import { User } from '../../context'
import { userMock, userMockConnected } from '../../../__mocks__/user-mock'
describe('Web3message', () => { describe('Web3message', () => {
it('default renders without crashing', () => { it('renders with noWeb3 message', () => {
const { container } = render(<Web3message />) const { container } = render(
<User.Provider value={{ ...userMock }}>
<Web3message />
</User.Provider>
)
expect(container.firstChild).toHaveTextContent('Not a Web3 Browser')
})
expect(container.firstChild).toBeInTheDocument() it('renders with wrongNetwork message', () => {
const { container } = render(
<User.Provider value={{ ...userMock, isWeb3: true }}>
<Web3message />
</User.Provider>
)
expect(container.firstChild).toHaveTextContent(
'Not connected to Nile network'
)
})
it('renders with noAccount message', () => {
const { container } = render(
<User.Provider value={{ ...userMock, isWeb3: true, isNile: true }}>
<Web3message />
</User.Provider>
)
expect(container.firstChild).toHaveTextContent('No accounts detected')
})
it('renders with hasAccount message', () => {
const { container } = render(
<User.Provider value={userMockConnected}>
<Web3message />
</User.Provider>
)
expect(container.firstChild).toHaveTextContent('0xxxxxx')
})
it('button click fires unlockAccounts', () => {
const { getByText } = render(
<User.Provider
value={{
...userMock,
isWeb3: true,
isNile: true
}}
>
<Web3message />
</User.Provider>
)
fireEvent.click(getByText('Unlock Account'))
expect(userMock.unlockAccounts).toBeCalled()
}) })
}) })

View File

@ -0,0 +1,24 @@
import React from 'react'
import { render } from 'react-testing-library'
import Route from './Route'
describe('Route', () => {
it('renders without crashing', () => {
const { container } = render(<Route title="Hello Title">Hello</Route>)
expect(container.firstChild).toBeInTheDocument()
})
it('renders title & description', () => {
const { container } = render(
<Route title="Hello Title" description="Hello Description">
Hello
</Route>
)
expect(container.querySelector('.title')).toHaveTextContent(
'Hello Title'
)
expect(container.querySelector('.description')).toHaveTextContent(
'Hello Description'
)
})
})

View File

@ -1,6 +1,6 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import Web3 from 'web3' import Web3 from 'web3'
import { Logger } from '@oceanprotocol/squid' import { Logger, Ocean, Account } from '@oceanprotocol/squid'
import { User } from '.' import { User } from '.'
import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean' import { provideOcean, requestFromFaucet, FaucetResponse } from '../ocean'
import { nodeHost, nodePort, nodeScheme } from '../config' import { nodeHost, nodePort, nodeScheme } from '../config'
@ -54,7 +54,7 @@ interface UserProviderState {
} }
network: string network: string
web3: Web3 web3: Web3
ocean: any ocean: Ocean
requestFromFaucet(account: string): Promise<FaucetResponse> requestFromFaucet(account: string): Promise<FaucetResponse>
unlockAccounts(): Promise<any> unlockAccounts(): Promise<any>
message: string message: string
@ -117,7 +117,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
} }
} }
private getWeb3 = async () => { private getWeb3 = () => {
// Modern dapp browsers // Modern dapp browsers
if (window.ethereum) { if (window.ethereum) {
window.web3 = new Web3(window.ethereum) window.web3 = new Web3(window.ethereum)
@ -236,7 +236,7 @@ export default class UserProvider extends PureComponent<{}, UserProviderState> {
} }
} }
private fetchBalance = async (account: any) => { private fetchBalance = async (account: Account) => {
const balance = await account.getBalance() const balance = await account.getBalance()
const { eth, ocn } = balance const { eth, ocn } = balance
if (eth !== this.state.balance.eth || ocn !== this.state.balance.ocn) { if (eth !== this.state.balance.eth || ocn !== this.state.balance.ocn) {

View File

@ -1,6 +1,6 @@
{ {
"noweb3": "Not a Web3 Browser. For publishing and downloading an asset you need to <a href='https://docs.oceanprotocol.com/tutorials/metamask-setup/' target='_blank' rel='noopener noreferrer'>setup MetaMask</a> or use any other Web3-capable plugin or browser.", "noweb3": "Not a Web3 Browser. For publishing and downloading an asset you need to <a href='https://docs.oceanprotocol.com/tutorials/metamask-setup/' target='_blank' rel='noopener noreferrer'>setup MetaMask</a> or use any other Web3-capable plugin or browser.",
"noAccount": "No accounts detected. For publishing and downloading an asset you need to unlock your Web3 account.", "noAccount": "No accounts detected. For publishing and downloading an asset you need to unlock your Web3 account.",
"hasAccount": "Connected with account ", "hasAccount": "",
"wrongNetwork": "Not connected to Nile network.<br />Please connect in MetaMask with Custom RPC <code>https://nile.dev-ocean.com</code>" "wrongNetwork": "Not connected to Nile network.<br />Please connect in MetaMask with Custom RPC <code>https://nile.dev-ocean.com</code>"
} }

View File

@ -8,7 +8,7 @@ const withTracker = <P extends RouteComponentProps>(
options: FieldsObject = {} options: FieldsObject = {}
) => { ) => {
ReactGA.initialize(analyticsId, { ReactGA.initialize(analyticsId, {
testMode: process.env.NODE_ENV === 'development', testMode: process.env.NODE_ENV === 'test',
debug: false debug: false
}) })

22
client/src/index.test.tsx Normal file
View File

@ -0,0 +1,22 @@
import ReactDOM from 'react-dom'
import { renderToDOM } from './index'
describe('test ReactDOM.render', () => {
const originalRender = ReactDOM.render
const originalGetElement = global.document.getElementById
beforeEach(() => {
global.document.getElementById = () => true
ReactDOM.render = jest.fn()
})
afterAll(() => {
global.document.getElementById = originalGetElement
ReactDOM.render = originalRender
})
it('should call ReactDOM.render', () => {
renderToDOM()
expect(ReactDOM.render).toHaveBeenCalled()
})
})

View File

@ -1,9 +1,25 @@
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import UserProvider from './context/UserProvider'
import App from './App' import App from './App'
import * as serviceWorker from './serviceWorker' import * as serviceWorker from './serviceWorker'
ReactDOM.render(<App />, document.getElementById('root')) function renderToDOM() {
const root = document.getElementById('root')
if (root !== null) {
ReactDOM.render(
<UserProvider>
<App />
</UserProvider>,
root
)
}
}
export { renderToDOM }
renderToDOM()
// If you want your app to work offline and load faster, you can change // If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls. // unregister() to register() below. Note this comes with some pitfalls.

17
client/src/ocean.test.ts Normal file
View File

@ -0,0 +1,17 @@
import Web3 from 'web3'
import { provideOcean, requestFromFaucet } from './ocean'
describe('ocean', () => {
const web3 = new Web3(Web3.givenProvider)
it('provideOcean can be called', async () => {
const response = await provideOcean(web3)
expect(response.ocean).toBeTruthy()
})
it('requestFromFaucet can be called', async () => {
const response = await requestFromFaucet('0xxxxxx')
response &&
expect(response.errors[0].msg).toBe('Invalid Ethereum address')
})
})

View File

@ -72,6 +72,6 @@ export async function requestFromFaucet(account: string) {
}) })
return response.json() return response.json()
} catch (error) { } catch (error) {
Logger.log('requestFromFaucet', error) Logger.error('requestFromFaucet', error)
} }
} }

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import About from './About'
describe('About', () => {
it('renders without crashing', () => {
const { container } = render(<About />)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -0,0 +1,68 @@
import React from 'react'
import { render } from 'react-testing-library'
import { DDO, MetaData } from '@oceanprotocol/squid'
import { BrowserRouter as Router } from 'react-router-dom'
import AssetDetails, { datafilesLine } from './AssetDetails'
/* eslint-disable @typescript-eslint/no-explicit-any */
describe('AssetDetails', () => {
it('renders loading without crashing', () => {
const { container } = render(
<AssetDetails
metadata={({ base: { name: '' } } as any) as MetaData}
ddo={({} as any) as DDO}
/>
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders with data', () => {
const { container } = render(
<Router>
<AssetDetails
metadata={
({
base: {
name: 'Hello',
description: 'Description',
categories: ['Category'],
files: [{ index: 0 }]
}
} as any) as MetaData
}
ddo={({} as any) as DDO}
/>
</Router>
)
expect(container.querySelector('.description')).toHaveTextContent(
'Description'
)
expect(container.firstChild).toHaveTextContent('Category')
})
it('datafilesLine renders correctly for one file', () => {
const files = [
{
index: 0,
url: 'https://hello.com'
}
]
const { container } = render(datafilesLine(files))
expect(container.firstChild).toHaveTextContent('1 data file')
})
it('datafilesLine renders correctly for multiple files', () => {
const files = [
{
index: 0,
url: 'https://hello.com'
},
{
index: 1,
url: 'https://hello2.com'
}
]
const { container } = render(datafilesLine(files))
expect(container.firstChild).toHaveTextContent('2 data files')
})
})

View File

@ -1,23 +1,24 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import Moment from 'react-moment' import Moment from 'react-moment'
import { DDO, MetaData, File } from '@oceanprotocol/squid'
import Markdown from '../../components/atoms/Markdown' import Markdown from '../../components/atoms/Markdown'
import styles from './AssetDetails.module.scss' import styles from './AssetDetails.module.scss'
import AssetFilesDetails from './AssetFilesDetails' import AssetFilesDetails from './AssetFilesDetails'
interface AssetDetailsProps { interface AssetDetailsProps {
metadata: any metadata: MetaData
ddo: any ddo: DDO
}
export function datafilesLine(files: File[]) {
if (files.length === 1) {
return <span>{files.length} data file</span>
}
return <span>{files.length} data files</span>
} }
export default class AssetDetails extends PureComponent<AssetDetailsProps> { export default class AssetDetails extends PureComponent<AssetDetailsProps> {
private datafilesLine = (files: any) => {
if (files.length === 1) {
return <span>{files.length} data file</span>
}
return <span>{files.length} data files</span>
}
public render() { public render() {
const { metadata, ddo } = this.props const { metadata, ddo } = this.props
const { base } = metadata const { base } = metadata
@ -51,14 +52,16 @@ export default class AssetDetails extends PureComponent<AssetDetailsProps> {
</Link> </Link>
)} )}
{base.files && this.datafilesLine(base.files)} {base.files && datafilesLine(base.files)}
</div> </div>
</aside> </aside>
<Markdown {base.description && (
text={base.description} <Markdown
className={styles.description} text={base.description}
/> className={styles.description}
/>
)}
<ul className={styles.meta}> <ul className={styles.meta}>
<li> <li>

View File

@ -0,0 +1,77 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import { DDO } from '@oceanprotocol/squid'
import { StateMock } from '@react-mock/state'
import { User } from '../../context'
import AssetFile from './AssetFile'
const file = {
index: 0,
url: 'https://hello.com',
contentType: 'zip',
contentLength: 100
}
const ddo = ({ id: 'xxx' } as any) as DDO
const contextConnectedMock = {
isLogged: true,
isLoading: false,
isWeb3: true,
isNile: true,
account: '',
web3: {},
ocean: {},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: () => {},
unlockAccounts: () => {},
message: ''
}
describe('AssetFile', () => {
it('renders without crashing', () => {
const { container } = render(<AssetFile file={file} ddo={ddo} />)
expect(container.firstChild).toBeInTheDocument()
})
it('button to be disabled when not connected', () => {
const { container } = render(<AssetFile file={file} ddo={ddo} />)
expect(container.querySelector('button')).toHaveAttribute('disabled')
})
it('button to be enabled when connected', async () => {
const { getByText } = render(
<User.Provider value={contextConnectedMock}>
<AssetFile file={file} ddo={ddo} />
</User.Provider>
)
const button = getByText('Get file')
expect(button).not.toHaveAttribute('disabled')
fireEvent.click(button)
})
it('renders loading state', async () => {
const { container } = render(
<StateMock state={{ isLoading: true }}>
<AssetFile file={file} ddo={ddo} />
</StateMock>
)
expect(container.querySelector('.spinner')).toBeInTheDocument()
})
it('renders error', async () => {
const { container } = render(
<StateMock state={{ error: 'Hello Error' }}>
<AssetFile file={file} ddo={ddo} />
</StateMock>
)
expect(container.querySelector('.error')).toBeInTheDocument()
expect(container.querySelector('.error')).toHaveTextContent(
'Hello Error'
)
})
})

View File

@ -1,5 +1,5 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { Logger } from '@oceanprotocol/squid' import { Logger, DDO, File } from '@oceanprotocol/squid'
import filesize from 'filesize' import filesize from 'filesize'
import Button from '../../components/atoms/Button' import Button from '../../components/atoms/Button'
import Spinner from '../../components/atoms/Spinner' import Spinner from '../../components/atoms/Spinner'
@ -8,8 +8,8 @@ import styles from './AssetFile.module.scss'
import ReactGA from 'react-ga' import ReactGA from 'react-ga'
interface AssetFileProps { interface AssetFileProps {
file: any file: File
ddo: any ddo: DDO
} }
interface AssetFileState { interface AssetFileState {
@ -30,7 +30,7 @@ export default class AssetFile extends PureComponent<
private resetState = () => this.setState({ isLoading: true, error: '' }) private resetState = () => this.setState({ isLoading: true, error: '' })
private purchaseAsset = async (ddo: any, index: number) => { private purchaseAsset = async (ddo: DDO, index: number) => {
this.resetState() this.resetState()
ReactGA.event({ ReactGA.event({
@ -77,6 +77,7 @@ export default class AssetFile extends PureComponent<
const { ddo, file } = this.props const { ddo, file } = this.props
const { isLoading, message, error } = this.state const { isLoading, message, error } = this.state
const { isLogged, isNile } = this.context const { isLogged, isNile } = this.context
const { index } = file
return ( return (
<div className={styles.fileWrap}> <div className={styles.fileWrap}>
@ -97,7 +98,7 @@ export default class AssetFile extends PureComponent<
<Button <Button
primary primary
className={styles.buttonMain} className={styles.buttonMain}
onClick={() => this.purchaseAsset(ddo, file.index)} onClick={() => index && this.purchaseAsset(ddo, index)}
disabled={!isLogged || !isNile} disabled={!isLogged || !isNile}
> >
Get file Get file

View File

@ -0,0 +1,43 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React from 'react'
import { render } from 'react-testing-library'
import { DDO } from '@oceanprotocol/squid'
import AssetFilesDetails from './AssetFilesDetails'
import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock'
describe('AssetFilesDetails', () => {
it('renders without crashing', () => {
const files = [
{
index: 0,
url: 'https://hello.com'
}
]
const { container } = render(
<AssetFilesDetails files={files} ddo={({} as any) as DDO} />
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders nothing when no files', () => {
const { container } = render(
<AssetFilesDetails files={[]} ddo={({} as any) as DDO} />
)
expect(container.firstChild).toHaveTextContent('No files attached.')
})
it('hides Web3message when all connected', () => {
const { container } = render(
<User.Provider value={userMockConnected}>
<AssetFilesDetails
files={[{ index: 0, url: '' }]}
ddo={({} as any) as DDO}
/>
</User.Provider>
)
expect(container.querySelector('.status')).not.toBeInTheDocument()
})
})

View File

@ -1,31 +1,32 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import { DDO, File } from '@oceanprotocol/squid'
import AssetFile from './AssetFile' import AssetFile from './AssetFile'
import { User } from '../../context' import { User } from '../../context'
import Web3message from '../../components/organisms/Web3message' import Web3message from '../../components/organisms/Web3message'
import styles from './AssetFilesDetails.module.scss' import styles from './AssetFilesDetails.module.scss'
export default class AssetFilesDetails extends PureComponent<{ export default class AssetFilesDetails extends PureComponent<{
files: any[] files: File[]
ddo: any ddo: DDO
}> { }> {
public render() { public render() {
const { files, ddo } = this.props const { files, ddo } = this.props
return files ? ( return files.length ? (
<> <>
<div className={styles.files}> <div className={styles.files}>
{files.map(file => ( {files.map(file => (
<AssetFile key={file.index} ddo={ddo} file={file} /> <AssetFile key={file.index} ddo={ddo} file={file} />
))} ))}
</div> </div>
<User.Consumer> {(!this.context.isNile || !this.context.isLogged) && (
{states => <Web3message />
(!states.isNile || !states.isLogged) && <Web3message /> )}
}
</User.Consumer>
</> </>
) : ( ) : (
<div>No files attached.</div> <div>No files attached.</div>
) )
} }
} }
AssetFilesDetails.contextType = User

View File

@ -0,0 +1,21 @@
import React from 'react'
import { render } from 'react-testing-library'
import Details from './index'
describe('Details', () => {
it('renders loading state by default', () => {
const { container } = render(
<Details
location={{
search: '',
pathname: '/',
state: '',
hash: ''
}}
match={{ params: { did: '' } }}
/>
)
expect(container.firstChild).toBeInTheDocument()
expect(container.querySelector('.loader')).toBeInTheDocument()
})
})

View File

@ -1,4 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { DDO, MetaData, Logger } from '@oceanprotocol/squid'
import Route from '../../components/templates/Route' import Route from '../../components/templates/Route'
import Spinner from '../../components/atoms/Spinner' import Spinner from '../../components/atoms/Spinner'
import { User } from '../../context' import { User } from '../../context'
@ -7,23 +8,37 @@ import stylesApp from '../../App.module.scss'
interface DetailsProps { interface DetailsProps {
location: Location location: Location
match: any match: {
params: {
did: string
}
}
} }
interface DetailsState { interface DetailsState {
ddo: any ddo: DDO
metadata: { base: { name: string } } metadata: MetaData
} }
export default class Details extends Component<DetailsProps, DetailsState> { export default class Details extends Component<DetailsProps, DetailsState> {
public state = { ddo: {}, metadata: { base: { name: '' } } } public state = {
ddo: ({} as any) as DDO,
metadata: ({ base: { name: '' } } as any) as MetaData
}
public async componentDidMount() { public async componentDidMount() {
const ddo = await this.context.ocean.assets.resolve( this.getData()
this.props.match.params.did }
)
const { metadata } = ddo.findServiceByType('Metadata') private async getData() {
this.setState({ ddo, metadata: { base: metadata.base } }) try {
const { ocean } = this.context
const ddo = await ocean.assets.resolve(this.props.match.params.did)
const { metadata } = ddo.findServiceByType('Metadata')
this.setState({ ddo, metadata })
} catch (error) {
Logger.error(error.message)
}
} }
public render() { public render() {

View File

@ -0,0 +1,43 @@
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import Faucet from './Faucet'
import { User } from '../context'
import { userMockConnected } from '../../__mocks__/user-mock'
const setup = () => {
const utils = render(
<User.Provider value={userMockConnected}>
<Faucet />
</User.Provider>
)
const button = utils.getByText('Request Ether')
const { container } = utils
return {
button,
container,
...utils
}
}
describe('Faucet', () => {
it('renders without crashing', () => {
const { container } = render(<Faucet />)
expect(container.firstChild).toBeInTheDocument()
})
it('shows actions when connected', () => {
const { button } = setup()
expect(button).toBeInTheDocument()
expect(button).not.toHaveAttribute('disabled')
})
it('fires requestFromFaucet', () => {
const { button, getByText } = setup()
fireEvent.click(button)
expect(userMockConnected.requestFromFaucet).toHaveBeenCalledTimes(1)
// check for spinner
expect(getByText('Getting Ether...')).toBeInTheDocument()
})
})

View File

@ -46,7 +46,7 @@ export default class Faucet extends PureComponent<{}, FaucetState> {
trxHash trxHash
}) })
} catch (error) { } catch (error) {
this.setState({ isLoading: false, error }) this.setState({ isLoading: false, error: error.message })
} }
} }

View File

@ -0,0 +1,38 @@
import React from 'react'
import { render } from 'react-testing-library'
import { User } from '../context'
import History from './History'
describe('History', () => {
it('renders without crashing', () => {
const { container } = render(<History />)
expect(container.firstChild).toBeInTheDocument()
})
it('outputs Web3 message when no Web3 detected', () => {
const context = {
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
account: '',
web3: {},
ocean: {},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: () => {},
unlockAccounts: () => {},
message: ''
}
const { container } = render(
<User.Provider value={context}>
<History />
</User.Provider>
)
expect(container.querySelector('.message')).toBeInTheDocument()
expect(container.querySelector('.message')).toHaveTextContent(
'Not a Web3 Browser.'
)
})
})

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import Home from './Home'
describe('Home', () => {
it('renders without crashing', () => {
const { container } = render(<Home history={''} />)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -7,9 +7,10 @@ import AssetsUser from '../components/organisms/AssetsUser'
import styles from './Home.module.scss' import styles from './Home.module.scss'
import meta from '../data/meta.json' import meta from '../data/meta.json'
import { History } from 'history'
interface HomeProps { interface HomeProps {
history: any history: History
} }
interface HomeState { interface HomeState {

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import NotFound from './NotFound'
describe('NotFound', () => {
it('renders without crashing', () => {
const { container } = render(<NotFound />)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -0,0 +1,39 @@
import React from 'react'
import { render } from 'react-testing-library'
import Item from './Item'
describe('Item', () => {
it('renders without crashing', () => {
const item = {
url: 'https://hello.com/hello.zip',
found: true,
contentType: 'application/zip',
contentLength: 10
}
const { container } = render(
<Item item={item} removeItem={() => null} />
)
expect(container.firstChild).toBeInTheDocument()
})
it('returns unknown strings', () => {
const item = {
url: 'https://hello.com/hello.zip',
found: false,
contentType: '',
contentLength: 10
}
const { container } = render(
<Item item={item} removeItem={() => null} />
)
expect(container.querySelector('.details')).toHaveTextContent(
'unknown type'
)
expect(container.querySelector('.details')).toHaveTextContent(
'unknown size'
)
expect(container.querySelector('.details')).toHaveTextContent(
'not confirmed'
)
})
})

View File

@ -0,0 +1,63 @@
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import ItemForm from './ItemForm'
const addItem = jest.fn()
const setup = () => {
const utils = render(<ItemForm placeholder={'Hello'} addItem={addItem} />)
const input = utils.getByPlaceholderText('Hello')
const button = utils.getByText('Add File')
const { container } = utils
return {
input,
button,
container,
...utils
}
}
describe('ItemForm', () => {
it('renders without crashing', () => {
const { container } = setup()
expect(container.firstChild).toBeInTheDocument()
})
it('fires addItem', async () => {
const { input, button } = setup()
fireEvent.change(input, {
target: { value: 'https://hello.com' }
})
fireEvent.click(button)
expect(addItem).toHaveBeenCalled()
})
it('does not fire addItem when no url present', () => {
const { input, button, container } = setup()
// empty url
fireEvent.change(input, {
target: { value: '' }
})
fireEvent.click(button)
expect(container.querySelector('.error')).toHaveTextContent(
'Please fill in all required fields.'
)
// invalid url
fireEvent.change(input, {
target: { value: 'blabla' }
})
fireEvent.click(button)
expect(container.querySelector('.error')).toHaveTextContent(
'Please enter a valid URL.'
)
// clear out errors
fireEvent.change(input, {
target: { value: 'blablabla' }
})
expect(container.querySelector('.error')).not.toBeInTheDocument()
})
})

View File

@ -25,7 +25,7 @@ export default class ItemForm extends PureComponent<
noUrl: false noUrl: false
} }
public handleSubmit = (e: Event) => { private handleSubmit = (e: Event) => {
e.preventDefault() e.preventDefault()
const { url } = this.state const { url } = this.state
@ -45,14 +45,14 @@ export default class ItemForm extends PureComponent<
this.props.addItem(url) this.props.addItem(url)
} }
public onChangeUrl = (e: React.FormEvent<HTMLInputElement>) => { private onChangeUrl = (e: React.FormEvent<HTMLInputElement>) => {
this.setState({ url: e.currentTarget.value }) this.setState({ url: e.currentTarget.value })
this.clearErrors() this.clearErrors()
} }
public clearErrors() { private clearErrors() {
if (this.state.hasError) this.setState({ hasError: false }) if (this.state.hasError) this.setState({ hasError: false })
if (this.state.noUrl) this.setState({ noUrl: true }) if (this.state.noUrl) this.setState({ noUrl: false })
} }
public render() { public render() {

View File

@ -0,0 +1,90 @@
import React from 'react'
import { render, fireEvent, waitForElement } from 'react-testing-library'
import Files, { getFileCompression } from '.'
const onChange = jest.fn()
const files = [
{
found: true,
url: 'https://hello.com',
checksum: 'cccccc',
checksumType: 'MD5',
contentLength: 100,
contentType: 'application/zip',
resourceId: 'xxx',
encoding: 'UTF-8',
compression: 'zip'
}
]
const setup = () => {
const utils = render(
<Files
files={files}
placeholder={'Hello'}
name={'Hello'}
onChange={onChange}
/>
)
const { container } = utils
return { container, ...utils }
}
describe('Files', () => {
it('renders without crashing', () => {
const { container } = setup()
expect(container.firstChild).toBeInTheDocument()
expect(container.querySelector('.itemForm')).not.toBeInTheDocument()
})
it('new file form can be opened and closed', async () => {
const { container, getByText } = setup()
// open
fireEvent.click(getByText('+ Add a file'))
await waitForElement(() => getByText('- Cancel'))
expect(container.querySelector('.itemForm')).toBeInTheDocument()
// close
fireEvent.click(getByText('- Cancel'))
await waitForElement(() => getByText('+ Add a file'))
expect(container.querySelector('.grow-exit')).toBeInTheDocument()
})
it('item can be removed', async () => {
const { getByTitle } = setup()
fireEvent.click(getByTitle('Remove item'))
expect(files.length).toBe(0)
})
it('item can be added', async () => {
const { getByText, getByPlaceholderText } = setup()
fireEvent.click(getByText('+ Add a file'))
await waitForElement(() => getByText('- Cancel'))
fireEvent.change(getByPlaceholderText('Hello'), {
target: { value: 'https://hello.com' }
})
fireEvent.click(getByText('Add File'))
})
})
describe('getFileCompression', () => {
it('outputs known compression', async () => {
const compression = await getFileCompression('application/zip')
expect(compression).toBe('zip')
})
it('outputs known x- compression', async () => {
const compression = await getFileCompression('application/x-gtar')
expect(compression).toBe('gtar')
})
it('outputs unknown compression', async () => {
const compression = await getFileCompression('blabla')
expect(compression).toBe('none')
})
})

View File

@ -38,7 +38,7 @@ interface FilesStates {
isFormShown: boolean isFormShown: boolean
} }
const getFileCompression = async (contentType: string) => { export const getFileCompression = async (contentType: string) => {
// TODO: add all the possible archive & compression MIME types // TODO: add all the possible archive & compression MIME types
if ( if (
contentType === 'application/zip' || contentType === 'application/zip' ||
@ -69,14 +69,21 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
isFormShown: false isFormShown: false
} }
public toggleForm = (e: Event) => { private toggleForm = (e: Event) => {
e.preventDefault() e.preventDefault()
this.setState({ isFormShown: !this.state.isFormShown }) this.setState({ isFormShown: !this.state.isFormShown })
} }
public addItem = async (value: string) => { private addItem = async (value: string) => {
let res: any let res: {
result: {
contentLength: number
contentType: string
found: boolean
}
}
let file: File = { let file: File = {
url: value, url: value,
found: false, found: false,
@ -104,6 +111,7 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
} catch (error) { } catch (error) {
// error // error
} }
this.props.files.push(file) this.props.files.push(file)
const event = { const event = {
currentTarget: { currentTarget: {
@ -115,7 +123,7 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
this.setState({ isFormShown: !this.state.isFormShown }) this.setState({ isFormShown: !this.state.isFormShown })
} }
public removeItem = (index: number) => { private removeItem = (index: number) => {
this.props.files.splice(index, 1) this.props.files.splice(index, 1)
const event = { const event = {
currentTarget: { currentTarget: {

View File

@ -0,0 +1,19 @@
import React from 'react'
import { render } from 'react-testing-library'
import Progress from './Progress'
describe('Progress', () => {
it('renders without crashing', () => {
const { container } = render(
<Progress currentStep={1} steps={[{ title: '' }]} />
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders completed state', () => {
const { container } = render(
<Progress currentStep={2} steps={[{ title: '' }]} />
)
expect(container.querySelector('li')).toHaveClass('completed')
})
})

View File

@ -0,0 +1,46 @@
import React from 'react'
import { render } from 'react-testing-library'
import Step from './Step'
const stateMock = {
validationStatus: {
1: { allFieldsValid: true },
2: { allFieldsValid: true },
3: { allFieldsValid: true }
}
}
const propsMock = {
inputChange: () => null,
inputToArrayChange: () => null,
state: stateMock,
title: 'Hello',
description: 'description',
next: () => null,
prev: () => null,
tryAgain: () => null,
toStart: () => null
}
describe('Step', () => {
it('renders without crashing', () => {
const { container } = render(
<Step currentStep={1} index={0} totalSteps={3} {...propsMock} />
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders previous button one page bigger than 1', () => {
const { queryByText } = render(
<Step currentStep={2} index={1} totalSteps={3} {...propsMock} />
)
expect(queryByText('← Previous')).toBeInTheDocument()
})
it('does not render next button when on last step', () => {
const { queryByText } = render(
<Step currentStep={3} index={2} totalSteps={3} {...propsMock} />
)
expect(queryByText('Next →')).toBeNull()
})
})

View File

@ -0,0 +1,76 @@
import React from 'react'
import { render, fireEvent } from 'react-testing-library'
import { BrowserRouter as Router } from 'react-router-dom'
import StepRegisterContent from './StepRegisterContent'
const stateMock = {
publishedDid: '',
publishingError: '',
isPublishing: false,
isPublished: false
}
const propsMock = {
tryAgain: jest.fn(),
toStart: jest.fn(),
content: 'Hello'
}
describe('StepRegisterContent', () => {
it('renders without crashing', () => {
const { container } = render(
<Router>
<StepRegisterContent state={stateMock} {...propsMock} />
</Router>
)
expect(container.firstChild).toBeInTheDocument()
})
it('renders publishing state', () => {
const { container } = render(
<Router>
<StepRegisterContent
state={{ ...stateMock, isPublishing: true }}
{...propsMock}
/>
</Router>
)
expect(container.querySelector('.spinnerMessage')).toHaveTextContent(
'Please sign with your crypto wallet'
)
})
it('renders published state', () => {
const { container, getByText } = render(
<Router>
<StepRegisterContent
state={{ ...stateMock, isPublished: true }}
{...propsMock}
/>
</Router>
)
expect(container.querySelector('.success')).toHaveTextContent(
'Your asset is published!'
)
fireEvent.click(getByText('Publish another asset'))
expect(propsMock.toStart).toHaveBeenCalled()
})
it('renders error state', () => {
const { container, getByText } = render(
<Router>
<StepRegisterContent
state={{ ...stateMock, publishingError: 'Error!' }}
{...propsMock}
/>
</Router>
)
expect(
container.querySelector('.message:last-child')
).toHaveTextContent('Something went wrong')
fireEvent.click(getByText('try again'))
expect(propsMock.tryAgain).toHaveBeenCalled()
})
})

View File

@ -7,7 +7,12 @@ import styles from './StepRegisterContent.module.scss'
interface StepRegisterContentProps { interface StepRegisterContentProps {
tryAgain(): void tryAgain(): void
toStart(): void toStart(): void
state: any state: {
publishedDid: string
isPublishing: boolean
publishingError: string
isPublished: boolean
}
content?: string content?: string
} }

View File

@ -0,0 +1,11 @@
import React from 'react'
import { render } from 'react-testing-library'
import Publish from '.'
describe('Progress', () => {
it('renders without crashing', () => {
const { container, getByText } = render(<Publish />)
expect(container.firstChild).toBeInTheDocument()
expect(getByText('Next →')).toHaveAttribute('disabled')
})
})

View File

@ -0,0 +1,51 @@
import React from 'react'
import { render } from 'react-testing-library'
import Search from './Search'
import { User } from '../context'
import { createMemoryHistory } from 'history'
describe('Search', () => {
it('renders without crashing', () => {
const history = createMemoryHistory()
const { container } = render(
<User.Provider
value={{
isLogged: false,
isLoading: false,
isWeb3: false,
isNile: false,
account: '',
web3: {},
ocean: {
aquarius: {
queryMetadata: () => {
return {
results: [],
totalResults: 1,
totalPages: 1
}
}
}
},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: () => {},
unlockAccounts: () => {},
message: ''
}}
>
<Search
location={{
search: '?text=Hello&page=1',
pathname: '/search',
state: '',
hash: ''
}}
history={history}
/>
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})
})

View File

@ -1,5 +1,6 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import queryString from 'query-string' import queryString from 'query-string'
import { History, Location } from 'history'
import { Logger } from '@oceanprotocol/squid' import { Logger } from '@oceanprotocol/squid'
import Spinner from '../components/atoms/Spinner' import Spinner from '../components/atoms/Spinner'
import Route from '../components/templates/Route' import Route from '../components/templates/Route'
@ -10,7 +11,7 @@ import styles from './Search.module.scss'
interface SearchProps { interface SearchProps {
location: Location location: Location
history: any history: History
} }
interface SearchState { interface SearchState {
@ -53,6 +54,8 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
} }
private searchAssets = async () => { private searchAssets = async () => {
const { ocean } = this.context
const searchQuery = { const searchQuery = {
offset: this.state.offset, offset: this.state.offset,
page: this.state.currentPage, page: this.state.currentPage,
@ -65,16 +68,18 @@ export default class Search extends PureComponent<SearchProps, SearchState> {
} }
} }
const search = await this.context.ocean.aquarius.queryMetadata( try {
searchQuery const search = await ocean.aquarius.queryMetadata(searchQuery)
) this.setState({
this.setState({ results: search.results,
results: search.results, totalResults: search.totalResults,
totalResults: search.totalResults, totalPages: search.totalPages,
totalPages: search.totalPages, isLoading: false
isLoading: false })
}) } catch (error) {
Logger.log(`Loaded ${this.state.results.length} assets`) Logger.error(error)
this.setState({ isLoading: false })
}
} }
private handlePageClick = async (data: { selected: number }) => { private handlePageClick = async (data: { selected: number }) => {

View File

@ -0,0 +1,10 @@
import React from 'react'
import { render } from 'react-testing-library'
import Styleguide from './Styleguide'
describe('Styleguide', () => {
it('renders without crashing', () => {
const { container } = render(<Styleguide />)
expect(container.firstChild).toBeInTheDocument()
})
})

1688
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,16 +31,16 @@
"concurrently": "^4.1.0", "concurrently": "^4.1.0",
"eslint": "^5.16.0", "eslint": "^5.16.0",
"eslint-config-oceanprotocol": "^1.3.0", "eslint-config-oceanprotocol": "^1.3.0",
"eslint-config-prettier": "^4.1.0", "eslint-config-prettier": "^4.2.0",
"eslint-plugin-prettier": "^3.0.1", "eslint-plugin-prettier": "^3.0.1",
"prettier": "^1.16.4", "prettier": "^1.17.0",
"prettier-stylelint": "^0.4.2", "prettier-stylelint": "^0.4.2",
"release-it": "^10.4.3", "release-it": "^11.0.2",
"stylelint": "^10.0.1", "stylelint": "^10.0.1",
"stylelint-config-bigchaindb": "^1.2.1", "stylelint-config-bigchaindb": "^1.2.2",
"stylelint-config-css-modules": "^1.3.0", "stylelint-config-css-modules": "^1.4.0",
"stylelint-config-standard": "^18.2.0", "stylelint-config-standard": "^18.3.0",
"typescript": "^3.4.4" "typescript": "^3.4.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

1106
server/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,22 +14,17 @@
}, },
"dependencies": { "dependencies": {
"body-parser": "^1.18.3", "body-parser": "^1.18.3",
"color-js": "^1.0.5",
"compression": "^1.7.4", "compression": "^1.7.4",
"debug": "^4.1.1", "debug": "^4.1.1",
"express": "^4.16.4", "express": "^4.16.4",
"express-validator": "^5.3.1", "express-validator": "^5.3.1",
"lusca": "^1.6.1",
"morgan": "^1.9.1", "morgan": "^1.9.1",
"multer": "^1.4.1", "request": "^2.88.0"
"request": "^2.88.0",
"uuid": "^3.3.2"
}, },
"devDependencies": { "devDependencies": {
"@types/body-parser": "^1.17.0", "@types/body-parser": "^1.17.0",
"@types/compression": "0.0.36", "@types/compression": "0.0.36",
"@types/debug": "^4.1.4", "@types/debug": "^4.1.4",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.16.1", "@types/express": "^4.16.1",
"@types/jasmine": "^3.3.12", "@types/jasmine": "^3.3.12",
"@types/jest": "^24.0.11", "@types/jest": "^24.0.11",
@ -42,7 +37,7 @@
"supertest": "^4.0.2", "supertest": "^4.0.2",
"ts-jest": "^24.0.2", "ts-jest": "^24.0.2",
"ts-node": "^8.1.0", "ts-node": "^8.1.0",
"typescript": "^3.4.3" "typescript": "^3.4.5"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -1,4 +1,4 @@
import { Router, Request, Response, NextFunction } from 'express' import { Router, Request, Response } from 'express'
import request from 'request' import request from 'request'
export class UrlCheckRouter { export class UrlCheckRouter {
@ -11,7 +11,7 @@ export class UrlCheckRouter {
this.router = Router() this.router = Router()
} }
public checkUrl(req: Request, res: Response, next: NextFunction) { public checkUrl(req: Request, res: Response) {
if (!req.body.url) { if (!req.body.url) {
return res.send({ status: 'error', message: 'missing url' }) return res.send({ status: 'error', message: 'missing url' })
} }

View File

@ -49,6 +49,7 @@ app.use(morgan('dev'))
app.use(bodyParser.json()) app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.urlencoded({ extended: false }))
app.use(compression()) app.use(compression())
// routes // routes
app.use('/api/v1/urlcheck', UrlCheckRouter) app.use('/api/v1/urlcheck', UrlCheckRouter)

View File

@ -7,9 +7,21 @@ afterAll(done => {
}) })
describe('POST /api/v1/urlcheck', () => { describe('POST /api/v1/urlcheck', () => {
it('responds with json', function(done) { it('responds with json', async () => {
request(server) const response = await request(server).post('/api/v1/urlcheck')
.post('/api/v1/urlcheck') expect(response.statusCode).toBe(200)
.expect(200, done) })
it('responds with error message when url is missing', async () => {
const response = await request(server).post('/api/v1/urlcheck')
const text = await JSON.parse(response.text)
expect(text.message).toBe('missing url')
})
})
describe('Errors', () => {
it('responds with 404 on unknown path', async () => {
const response = await request(server).post('/whatever')
expect(response.statusCode).toBe(404)
}) })
}) })