Skip to content

Commit

Permalink
Merge branch 'service_rewrite_2023' into customize-modes-step2
Browse files Browse the repository at this point in the history
  • Loading branch information
jiji14 authored Jan 12, 2024
2 parents 0e0569e + 8070e76 commit 7eb31dd
Show file tree
Hide file tree
Showing 47 changed files with 1,815 additions and 1,090 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: code coverage
on:
pull_request:
types:
- opened
- reopened
- synchronize
- ready_for_review

jobs:
run-codecov:
if: github.event.pull_request.draft == false
runs-on: macos-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Setup the serve environment
shell: bash -l {0}
run: |
bash setup/setup_serve.sh
- name: Run Jest tests
shell: bash -l {0}
run: |
source setup/activate_serve.sh
npx jest
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage/coverage-final.json
flags: unit
fail_ci_if_error: ${{ github.repository == 'e-mission/e-mission-phone' }}

3 changes: 2 additions & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npx prettier --check www
- run: npx prettier@3.0.3 --check www


5 changes: 0 additions & 5 deletions .github/workflows/serve-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ jobs:
echo "ionic version"
npx ionic --version
- name: Run Jest tests
shell: bash -l {0}
run: |
npx jest
# TODO: figure out how to check that a server started correctly
# - name: Try starting it
# run: npx run serve
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ app-settings.json
www/dist/
config.xml
package.json
coverage/
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
comment:
layout: " diff, flags, files"
behavior: default
require_changes: false
require_base: false
require_head: true
hide_project_coverage: false

