Skip to content

Commit

Permalink
Merge pull request #1 from callstack-internal/data-and-components
Browse files Browse the repository at this point in the history
[BASE] Add Data and Components
  • Loading branch information
adam-sajko authored Jun 20, 2024
2 parents 3551241 + 6880e08 commit 481440c
Show file tree
Hide file tree
Showing 40 changed files with 1,158 additions and 59 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WEATHER_API_KEY=
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
root: true,
extends: '@react-native',
env: {
jest: true,
},
overrides: [
{
// Test files only
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
extends: ['plugin:testing-library/react'],
},
],
};
18 changes: 18 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Install dependencies'
description: 'Install dependencies for the project'
runs:
using: 'composite'
steps:
- name: Copy .env file
shell: bash
run: cp .env.template .env

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
shell: bash
run: yarn install --frozen-lockfile
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install

- name: Run TypeScript
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn tsc --noEmit

- name: Run ESLint
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn lint

- name: Run Unit Tests
env:
NODE_OPTIONS: '--max_old_space_size=4096'
run: yarn test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ yarn-error.log
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Env
.env
4 changes: 3 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = {
arrowParens: 'avoid',
arrowParens: 'always',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
semi: true,
tabWidth: 2,
};
41 changes: 16 additions & 25 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
import {
DarkTheme,
DefaultTheme,
NavigationContainer,
} from '@react-navigation/native';
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {useColorScheme} from 'react-native';
import {RootNavigator} from './src/RootNavigator';

function HomeScreen() {
return (
<View style={styles.screen}>
<Text>Home Screen</Text>
</View>
);
}

const Stack = createNativeStackNavigator();
const queryClient = new QueryClient();

function App() {
const scheme = useColorScheme();

return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
<QueryClientProvider client={queryClient}>
<NavigationContainer theme={scheme === 'dark' ? DarkTheme : DefaultTheme}>
<RootNavigator />
</NavigationContainer>
</QueryClientProvider>
);
}

const styles = StyleSheet.create({
screen: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});

export default App;
3 changes: 3 additions & 0 deletions __mocks__/react-native-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
WEATHER_API_KEY: 'test-weather',
};
16 changes: 3 additions & 13 deletions __tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/**
* @format
*/

import 'react-native';
import {render} from '@testing-library/react-native';
import React from 'react';
import App from '../App';

// Note: import explicitly to use the types shipped with jest.
import {it} from '@jest/globals';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
it('renders correctly', async () => {
render(<App />);
});
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
apply plugin: "org.jetbrains.kotlin.android"
apply plugin: "com.facebook.react"

