Skip to content

Commit

Permalink
test: Added more unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Agrawal committed Jan 1, 2024
1 parent 17183eb commit c156062
Show file tree
Hide file tree
Showing 36 changed files with 7,454 additions and 27 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
],
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{js,jsx,ts,tsx}",
"src/**/*.{js,jsx,ts,tsx}",
"!**/index.ts",
"!App.tsx",
"!**/*.{json,md}",
"!commitlint.config.js",
Expand Down
4 changes: 3 additions & 1 deletion src/__snapshots__/pearl.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ exports[`pearl/basic passes the snapshot test for a <Text> component 1`] = `
<Text
style={{}}
>
asdasd
<Text>
asdasd
</Text>
</Text>
</View>
`;
Expand Down
52 changes: 48 additions & 4 deletions src/components/atoms/box/__snapshots__/box.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,60 @@ exports[`Atoms/Box passes the basic snapshot test 1`] = `
}
>
<View
animate={{}}
animate={
{
"height": 10,
"width": 10,
}
}
animatedStyle={
{
"value": {
"height": 10,
"width": 10,
},
}
}
collapsable={false}
style={
{
"height": 10,
"width": 10,
}
}
/>
</View>
`;

exports[`Atoms/Box renders correctly with different props 1`] = `
<View
style={
{
"flex": 1,
}
}
>
<View
animate={
{
"backgroundColor": "#ff0000",
}
}
animatedStyle={
{
"value": {},
"value": {
"backgroundColor": "#ff0000",
},
}
}
collapsable={false}
style={{}}
style={
{
"backgroundColor": "#ff0000",
}
}
>
asdasd
Test Text
</View>
</View>
`;
23 changes: 22 additions & 1 deletion src/components/atoms/box/box.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import Box from "./box";
import Text from "../text/text";
import { render } from "@testing-library/react-native";
import { ThemeProvider } from "../../../theme/src/theme-context";

Expand All @@ -9,7 +10,27 @@ describe("Atoms/Box", () => {
it("passes the basic snapshot test", () => {
const tree = render(
<ThemeProvider>
<Box>asdasd</Box>
<Box w={10} h={10} />
</ThemeProvider>
).toJSON();
expect(tree).toMatchSnapshot();
});

it("renders the correct text", () => {
const { getByText } = render(
<ThemeProvider>
<Box>
<Text>Test Text</Text>
</Box>
</ThemeProvider>
);
expect(getByText("Test Text")).toBeTruthy();
});

it("renders correctly with different props", () => {
const tree = render(
<ThemeProvider>
<Box bgColor="red">Test Text</Box>
</ThemeProvider>
).toJSON();
expect(tree).toMatchSnapshot();
Expand Down
118 changes: 118 additions & 0 deletions src/components/atoms/collapse/__snapshots__/collapse.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Atoms/Collapse passes the snapshot test when show is false 1`] = `
<View
style={
{
"flex": 1,
}
}
/>
`;

exports[`Atoms/Collapse passes the snapshot test when show is true 1`] = `
<View
style={
{
"flex": 1,
}
}
>
<View
animate={
{
"height": "auto",
"opacity": 1,
}
}
animatedStyle={
{
"value": {
"height": 0,
"opacity": 0,
},
}
}
collapsable={false}
exit={
{
"height": 0,
"opacity": 0,
}
}
exitTransition={
{
"dampingRatio": 1,
"duration": 150,
"easing": [Function],
"type": "spring",
}
}
from={
{
"height": 0,
"opacity": 0,
}
}
style={
{
"height": 0,
"opacity": 0,
}
}
transition={
{
"dampingRatio": 1,
"duration": 150,
"easing": [Function],
"type": "spring",
}
}
>
<View
animate={{}}
animatedStyle={
{
"value": {},
}
}
collapsable={false}
onLayout={[Function]}
style={{}}
>
<Text
accessibilityRole="text"
accessible={true}
allowFontScaling={true}
animate={
{
"color": "#1A2138",
}
}
animatedStyle={
{
"value": {
"color": "#1A2138",
},
}
}
collapsable={false}
style={
{
"color": "#1A2138",
"fontFamily": "Poppins-Regular",
"fontSize": 16.099999999999998,
"fontStyle": "normal",
"fontWeight": "400",
"includeFontPadding": false,
"letterSpacing": 0,
"lineHeight": 22,
}
}
>
This is a test
</Text>
</View>
</View>
</View>
`;
31 changes: 31 additions & 0 deletions src/components/atoms/collapse/collapse.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import { render } from "@testing-library/react-native";
import Collapse from "./collapse";
import Text from "../text/text";
import { ThemeProvider } from "../../../theme/src/theme-context";

jest.useFakeTimers();

describe("Atoms/Collapse", () => {
it("passes the snapshot test when show is true", () => {
const tree = render(
<ThemeProvider>
<Collapse show={true}>
<Text>This is a test</Text>
</Collapse>
</ThemeProvider>
).toJSON();
expect(tree).toMatchSnapshot();
});

it("passes the snapshot test when show is false", () => {
const tree = render(
<ThemeProvider>
<Collapse show={false}>
<Text>This is a test</Text>
</Collapse>
</ThemeProvider>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
99 changes: 99 additions & 0 deletions src/components/atoms/fade/__snapshots__/fade.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Atoms/Fade passes the snapshot test when show is false 1`] = `
<View
style={
{
"flex": 1,
}
}
/>
`;

exports[`Atoms/Fade passes the snapshot test when show is true 1`] = `
<View
style={
{
"flex": 1,
}
}
>
<View
animate={
{
"opacity": 1,
}
}
animatedStyle={
{
"value": {
"opacity": 0,
},
}
}
collapsable={false}
exit={
{
"opacity": 0,
}
}
exitTransition={
{
"dampingRatio": 1,
"duration": 100,
"type": "spring",
}
}
from={
{
"opacity": 0,
}
}
style={
{
"opacity": 0,
}
}
transition={
{
"dampingRatio": 1,
"duration": 100,
"type": "spring",
}
}
>
<Text
accessibilityRole="text"
accessible={true}
allowFontScaling={true}
animate={
{
"color": "#1A2138",
}
}
animatedStyle={
{
"value": {
"color": "#1A2138",
},
}
}
collapsable={false}
style={
{
"color": "#1A2138",
"fontFamily": "Poppins-Regular",
"fontSize": 16.099999999999998,
"fontStyle": "normal",
"fontWeight": "400",
"includeFontPadding": false,
"letterSpacing": 0,
"lineHeight": 22,
}
}
>
This is a test
</Text>
</View>
</View>
`;
Loading

0 comments on commit c156062

Please sign in to comment.