Skip to content

Commit

Permalink
Merge pull request #237 from SCCapstone/Testing-Brian
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
BrianW2301 authored Apr 24, 2023
2 parents 3d31d1a + 7207f94 commit 83c4677
Show file tree
Hide file tree
Showing 8 changed files with 27,417 additions and 12,995 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ npm-debug.*
*.mobileprovision
*.orig.*
web-build/

coverage/**/*
# macOS
.DS_Store
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Life React


LifeReact is a lifestyle app that allows users to keep track of your calorie intake by providing a persistent, interactive food diary. All nutritional information is pulled directly from the USDA to ensure a high degree of accuracy. Users can also view dynamic updates on their progress towards their calorie goal from the home screen.

## External Requirements
Expand All @@ -16,7 +15,6 @@ In order to build this project you first have to install:
- If you choose to use an emulator, there are many free options to choose from, such as the built-in [Android Emulator](https://developer.android.com/studio/run/emulator) from Android Studio.
- If you're using macOS, you can download [Xcode](https://apps.apple.com/us/app/xcode/id497799835?mt=12) via the Mac App store.


## Setup

Install expo-cli with the following command:
Expand Down Expand Up @@ -61,21 +59,22 @@ eas build

# Testing

Unit tests are located in `/test/unit`.
Unit tests are located in `/__tests__/unit`.

Behavioral tests are located in `/test/behavioral`.
Behavioral tests are located in `/__tests__/behavioral`.

## Testing Technology

Testing is done using jest and the React Native Testing Library. These are included in the projects dependencies and can be installed with the command
Testing is done using jest and the React Native Testing Library. These are included in the projects dependencies and can be installed with the command

```console
npm install
```


## Running Tests

Tests are ran with the following command .

```console
npm run test
```
Expand Down
1 change: 1 addition & 0 deletions __mocks__/@react-native-async-storage/async-storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default from '@react-native-async-storage/async-storage/jest/async-storage-mock';
16 changes: 16 additions & 0 deletions __tests__/behavioral/FoodSearchScreenBehavioral.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react';
import FoodSearchScreen from '../../Screens/FoodSearchScreen';
import {render, screen, fireEvent,} from '@testing-library/react-native';
describe('FoodSearchScreenBehavioral', () => {
const thisRoute = { params: 'breakfast' };
beforeEach(() => {
var wrapper = render(<FoodSearchScreen route={thisRoute}/>);
});
it('Renders results based on user input', async () => {
const searchInput = screen.getByPlaceholderText('Search');
fireEvent.changeText(searchInput, 'ham');
fireEvent(searchInput, 'onEndEditing');
const results = screen.getAllByTestId('foodList');
expect(results).not.toBeNull();
});
});
17 changes: 17 additions & 0 deletions __tests__/unit/FoodSearchScreen.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as React from 'react';
import FoodSearchScreen from '../../Screens/FoodSearchScreen';
import {render, screen, fireEvent,} from '@testing-library/react-native';
describe('FoodSearchScreen', () => {
const thisRoute = { params: 'breakfast' };
beforeEach(() => {
var wrapper = render(<FoodSearchScreen route={thisRoute}/>);
});
it('ham search returns results', async () => {
const searchInput = screen.getByPlaceholderText('Search');
fireEvent.changeText(searchInput, 'ham');
fireEvent(searchInput, 'onEndEditing');
const results = screen.getAllByTestId('foodList');
screen.debug();
expect(results).not.toBeNull();
});
});
61 changes: 61 additions & 0 deletions __tests__/unit/UtilityUnit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { getNutrientValue } from '../../util'

describe('Utility Functions ', () => {
it('retrieve nutrient value from json ', async () => {
let json =
{
"foodNutrients":[
{
"nutrientId":1003,
"nutrientName":"Protein",
"nutrientNumber":"203",
"unitName":"G",
"derivationCode":"LCSL",
"derivationDescription":"Calculated from a less than value per serving size measure",
"derivationId":73,
"value":2.56,
"foodNutrientSourceId":9,
"foodNutrientSourceCode":"12",
"foodNutrientSourceDescription":"Manufacturer's analytical; partial documentation",
"rank":600,
"indentLevel":1,
"foodNutrientId":24024317
},
{
"nutrientId":1004,
"nutrientName":"Total lipid (fat)",
"nutrientNumber":"204",
"unitName":"G",
"derivationCode":"LCCS",
"derivationDescription":"Calculated from value per serving size measure",
"derivationId":70,
"value":15.4,
"foodNutrientSourceId":9,
"foodNutrientSourceCode":"12",
"foodNutrientSourceDescription":"Manufacturer's analytical; partial documentation",
"rank":800,
"indentLevel":1,
"foodNutrientId":24024318,
"percentDailyValue":9
},
{
"nutrientId":1005,
"nutrientName":"Carbohydrate, by difference",
"nutrientNumber":"205",
"unitName":"G",
"derivationCode":"LCCS",
"derivationDescription":"Calculated from value per serving size measure",
"derivationId":70,
"value":69.2,
"foodNutrientSourceId":9,
"foodNutrientSourceCode":"12",
"foodNutrientSourceDescription":"Manufacturer's analytical; partial documentation",
"rank":1110,
"indentLevel":2,
"foodNutrientId":24024319,
"percentDailyValue":9
}]}
result = getNutrientValue(json,"Carbohydrate, by difference")
expect(result).toBe(69.2);
});
});
Loading

0 comments on commit 83c4677

Please sign in to comment.