Skip to content

Commit

Permalink
Add test for Blocks (+ Update test environment)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Mar 15, 2022
1 parent 9ba421b commit 107b9ad
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"test": {
"presets": ["@babel/preset-react"],
"presets": ["@babel/preset-react", "@babel/preset-typescript"],
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
},
Expand Down
32 changes: 32 additions & 0 deletions app/scripts/components/discoveries/single/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* set up test environment for jest
* @jest-environment jsdom
*/
import React from 'react';
import { render } from '@testing-library/react';

import { ContentBlockProse } from '$styles/content-block';
import Block from '$components/discoveries/blocks';
import Figure from '$components/discoveries/blocks/figure';
import { Caption } from '$components/discoveries/images';

test('Throws an error when content is not wrapped with Prose', () => {
const { getByText } = render(
<Block>
<p>test</p>
</Block>
);
expect(getByText(/There is an error in this block: /)).toBeDefined();
});

test('Throws an error when a block has two captions', () => {
const { getByText } = render(
<Block>
<Figure>
<Caption />
<Caption />
</Figure>
</Block>
);
expect(getByText(/There is an error in this block: /)).toBeDefined();
});
2 changes: 1 addition & 1 deletion app/scripts/styles/content-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { glsp, themeVal } from '@devseed-ui/theme-provider';
import { variableGlsp, variableProseVSpace } from './variable-utils';
import { VarProse } from './variable-components';

import Hug from './hug';
import Hug from './hug/index.ts';

import { FigcaptionInner, Figure } from '$components/common/figure';

Expand Down
18 changes: 13 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.10.0",
"ts-jest": "^27.1.3",
"typescript": "^4.5.5"
},
"dependencies": {
Expand All @@ -89,14 +90,14 @@
"@devseed-ui/shadow-scrollbar": "^4.0.0",
"@devseed-ui/theme-provider": "^4.0.0",
"@devseed-ui/typography": "^4.0.0",
"@types/mdx": "^2.0.1",
"axios": "^0.25.0",
"date-fns": "^2.28.0",
"@nivo/core": "^0.79.0",
"@nivo/line": "^0.79.1",
"@types/mdx": "^2.0.1",
"axios": "^0.25.0",
"d3-fetch": "^3.0.1",
"d3-scale-chromatic": "^3.0.0",
"d3-shape": "^3.1.0",
"date-fns": "^2.28.0",
"history": "^5.1.0",
"lodash.defaultsdeep": "^4.6.1",
"lodash.get": "^4.4.2",
Expand All @@ -122,7 +123,8 @@
"jest": {
"verbose": true,
"transform": {
"^.+\\.js$": "babel-jest"
"^.+\\.js$": "babel-jest",
"^.+\\.ts?$": "ts-jest"
},
"globals": {
"NODE_ENV": "test"
Expand All @@ -133,6 +135,12 @@
],
"moduleDirectories": [
"node_modules"
]
],
"moduleNameMapper": {
"^\\$styles(.*)$": "<rootDir>/app/scripts/styles$1",
"^\\$components(.*)$": "<rootDir>/app/scripts/components$1",
"^\\$utils(.*)$": "<rootDir>/app/scripts/utils$1",
"^\\$context(.*)$": "<rootDir>/app/scripts/context$1"
}
}
}
48 changes: 37 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3284,6 +3284,13 @@ browserslist@^4.0.0, browserslist@^4.12.0, browserslist@^4.16.6, browserslist@^4
node-releases "^2.0.2"
picocolors "^1.0.0"

[email protected]:
version "0.2.6"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/bs-logger/-/bs-logger-0.2.6.tgz#eb7d365307a72cf974cc6cda76b68354ad336bd8"
integrity sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==
dependencies:
fast-json-stable-stringify "2.x"

[email protected]:
version "2.1.1"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/bser/-/bser-2.1.1.tgz#e6787da20ece9d07998533cfd9de6f5c38f4bc05"
Expand Down Expand Up @@ -4835,7 +4842,7 @@ fast-glob@^3.2.5, fast-glob@^3.2.7, fast-glob@^3.2.9:
merge2 "^1.3.0"
micromatch "^4.0.4"

