Skip to content

Commit

Permalink
Basic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
gksander committed Nov 1, 2021
1 parent 61d20db commit 7655dc3
Show file tree
Hide file tree
Showing 7 changed files with 1,441 additions and 21 deletions.
4 changes: 4 additions & 0 deletions babel-native-config.js
@@ -0,0 +1,4 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
plugins: ["@babel/plugin-proposal-export-namespace-from"]
};
11 changes: 11 additions & 0 deletions jest-native-config.js
@@ -0,0 +1,11 @@
module.exports = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
testMatch: ["**/jest/**/?(*.)+(spec|test).[jt]s?(x)"],
transform: {
"^.+\\.(js|jsx)$": [
"babel-jest",
{ configFile: "./babel-native-config.js" }
]
},
setupFiles: ["./jest-native-setup.js"]
};
1 change: 1 addition & 0 deletions jest-native-setup.js
@@ -0,0 +1 @@
jest.mock("react-native", () => ({}));
4 changes: 4 additions & 0 deletions package-scripts.js
Expand Up @@ -17,6 +17,10 @@ module.exports = {
watch: "karma start --auto-watch ./config/karma/karma.conf.js",
default: "karma start ./config/karma/karma.conf.js"
},
jest: {
native: "jest --config=jest-native-config.js",
default: "jest --config=jest-native-config.js"
},
test: {
cov: npsUtils.series.nps("build-package-libs", "karma.cov"),
dev: "karma start ./config/karma/karma.conf.dev.js",
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -122,7 +122,10 @@
"webpack": "^5.0.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-stats-plugin": "^0.1.1"
"webpack-stats-plugin": "^0.1.1",
"jest": "27.3.1",
"metro-react-native-babel-preset": "0.66.2",
"@babel/plugin-proposal-export-namespace-from": "7.16.0"
},
"sideEffects": false,
"dependencies": {
Expand Down
88 changes: 88 additions & 0 deletions test/jest/native-helpers.test.js
@@ -0,0 +1,88 @@
import NativeHelpers from "../../packages/victory-native/src/helpers/native-helpers";

describe("getStyle", () => {
it("should return undefined if not called with any arguments", () => {
expect(NativeHelpers.getStyle()).toEqual(undefined);
});

it("removes all unsupported props and leaves others, including stroke props", () => {
expect(
NativeHelpers.getStyle({
fill: "black",
stroke: "grey",
pointerEvents: "auto",
x: 0,
y: 0,
_x: 0,
_y: 0,
userSelect: "none",
strokeWidth: 1,
strokeOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeLinecap: 1,
strokeLinejoin: 1
})
).toEqual({
fill: "black",
stroke: "grey",
strokeWidth: 1,
strokeOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeLinecap: 1,
strokeLinejoin: 1
});
});

it("removes all unsupported and stroke props when stroke is transparent", () => {
expect(
NativeHelpers.getStyle({
stroke: "transparent",
fill: "black",
pointerEvents: "auto",
x: 0,
y: 0,
_x: 0,
_y: 0,
userSelect: "none",
strokeWidth: 1,
strokeOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeLinecap: 1,
strokeLinejoin: 1
})
).toEqual({ fill: "black" });
});

it("removes all unsupported and stroke props when stroke is 'none'", () => {
expect(
NativeHelpers.getStyle({
stroke: "none",
fill: "black",
pointerEvents: "auto",
x: 0,
y: 0,
_x: 0,
_y: 0,
userSelect: "none",
strokeWidth: 1,
strokeOpacity: 1,
strokeDasharray: 1,
strokeDashoffset: 1,
strokeLinecap: 1,
strokeLinejoin: 1
})
).toEqual({ fill: "black" });
});

it("removes extra properties if given", () => {
expect(
NativeHelpers.getStyle({ width: 100, height: 100, depth: 100 }, [
"width",
"depth"
])
).toEqual({ height: 100 });
});
});

0 comments on commit 7655dc3

Please sign in to comment.