4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ module.exports = {
"^.+\\.(ts|tsx|js|jsx)$": "babel-jest"
},
transformIgnorePatterns: [
"node_modules/(?!((jest-)?react-native(-.*)?|@react-native(-community)?)/)"
"node_modules/(?!((enketo-transformer/dist/enketo-transformer/web)|(jest-)?react-native(-.*)?|@react-native(-community)?)/)",
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
moduleDirectories: ["node_modules", "src"],
globals: {"__DEV__": false},
collectCoverage: true,
};
3 changes: 2 additions & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
},
"dependencies": {
"@havesource/cordova-plugin-push": "git+https://github.com/havesource/cordova-plugin-push.git#4.0.0-dev.0",
"@messageformat/core": "^3.2.0",
"@react-navigation/native": "^6.1.7",
"@react-navigation/stack": "^6.3.17",
"@shopify/flash-list": "^1.3.1",
Expand Down Expand Up @@ -141,6 +142,7 @@
"cordova-plugin-x-socialsharing": "6.0.4",
"core-js": "^2.5.7",
"enketo-core": "^6.1.7",
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
"fs-extra": "^9.0.1",
"i18next": "^22.5.0",
Expand All @@ -151,7 +153,6 @@
"klaw-sync": "^6.0.0",
"leaflet": "^1.9.4",
"luxon": "^3.3.0",
"messageformat": "^2.3.0",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"ng-i18next": "^1.0.7",
Expand Down
3 changes: 2 additions & 1 deletion package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"prettier": "3.0.3"
},
"dependencies": {
"@messageformat/core": "^3.2.0",
"@react-navigation/native": "^6.1.7",
"@react-navigation/stack": "^6.3.17",
"@shopify/flash-list": "^1.3.1",
Expand All @@ -72,6 +73,7 @@
"chartjs-plugin-annotation": "^3.0.1",
"core-js": "^2.5.7",
"enketo-core": "^6.1.7",
"enketo-transformer": "^4.0.0",
"fast-xml-parser": "^4.2.2",
"fs-extra": "^9.0.1",
"i18next": "^22.5.0",
Expand All @@ -82,7 +84,6 @@
"klaw-sync": "^6.0.0",
"leaflet": "^1.9.4",
"luxon": "^3.3.0",
"messageformat": "^2.3.0",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"ng-i18next": "^1.0.7",
Expand Down
24 changes: 21 additions & 3 deletions setup/setup_ios_native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,32 @@ source setup/setup_shared.sh
OSX_MAJOR_VERSION=`sw_vers | grep ProductVersion | cut -d ':' -f 2 | cut -d '.' -f 1`
echo "Found OSX major version" $OSX_MAJOR_VERSION

# The Homebrew pac-man is installed in different locations, depending on whether the processor
# is an Intel or Apple Silicone chip. Intel uses x86_64, Apple chips are amd64, so we can
# check the chip type using these hardware platforms.
CHIP_ARC=`uname -m`
INTEL="x86_64"
APPLE_SILICONE="arm64"
WORKING_DIR=""

if [ $CHIP_ARC == $INTEL ]; then
echo "Found "$INTEL" chip"
WORKING_DIR="/usr/local/"
else
if [ $CHIP_ARC == $APPLE_SILICONE ]; then
echo "Found "$APPLE_SILICONE" chip"
WORKING_DIR="/opt/homebrew/"
fi
fi

CURR_RUBY_VERSION=`ruby --version | cut -d ' ' -f 2 | cut -d '.' -f 1-2`
echo "Found ruby version "$CURR_RUBY_VERSION

if [ $CURR_RUBY_VERSION == $RUBY_VERSION ]; then
echo "Found ruby version "$CURR_RUBY_VERSION" expected "$RUBY_VERSION" no need to upgrade"
else
if [ -x /usr/local/bin/brew ]; then
echo "Found brew installation with version" `/usr/local/bin/brew --version`
if [ -x "${WORKING_DIR}/bin/brew" ]; then
echo "Found brew installation with version" ` brew --version`
echo "Installing ruby version to brew" $RUBY_VERSION
brew install ruby@$RUBY_VERSION
else
Expand All @@ -32,6 +50,6 @@ echo "Adding $RUBY_PATH to the path before the install"
export PATH=$RUBY_PATH:$PATH

echo "Installing cocoapods"
/usr/local/opt/ruby@$RUBY_VERSION/bin/gem install --no-document --user-install cocoapods -v $COCOAPODS_VERSION
${WORKING_DIR}/opt/ruby@$RUBY_VERSION/bin/gem install --no-document --user-install cocoapods -v $COCOAPODS_VERSION

source setup/setup_shared_native.sh
7 changes: 6 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ module.exports = {
/* Enketo expects its per-app configuration to be available as 'enketo-config',
so we have to alias it here.
https://github.com/enketo/enketo-core#global-configuration */
'enketo/config': path.resolve(__dirname, 'www/js/config/enketo-config')
'enketo/config': path.resolve(__dirname, 'www/js/config/enketo-config'),
/* enketo-transformer has 'libxslt' as an optional peer dependency.
We don't need it since we are only doing client-side transformations via
enketo-transformer/web (https://github.com/enketo/enketo-transformer#web).
So, we can tell webpack it's ok to ignore libxslt by aliasing it to false. */
'libxslt': false,
},
extensions: ['.web.js', '.jsx', '.tsx', '.ts', '.js'],
},
Expand Down
37 changes: 31 additions & 6 deletions www/__mocks__/cordovaMocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import packageJsonBuild from '../../package.cordovabuild.json';
import fakeConfig from './fakeConfig.json';

