Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #24

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4f1f037
purge jest from our repo
zineanteoh Mar 19, 2023
c9f1572
install [email protected] (must be SAME VERSION AS REACT)
zineanteoh Mar 20, 2023
16d1b2d
npm install --save-dev @testing-library/react-native (wow it worked f…
zineanteoh Mar 20, 2023
6d3a0be
npm install --save-dev @testing-library/jest-native (life is great)
zineanteoh Mar 20, 2023
ce3bd42
npm install --save-dev jest typescript ts-jest @types/jest
zineanteoh Mar 20, 2023
65e7151
run npx ts-jest config:init
zineanteoh Mar 20, 2023
23a1d3a
install jest-expo, ts-node
zineanteoh Mar 20, 2023
84eeee9
add jest config ts
zineanteoh Mar 20, 2023
5acb18f
minimal jest setup
zineanteoh Mar 20, 2023
1aac8de
add a unit test
zineanteoh Mar 20, 2023
003adf1
add other cards tests
zineanteoh Mar 20, 2023
065dc2c
mock native helper
zineanteoh Mar 20, 2023
6d1fa84
mock firebase
zineanteoh Mar 20, 2023
27a0794
add env to yml
zineanteoh Mar 20, 2023
e1ffd7d
remove firebase mock
zineanteoh Mar 20, 2023
4e58cc4
npm i detox --save-dev
zineanteoh Mar 20, 2023
44fa1c6
detox init
zineanteoh Mar 20, 2023
332c2e3
run format and add to prettier ignore
zineanteoh Mar 20, 2023
31880f5
device configs
zineanteoh Mar 20, 2023
b3c154a
set up typescript for detox and implement basic signin test
zineanteoh Mar 20, 2023
803cf5b
Add .circleci/config.yml
zineanteoh Mar 20, 2023
69d1ba3
Merge branch 'circleci-project-setup' into testing
zineanteoh Mar 20, 2023
a820be5
make github actino run only jest tests
zineanteoh Mar 20, 2023
564c6c1
try to run detox on github actino first
zineanteoh Mar 20, 2023
bf796b0
use latest actions
zineanteoh Mar 20, 2023
e0a3acd
add npx before detox
zineanteoh Mar 20, 2023
711825a
increase timeout minutes
zineanteoh Mar 20, 2023
e078d50
there is no way this fails
zineanteoh Mar 21, 2023
a65180f
increase jest timeout
zineanteoh Mar 21, 2023
182d302
THIS HAS TO WORK, RIGHT??
zineanteoh Mar 21, 2023
c0f0d35
extract testIDs to constant
zineanteoh Mar 22, 2023
d58bb7f
add comments for clairification
zineanteoh Mar 22, 2023
4a5f16e
install detox cli
zineanteoh Mar 22, 2023
a53491a
remove circleci
zineanteoh Mar 22, 2023
628d84d
Merge branch 'main' into testing
zineanteoh Mar 24, 2023
43f09b9
add npm scripts
zineanteoh Mar 24, 2023
2fa0ead
use constants to fix e2e test
zineanteoh Mar 24, 2023
013879e
Merge branch 'main' into testing
zineanteoh Mar 28, 2023
c617d23
Merge branch 'main' into testing
zineanteoh Mar 28, 2023
7ce71a2
Merge branch 'main' into testing
zineanteoh Apr 8, 2023
6fcb4df
Merge branch 'main' into testing
ethanratnofsky Apr 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
say-hello:
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/base:stable
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- run:
name: "Say hello"
command: "echo Hello, World!"

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
say-hello-workflow:
jobs:
- say-hello
87 changes: 87 additions & 0 deletions .detoxrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/** @type {Detox.DetoxConfig} */
module.exports = {
testRunner: {
args: {
$0: 'jest',
config: 'e2e/jest.config.js',
},
jest: {
setupTimeout: 300000,
},
},
apps: {
'ios.debug': {
type: 'ios.app',
binaryPath:
'ios/build/Build/Products/Debug-iphonesimulator/nightlight.app',
build:
'xcodebuild -workspace ios/nightlight.xcworkspace -scheme nightlight -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build',
},
'ios.release': {
type: 'ios.app',
binaryPath:
'ios/build/Build/Products/Release-iphonesimulator/nightlight.app',
build:
'xcodebuild -workspace ios/nightlight.xcworkspace -scheme nightlight -configuration Release -sdk iphonesimulator -derivedDataPath ios/build',
},
'android.debug': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
build:
'cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug',
reversePorts: [8081],
},
'android.release': {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
build:
'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release',
},
},
devices: {
simulator: {
type: 'ios.simulator',
device: {
type: 'iPhone 14',
},
},
attached: {
type: 'android.attached',
device: {
adbName: '.*',
},
},
emulator: {
type: 'android.emulator',
device: {
avdName: 'Pixel_3a_API_30_x86',
},
},
},
configurations: {
'ios.sim.debug': {
device: 'simulator',
app: 'ios.debug',
},
'ios.sim.release': {
device: 'simulator',
app: 'ios.release',
},
'android.att.debug': {
device: 'attached',
app: 'android.debug',
},
'android.att.release': {
device: 'attached',
app: 'android.release',
},
'android.emu.debug': {
device: 'emulator',
app: 'android.debug',
},
'android.emu.release': {
device: 'emulator',
app: 'android.release',
},
},
};
65 changes: 62 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- uses: stefanzweifel/[email protected]
with:
commit_message: Apply Prettier formatting
test:
name: Run tests
unit-test:
name: Run jest tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -41,4 +41,63 @@ jobs:
- name: Install packages
run: npm ci
- name: Run tests
run: npm test
run: npm test -- --testPathPattern=__tests__
env:
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}
FIREBASE_AUTHDOMAIN: ${{ secrets.FIREBASE_AUTHDOMAIN }}
FIREBASE_PROJECTID: ${{ secrets.FIREBASE_PROJECTID }}
FIREBASE_STORAGEBUCKET: ${{ secrets.FIREBASE_STORAGEBUCKET }}
FIREBASE_MESSAGINGSENDERID: ${{ secrets.FIREBASE_MESSAGINGSENDERID }}
FIREBASE_APPID: ${{ secrets.FIREBASE_APPID }}
FIREBASE_MEASUREMENTID: ${{ secrets.FIREBASE_MEASUREMENTID }}
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }}
SERVER_URL: ${{ secrets.SERVER_URL }}
e2e-test:
name: Run Detox e2e tests
runs-on: macos-latest
timeout-minutes: 120
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Node
uses: actions/setup-node@v3
- name: Cache node modules
uses: actions/cache@v3
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('**/package-lock.json') }}
- name: Rebuild detox
if: steps.cache.outputs.cache-hit == 'true'
run: npx detox clean-framework-cache && detox build-framework-cache
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: npm install

