Skip to content

Commit

Permalink
feat: Add jest tests and run it on workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
groot007 committed Feb 24, 2024
1 parent 23d9593 commit ee6e5ba
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 12 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Jest on CI

on:
push:
branches: main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install dependecies
run: npm ci

- name: Run test
run: npm test
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
presets: ['module:@react-native/babel-preset', '@babel/preset-typescript'],
};
3 changes: 2 additions & 1 deletion ios/onboarding/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This is needed to get location updates in the background</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UILaunchStoryboardName</key>
Expand Down
1 change: 1 addition & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/react-native/extend-expect';
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
preset: 'react-native',
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
testMatch: ['<rootDir>/src/**/*.test.ts?(x)'],
transformIgnorePatterns: [
'node_modules/(?!(jest-)?react-native|react-clone-referenced-element|@react-native-community|rollbar-react-native|@react-native|@react-navigation)',
],
};
80 changes: 79 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/preset-typescript": "^7.23.3",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.73.21",
"@react-native/eslint-config": "0.73.2",
"@react-native/metro-config": "0.73.5",
"@react-native/typescript-config": "0.73.1",
"@testing-library/react-native": "^12.4.3",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.56.0",
"jest": "^29.6.3",
"jest": "^29.7.0",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
Expand Down
133 changes: 133 additions & 0 deletions src/components/weather-row/__snapshots__/weather.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Weather row should render correctly 1`] = `
<View
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"borderBottomWidth": 1,
"borderColor": "#ddd",
"marginBottom": 10,
"opacity": 1,
"paddingBottom": 10,
"paddingHorizontal": 10,
}
}
testID="wheather-row"
>
<View
style={
{
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"gap": 16,
}
}
>
<View
style={
{
"height": 50,
"position": "relative",
"width": 80,
}
}
>
<Image
height={50}
source={
{
"uri": "https://openweathermap.org/img/wn/[email protected]",
}
}
style={
{
"left": 0,
"position": "absolute",
"top": 0,
}
}
width={50}
/>
</View>
<View
style={
{
"alignItems": "center",
"flex": 1,
"flexDirection": "column",
}
}
>
<Text
style={
{
"fontWeight": "600",
}
}
testID="cityName"
>
Gothem
</Text>
<Text
style={
{
"fontWeight": "300",
}
}
>
snow
</Text>
</View>
<View
style={
{
"backgroundColor": "#9c3a5f",
"borderRadius": 50,
"padding": 8,
}
}
>
<Text
style={
{
"color": "#fff",
}
}
>
100 F
</Text>
</View>
<Text>
&gt;
</Text>
</View>
</View>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import React from 'react';
import {useNavigation} from '@react-navigation/native';
import {Image, Text, TouchableOpacity, View} from 'react-native';

type WheatherRowProps = {
wheather: any;
type WeatherRowProps = {
weather: any;
};

const WheatherRow = ({wheather}: WheatherRowProps) => {
const WeatherRow = ({weather}: WeatherRowProps) => {
const navigation = useNavigation();
const {name, main, coord, weather: details} = wheather;
const {name, main, coord, weather: details} = weather;

return (
<TouchableOpacity
Expand Down Expand Up @@ -56,7 +56,9 @@ const WheatherRow = ({wheather}: WheatherRowProps) => {
flexDirection: 'column',
alignItems: 'center',
}}>
<Text style={{fontWeight: '600'}}>{name}</Text>
<Text style={{fontWeight: '600'}} testID="cityName">
{name}
</Text>
<Text style={{fontWeight: '300'}}>{details[0].main}</Text>
</View>

Expand All @@ -70,4 +72,4 @@ const WheatherRow = ({wheather}: WheatherRowProps) => {
);
};

export default WheatherRow;
export default WeatherRow;
Loading

0 comments on commit ee6e5ba

Please sign in to comment.