export const mockCordova = () => {
window['cordova'] ||= {};
Expand Down Expand Up @@ -28,13 +29,14 @@ export const mockFile = () => {
window['cordova'].file = {
dataDirectory: '../path/to/data/directory',
applicationStorageDirectory: '../path/to/app/storage/directory',
tempDirectory: '../path/to/temp/directory',
};
};

//for consent document
const _storage = {};

export const mockBEMUserCache = () => {
export const mockBEMUserCache = (config?) => {
const _cache = {};
const messages = [];
const mockBEMUserCache = {
Expand Down Expand Up @@ -100,11 +102,20 @@ export const mockBEMUserCache = () => {
);
},
getDocument: (key: string, withMetadata?: boolean) => {
return new Promise<any[]>((rs, rj) =>
setTimeout(() => {
rs(_storage[key]);
}, 100),
);
//returns the config provided as a paramenter to this mock!
if (key == 'config/app_ui_config') {
return new Promise<any>((rs, rj) =>
setTimeout(() => {
rs(config || fakeConfig);
}, 100),
);
} else {
return new Promise<any[]>((rs, rj) =>
setTimeout(() => {
rs(_storage[key]);
}, 100),
);
}
},
isEmptyDoc: (doc) => {
if (doc == undefined) {
Expand All @@ -117,6 +128,20 @@ export const mockBEMUserCache = () => {
return false;
}
},
getAllTimeQuery: () => {
return { key: 'write_ts', startTs: 0, endTs: Date.now() / 1000 };
},
getSensorDataForInterval: (key, tq, withMetadata) => {
if (key == `manual/demographic_survey`) {
return new Promise<any>((rs, rj) =>
setTimeout(() => {
rs({ metadata: { write_ts: '1699897723' }, data: 'completed', time: '01/01/2001' });
}, 100),
);
} else {
return undefined;
}
},
};
window['cordova'] ||= {};
window['cordova'].plugins ||= {};
Expand Down
88 changes: 88 additions & 0 deletions www/__mocks__/fakeConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"version": 1,
"ts": 1655143472,
"server": {
"connectUrl": "https://openpath-test.nrel.gov/api/",
"aggregate_call_auth": "user_only"
},
"intro": {
"program_or_study": "study",
"start_month": "10",
"start_year": "2023",
"program_admin_contact": "K. Shankari",
"deployment_partner_name": "NREL",
"translated_text": {
"en": {
"deployment_partner_name": "NREL",
"deployment_name": "Testing environment for Jest testing",
"summary_line_1": "",
"summary_line_2": "",
"summary_line_3": "",
"short_textual_description": "",
"why_we_collect": "",
"research_questions": ["", ""]
},
"es": {
"deployment_partner_name": "NREL",
"deployment_name": "Ambiente prueba para las pruebas de Jest",
"summary_line_1": "",
"summary_line_2": "",
"summary_line_3": "",
"short_textual_description": "",
"why_we_collect": "",
"research_questions": ["", ""]
}
}
},
"survey_info": {
"surveys": {
"TimeUseSurvey": {
"compatibleWith": 1,
"formPath": "https://raw.githubusercontent.com/sebastianbarry/nrel-openpath-deploy-configs/surveys-info-and-surveys-data/survey-resources/data-json/time-use-survey-form-v9.json",
"labelTemplate": {
"en": "{ erea, plural, =0 {} other {# Employment/Education, } }{ da, plural, =0 {} other {# Domestic, } }",
"es": "{ erea, plural, =0 {} other {# Empleo/Educación, } }{ da, plural, =0 {} other {# Actividades domesticas, }}"
},
"labelVars": {
"da": {
"key": "Domestic_activities",
"type": "length"
},
"erea": {
"key": "Employment_related_a_Education_activities",
"type": "length"
}
},
"version": 9
}
},
"trip-labels": "ENKETO"
},
"display_config": {
"use_imperial": false
},
"profile_controls": {
"support_upload": true,
"trip_end_notification": false
},
"admin_dashboard": {
"overview_users": true,
"overview_active_users": true,
"overview_trips": true,
"overview_signup_trends": true,
"overview_trips_trend": true,
"data_uuids": true,
"data_trips": true,
"data_trips_columns_exclude": [],
"additional_trip_columns": [],
"data_uuids_columns_exclude": [],
"token_generate": true,
"token_prefix": "nrelop",
"map_heatmap": true,
"map_bubble": true,
"map_trip_lines": true,
"push_send": true,
"options_uuids": true,
"options_emails": true
}
}
Loading

0 comments on commit 7eb31dd

Please sign in to comment.