Skip to content

Commit d25acf4

Browse files
authored
Well completion unit tests (equinor#378)
1 parent 887907b commit d25acf4

32 files changed

+5650
-12026
lines changed

.babelrc.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
{
22
"presets": [
3-
["@babel/preset-env",
4-
{
5-
"targets": {
6-
"esmodules": true
7-
}
8-
}] ,
9-
"@babel/preset-react",
10-
"@babel/preset-typescript"
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"esmodules": true
8+
}
9+
}
10+
],
11+
"@babel/preset-react",
12+
"@babel/preset-typescript"
1113
],
1214
"plugins": [
13-
["@babel/plugin-proposal-class-properties", { "loose": true }],
14-
["@babel/plugin-proposal-private-methods", { "loose": true }],
15-
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
15+
["@babel/plugin-proposal-class-properties", { "loose": true }],
16+
["@babel/plugin-proposal-private-methods", { "loose": true }],
17+
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
1618
]
1719
}

__mocks__/fileMock.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Jest doesn't works with JSX which imports CSS
3+
* https://jestjs.io/docs/webpack
4+
*/
5+
module.exports = "test-file-stub";

__mocks__/styleMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

config/babel.config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"esmodules": true
8+
}
9+
}
10+
],
11+
"@babel/preset-react",
12+
"@babel/preset-typescript"
13+
],
14+
"plugins": [
15+
["@babel/plugin-proposal-class-properties", { "loose": true }],
16+
["@babel/plugin-proposal-private-methods", { "loose": true }],
17+
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
18+
]
19+
}

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* The jest tests had an error: SyntaxError: Cannot use import statement outside a module
3+
* After some investigation, it leads to this page https://github.com/facebook/jest/issues/9395.
4+
*/
5+
module.exports = {
6+
moduleNameMapper: {
7+
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
8+
"<rootDir>/__mocks__/fileMock.js",
9+
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
10+
},
11+
transform: {
12+
"\\.(js|ts|jsx|tsx)$": [
13+
"babel-jest",
14+
{ configFile: "./config/babel.config.json" },
15+
],
16+
},
17+
transformIgnorePatterns: ["<rootDir>/node_modules/(?!(@webviz)/)"],
18+
};

package-lock.json

Lines changed: 3628 additions & 11999 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@
8080
"@storybook/react": "^6.2.9",
8181
"@testing-library/jest-dom": "^5.11.9",
8282
"@testing-library/react": "^11.2.5",
83+
"@testing-library/user-event": "^13.1.9",
8384
"@types/jest": "^26.0.20",
8485
"@typescript-eslint/eslint-plugin": "^4.19.0",
8586
"@typescript-eslint/parser": "^4.19.0",
8687
"ace-builds": "^1.4.12",
8788
"addon-redux": "^1.1.0",
89+
"babel-jest": "^26.6.3",
8890
"babel-loader": "^8.1.0",
8991
"copyfiles": "^2.0.0",
9092
"core-js": "^3.9.1",

src/lib/components/DeckGLMap/components/settings/LayerSettingsButton.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const LayerSettingsButton: React.FC<Props> = React.memo(
2222
const classes = useStyles();
2323
const spec = useSelector((st: MapState) => st.spec);
2424
const layerVisibility = useMemo(() => getLayerVisibility(spec), [spec]);
25-
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(
26-
null
27-
);
25+
const [anchorEl, setAnchorEl] =
26+
React.useState<null | HTMLElement>(null);
2827

2928
// handlers
3029
const handleClick = useCallback(

src/lib/components/WellCompletions/components/Settings/FilterByAttributesButton.stories.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import "@testing-library/jest-dom/extend-expect";
2+
import { fireEvent, render, screen } from "@testing-library/react";
3+
import "jest-styled-components";
4+
import React from "react";
5+
import { testStore, Wrapper } from "../../test/TestWrapper";
6+
import FilterMenu from "./FilterMenu";
7+
8+
describe("Test Filter Menu", () => {
9+
it("snapshot test", () => {
10+
const { container } = render(Wrapper({ children: <FilterMenu /> }));
11+
expect(container.firstChild).toMatchSnapshot();
12+
});
13+
it("click to open filter menu and dispatch redux action", async () => {
14+
render(<FilterMenu />, {
15+
wrapper: Wrapper,
16+
});
17+
fireEvent.click(screen.getByTestId("filter_button"));
18+
expect(testStore.dispatch).toHaveBeenCalledTimes(1);
19+
expect(testStore.dispatch).toBeCalledWith({
20+
payload: true,
21+
type: "ui/updateIsDrawerOpen",
22+
});
23+
});
24+
});

0 commit comments

Comments
 (0)