-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 💍 Added tests and new storybook
- Loading branch information
Showing
32 changed files
with
9,368 additions
and
9,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Extract working directory based on jest config file | ||
|
||
# Path to Jest config file supplied by VSCode Jest Runner | ||
jest_config=$3 | ||
|
||
# Remove part after last slash | ||
cwd=$(echo "$jest_config" | sed 's|\(.*\)/.*|\1|') | ||
|
||
cd "$cwd" | ||
|
||
command="yarn jest '$1' -c ./jest.config.ts -t '$5' $6" | ||
|
||
echo "$command" | ||
|
||
eval "$command" | ||
|
||
cd ./ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { StorybookConfig } from "@storybook/react-vite"; | ||
import tsconfigPaths from "vite-tsconfig-paths"; | ||
import { mergeConfig } from "vite"; | ||
|
||
const config: StorybookConfig = { | ||
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-onboarding", | ||
"@storybook/addon-interactions", | ||
], | ||
framework: { | ||
name: "@storybook/react-vite", | ||
options: {}, | ||
}, | ||
docs: { | ||
autodocs: "tag", | ||
}, | ||
async viteFinal(config, { configType }) { | ||
// return the customized config | ||
return mergeConfig(config, { | ||
plugins: [tsconfigPaths()], | ||
}); | ||
}, | ||
}; | ||
export default config; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Preview } from "@storybook/react"; | ||
|
||
const preview: Preview = { | ||
parameters: { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/i, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default preview; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
|
||
import { useControls } from "../../src"; | ||
|
||
export const Controls: React.FC = () => { | ||
const { zoomIn, zoomOut, resetTransform, centerView } = useControls(); | ||
|
||
return ( | ||
<div> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
zoomIn(); | ||
console.log("zoomIn"); | ||
}} | ||
data-testid="zoom-in" | ||
> | ||
Zoom In + | ||
</button> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
zoomOut(); | ||
console.log("zoomOut"); | ||
}} | ||
data-testid="zoom-out" | ||
> | ||
Zoom Out - | ||
</button> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
resetTransform(); | ||
console.log("resetTransform"); | ||
}} | ||
data-testid="reset" | ||
> | ||
Reset | ||
</button> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
centerView(); | ||
console.log("centerView"); | ||
}} | ||
data-testid="center" | ||
> | ||
Center | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from "react"; | ||
|
||
import { | ||
TransformWrapper, | ||
TransformComponent, | ||
ReactZoomPanPinchProps, | ||
} from "../../src"; | ||
import { Controls } from "./controls.utils"; | ||
|
||
export const Example = (options: { | ||
props?: ReactZoomPanPinchProps; | ||
onRender: () => void; | ||
children?: React.ReactNode; | ||
}) => { | ||
const { props = {}, onRender, children } = options; | ||
|
||
onRender(); | ||
|
||
return ( | ||
<TransformWrapper {...props}> | ||
<div> | ||
{children} | ||
<Controls /> | ||
<TransformComponent | ||
wrapperProps={ | ||
{ | ||
"data-testid": "wrapper", | ||
} as React.HTMLAttributes<HTMLDivElement> | ||
} | ||
contentProps={ | ||
{ | ||
"data-testid": "content", | ||
} as React.HTMLAttributes<HTMLDivElement> | ||
} | ||
wrapperStyle={{ | ||
width: "500px", | ||
height: "500px", | ||
maxWidth: "100%", | ||
maxHeight: "calc(100vh - 50px)", | ||
}} | ||
> | ||
<div style={{ background: "#444", color: "white", padding: "50px" }}> | ||
<h1>Title</h1> | ||
<h2>Subtitle</h2> | ||
<button | ||
type="button" | ||
onClick={() => alert("You can still interact with click events!")} | ||
> | ||
Click me! | ||
</button> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | ||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | ||
enim ad minim veniam, quis nostrud exercitation ullamco laboris | ||
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in | ||
reprehenderit in voluptate velit esse cillum dolore eu fugiat | ||
nulla pariatur. Excepteur sint occaecat cupidatat non proident, | ||
sunt in culpa qui officia deserunt mollit anim id est laborum | ||
</p> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do | ||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | ||
enim ad minim veniam, quis nostrud exercitation ullamco laboris | ||
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in | ||
reprehenderit in voluptate velit esse cillum dolore eu fugiat | ||
nulla pariatur. Excepteur sint occaecat cupidatat non proident, | ||
sunt in culpa qui officia deserunt mollit anim id est laborum | ||
</p> | ||
</div> | ||
</TransformComponent> | ||
</div> | ||
</TransformWrapper> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { waitFor } from "@testing-library/react"; | ||
|
||
import { renderApp } from "../../utils/render-app"; | ||
import { ReactZoomPanPinchState } from "models"; | ||
|
||
describe("Animations [Base]", () => { | ||
describe("When panning out of boundaries", () => { | ||
describe("And content is zoomed in", () => { | ||
it("should animate returning to the bounded position", async () => { | ||
const transformStates: ReactZoomPanPinchState[] = []; | ||
const { content, pan, zoom } = renderApp({ | ||
onPanning: (ref) => { | ||
transformStates.push(ref.instance.transformState); | ||
}, | ||
}); | ||
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); | ||
zoom({ value: 1.5 }); | ||
expect(content.style.transform).toBe( | ||
"translate(0px, 0px) scale(1.5009999999999448)", | ||
); | ||
pan({ x: -100, y: -100 }); | ||
expect(transformStates).toHaveLength(1); | ||
expect(content.style.transform).toBe( | ||
"translate(-100px, -100px) scale(1.5009999999999448)", | ||
); | ||
// await waitFor(() => { | ||
// expect(transformStates).toHaveLength(5); | ||
// }); | ||
}); | ||
}); | ||
it("should animate returning to the bounded position", async () => { | ||
const { content, pan, zoom } = renderApp(); | ||
expect(content.style.transform).toBe("translate(0px, 0px) scale(1)"); | ||
pan({ x: -100, y: -100 }); | ||
expect(content.style.transform).toBe( | ||
"translate(-100px, -100px) scale(1)", | ||
); | ||
// await waitFor(() => { | ||
// expect(transformStates).toHaveLength(5); | ||
// }); | ||
}); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
__tests__/features/props.spec.tsx → __tests__/features/base/props.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
__tests__/features/rendering.spec.tsx → __tests__/features/base/rendering.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.