- name: Cache Pods
uses: actions/cache@v1
id: podcache
with:
path: ios/Pods
key: pods-${{ hashFiles('**/Podfile.lock') }}

- name: Update Pods
run: |
gem update cocoapods xcodeproj
cd ios && pod install && cd ..
- run: brew tap wix/brew
- run: brew install applesimutils
- run: npx detox build e2e --configuration ios.sim.release
- run: npx detox test e2e --configuration ios.sim.release --cleanup --debug-synchronization 200
env:
FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }}
FIREBASE_AUTHDOMAIN: ${{ secrets.FIREBASE_AUTHDOMAIN }}
FIREBASE_PROJECTID: ${{ secrets.FIREBASE_PROJECTID }}
FIREBASE_STORAGEBUCKET: ${{ secrets.FIREBASE_STORAGEBUCKET }}
FIREBASE_MESSAGINGSENDERID: ${{ secrets.FIREBASE_MESSAGINGSENDERID }}
FIREBASE_APPID: ${{ secrets.FIREBASE_APPID }}
FIREBASE_MEASUREMENTID: ${{ secrets.FIREBASE_MEASUREMENTID }}
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }}
SERVER_URL: ${{ secrets.SERVER_URL }}
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

.expo/
.expo/

ios/build
ios/Pods
20 changes: 0 additions & 20 deletions __tests__/components/TabBar.test.tsx

This file was deleted.

73 changes: 38 additions & 35 deletions __tests__/components/map/UserCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('<UserCard />', () => {
longitude: 42,
latitude: 42,
};
const phoneNumber = '615-555-5555';
const phone = '615-555-5555';
const dummyUser: User = {
_id: '',
firstName,
Expand All @@ -20,7 +20,10 @@ describe('<UserCard />', () => {
location,
time: new Date(),
},
phoneNumber,
phone,
birthday: new Date(),
email: '[email protected]',
firebaseUid: 'rO9mtd0kjCh8xv6Adqr3OwY0kky1',
};

test('it should have a functioning close button', () => {
Expand Down Expand Up @@ -63,42 +66,42 @@ describe('<UserCard />', () => {
screen.getByText(firstName + ' ' + lastName);

// get phone number (throw error if no exist)
screen.getByText(phoneNumber);
screen.getByText(phone);

// get initials of user (throw error if no exist)
screen.getByText(`${firstName[0]}${lastName[0]}`);
});

test('it should have functioning action buttons', () => {
// TODO: this is only to temporary mock alert() -- remove later
global.alert = jest.fn();

// create mock variables
let mockLocations: Location[] = [];

// TODO: mock the necessary functions for testing pressables
// (currently does not work)
const mockHandleStartNavigation = jest.fn(location =>
mockLocations.push(location)
);
const mockHandleCallUser = jest.fn();
const mockHandlePingUser = jest.fn();

// render component
render(<UserCard user={dummyUser} onClose={() => {}} />);

// get the pressables (throw error if no exist)
const press1 = screen.getByLabelText(
TestingLabel.USER_CARD_START_NAVIGATION
);
const press2 = screen.getByLabelText(TestingLabel.USER_CARD_CALL_USER);
const press3 = screen.getByLabelText(TestingLabel.USER_CARD_PING_USER);

// click on the pressables
fireEvent(press1, 'press');
fireEvent(press2, 'press');
fireEvent(press3, 'press');

// TODO: test what happens when each pressables are pressed
});
// test('it should have functioning action buttons', () => {
// // TODO: this is only to temporary mock alert() -- remove later
// global.alert = jest.fn();

// // create mock variables
// let mockLocations: Location[] = [];

// // TODO: mock the necessary functions for testing pressables
// // (currently does not work)
// const mockHandleStartNavigation = jest.fn(location =>
// mockLocations.push(location)
// );
// const mockHandleCallUser = jest.fn();
// const mockHandlePingUser = jest.fn();

// // render component
// render(<UserCard user={dummyUser} onClose={() => {}} />);

// // get the pressables (throw error if no exist)
// const press1 = screen.getByLabelText(
// TestingLabel.USER_CARD_START_NAVIGATION
// );
// const press2 = screen.getByLabelText(TestingLabel.USER_CARD_CALL_USER);
// const press3 = screen.getByLabelText(TestingLabel.USER_CARD_PING_USER);

// // click on the pressables
// fireEvent(press1, 'press');
// fireEvent(press2, 'press');
// fireEvent(press3, 'press');

// // TODO: test what happens when each pressables are pressed
// });
});
51 changes: 0 additions & 51 deletions __tests__/index.test.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions __tests__/screens/MapScreen.test.tsx

This file was deleted.

Loading