Expand Down
14 changes: 14 additions & 0 deletions e2e/flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
appId: ${APP_ID}
---
- launchApp
- assertVisible: 'Weather'
- assertVisible:
id: 'Warsaw'
index: 0
- tapOn:
id: 'Warsaw'
index: 0
- assertVisible: 'Humidity'
- assertVisible: 'Pressure'
- assertVisible: 'Wind'
- assertVisible: 'Visibility'
8 changes: 8 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,10 @@ PODS:
- React-Mapbuffer (0.74.2):
- glog
- React-debug
- react-native-config (1.5.2):
- react-native-config/App (= 1.5.2)
- react-native-config/App (1.5.2):
- React-Core
- react-native-safe-area-context (4.10.5):
- React-Core
- React-nativeconfig (0.74.2)
Expand Down Expand Up @@ -1224,6 +1228,7 @@ DEPENDENCIES:
- React-jsitracing (from `../node_modules/react-native/ReactCommon/hermes/executor/`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-config (from `../node_modules/react-native-config`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -1317,6 +1322,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
React-Mapbuffer:
:path: "../node_modules/react-native/ReactCommon"
react-native-config:
:path: "../node_modules/react-native-config"
react-native-safe-area-context:
:path: "../node_modules/react-native-safe-area-context"
React-nativeconfig:
Expand Down Expand Up @@ -1401,6 +1408,7 @@ SPEC CHECKSUMS:
React-jsitracing: 0fa7f78d8fdda794667cb2e6f19c874c1cf31d7e
React-logger: 29fa3e048f5f67fe396bc08af7606426d9bd7b5d
React-Mapbuffer: bf56147c9775491e53122a94c423ac201417e326
react-native-config: d7d8a0c65f7fa523197879f6b777997abbfc987e
react-native-safe-area-context: a240ad4b683349e48b1d51fed1611138d1bdad97
React-nativeconfig: 9f223cd321823afdecf59ed00861ab2d69ee0fc1
React-NativeModulesApple: ff7efaff7098639db5631236cfd91d60abff04c0
Expand Down
12 changes: 3 additions & 9 deletions ios/WeatherApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
5DCACB8F33CDC322A6C60F78 /* libPods-WeatherApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WeatherApp.a"; sourceTree = BUILT_PRODUCTS_DIR; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = WeatherApp/LaunchScreen.storyboard; sourceTree = "<group>"; };
89C6BE57DB24E9ADA2F236DE /* Pods-WeatherApp-WeatherAppTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WeatherApp-WeatherAppTests.release.xcconfig"; path = "Target Support Files/Pods-WeatherApp-WeatherAppTests/Pods-WeatherApp-WeatherAppTests.release.xcconfig"; sourceTree = "<group>"; };
9FC02B7AF3BE7B696F3E5EF5 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; name = PrivacyInfo.xcprivacy; path = WeatherApp/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
9FC02B7AF3BE7B696F3E5EF5 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = WeatherApp/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -590,10 +590,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down Expand Up @@ -665,10 +662,7 @@
"-DFOLLY_CFG_NO_COROUTINES=1",
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
);
OTHER_LDFLAGS = (
"$(inherited)",
" ",
);
OTHER_LDFLAGS = "$(inherited) ";
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
SDKROOT = iphoneos;
USE_HERMES = true;
Expand Down
11 changes: 11 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '@testing-library/react-native/extend-expect';
import {setupServer} from 'msw/node';
import {handlers} from './src/mocks/handlers';

jest.useFakeTimers();

export const server = setupServer(...handlers);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
9 changes: 8 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module.exports = {
/** @type {import('jest').Config} */
const config = {
preset: 'react-native',
transformIgnorePatterns: [
'node_modules/(?!((jest-)?react-native|@react-native/.*|react-navigation|@react-navigation/.*))',
],
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
};

module.exports = config;
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
"test": "jest",
"tsc": "tsc"
},
"dependencies": {
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.9.26",
"@tanstack/react-query": "^5.45.1",
"react": "18.2.0",
"react-native": "0.74.2",
"react-native-config": "^1.5.2",
"react-native-safe-area-context": "^4.10.5",
"react-native-screens": "^3.32.0"
"react-native-screens": "^3.32.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@babel/core": "^7.20.0",
Expand All @@ -25,11 +29,15 @@
"@react-native/eslint-config": "0.74.84",
"@react-native/metro-config": "0.74.84",
"@react-native/typescript-config": "0.74.84",
"@testing-library/react-native": "^12.5.1",
"@types/jest": "^29.5.12",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"eslint-plugin-testing-library": "^6.2.2",
"jest": "^29.6.3",
"msw": "^2.3.1",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
Expand Down
8 changes: 8 additions & 0 deletions react-native-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'react-native-config' {
export interface NativeConfig {
WEATHER_API_KEY?: string;
}

export const Config: NativeConfig;
export default Config;
}
37 changes: 37 additions & 0 deletions src/RootNavigator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {RootStackParamList, WeatherStackParamsList} from './types';
import WeatherList from './screens/WeatherList';
import WeatherDetails from './screens/WeatherDetails';

const Stack = createNativeStackNavigator<RootStackParamList>();
const WeatherStack = createNativeStackNavigator<WeatherStackParamsList>();

function WeatherStackScreen() {
return (
<WeatherStack.Navigator>
<WeatherStack.Screen
name="WeatherList"
component={WeatherList}
options={{title: 'Weather'}}
/>
<WeatherStack.Screen
name="WeatherDetails"
component={WeatherDetails}
options={{title: 'Details'}}
/>
</WeatherStack.Navigator>
);
}

export function RootNavigator() {
return (
<Stack.Navigator>
<Stack.Screen
name="Weather"
component={WeatherStackScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
);
}
Loading

0 comments on commit 481440c

Please sign in to comment.