fast-json-stable-stringify@^2.0.0:
fast-json-stable-stringify@2.x, fast-json-stable-stringify@^2.0.0:
version "2.1.0"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
Expand Down Expand Up @@ -6513,7 +6520,7 @@ jest-snapshot@^27.5.1:
pretty-format "^27.5.1"
semver "^7.3.2"

jest-util@^27.5.1:
jest-util@^27.0.0, jest-util@^27.5.1:
version "27.5.1"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/jest-util/-/jest-util-27.5.1.tgz#3ba9771e8e31a0b85da48fe0b0891fb86c01c2f9"
integrity sha512-Kv2o/8jNvX1MQ0KGtw480E/w4fBCDOnH6+6DmeKi6LZUIlKA5kwY0YNdlzaWTiVgxqAqik11QyxDOKk543aKXw==
Expand Down Expand Up @@ -6656,7 +6663,7 @@ json-stable-stringify-without-jsonify@^1.0.1:
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=

json5@^2.1.2, json5@^2.2.0:
json5@2.x, json5@^2.1.2, json5@^2.2.0:
version "2.2.0"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
Expand Down Expand Up @@ -6852,7 +6859,7 @@ lodash.isfinite@^3.3.2:
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/lodash.isfinite/-/lodash.isfinite-3.3.2.tgz#fb89b65a9a80281833f0b7478b3a5104f898ebb3"
integrity sha1-+4m2WpqAKBgz8LdHizpRBPiY67M=

lodash.memoize@^4.1.2:
lodash.memoize@4.x, lodash.memoize@^4.1.2:
version "4.1.2"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
Expand Down Expand Up @@ -6921,6 +6928,11 @@ make-dir@^3.0.0:
dependencies:
semver "^6.0.0"

[email protected]:
version "1.3.6"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

make-iterator@^1.0.0:
version "1.0.1"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/make-iterator/-/make-iterator-1.0.1.tgz#29b33f312aa8f547c4a5e490f56afcec99133ad6"
Expand Down Expand Up @@ -9423,18 +9435,18 @@ [email protected]:
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==

semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
[email protected], semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.3.5"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7"
integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==
dependencies:
lru-cache "^6.0.0"

semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

set-blocking@^2.0.0:
version "2.0.0"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down Expand Up @@ -10204,6 +10216,20 @@ trough@^2.0.0:
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/trough/-/trough-2.1.0.tgz#0f7b511a4fde65a46f18477ab38849b22c554876"
integrity sha512-AqTiAOLcj85xS7vQ8QkAV41hPDIJ71XJB4RCUrzo/1GM2CQwhkJGaf9Hgr7BOugMRpgGUrqRg/DrBDl4H40+8g==

ts-jest@^27.1.3:
version "27.1.3"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/ts-jest/-/ts-jest-27.1.3.tgz#1f723e7e74027c4da92c0ffbd73287e8af2b2957"
integrity sha512-6Nlura7s6uM9BVUAoqLH7JHyMXjz8gluryjpPXxr3IxZdAXnU6FhjvVLHFtfd1vsE1p8zD1OJfskkc0jhTSnkA==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
jest-util "^27.0.0"
json5 "2.x"
lodash.memoize "4.x"
make-error "1.x"
semver "7.x"
yargs-parser "20.x"

tslib@^1.8.1:
version "1.14.1"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
Expand Down Expand Up @@ -10918,7 +10944,7 @@ yaml@^1.10.0, yaml@^1.10.2:
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/yaml/-/yaml-1.10.2.tgz#2301c5ffbf12b467de8da2333a459e29e7920e4b"
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==

yargs-parser@^20.2.2, yargs-parser@^20.2.3:
yargs-parser@20.x, yargs-parser@^20.2.2, yargs-parser@^20.2.3:
version "20.2.9"
resolved "http://ec2-3-82-125-171.compute-1.amazonaws.com:4873/yargs-parser/-/yargs-parser-20.2.9.tgz#2eb7dc3b0289718fc295f362753845c41a0c94ee"
integrity sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==
Expand Down

0 comments on commit 107b9ad

Please sign in to comment.