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

Rewrite answer.js into enketoHelper.ts #1063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5d6fb5a
Merge remote-tracking branch 'JGreenlee/rewrite-services-sept2023' in…
Oct 11, 2023
0815334
draft enketoHelper tests
Oct 11, 2023
43b8386
convert answer.js into enketoHelper
Oct 11, 2023
9840b5a
exclude platforms
Oct 11, 2023
1eaf8b8
add more tests
Oct 11, 2023
74b8471
remove answer.js
Oct 11, 2023
d259799
adding tests for resolveTimestamps
Oct 12, 2023
11a3df6
testing for _lazyLoadConfig
Oct 12, 2023
bc42845
attempting to add more tests
Oct 12, 2023
608d97d
update messageformat plugin
Oct 13, 2023
8b901f6
start to configure i18next for tests
Oct 13, 2023
cea96dd
update the message format import
Oct 13, 2023
b7f6d68
updates to testing
Oct 13, 2023
75a0371
updates to tests
Oct 13, 2023
09f21bc
update types
Oct 13, 2023
496eeb5
merge changes from #1049
Oct 13, 2023
e7fe7a8
don't mock i18n, use the real thing
Oct 13, 2023
70f98cd
set up baseline testing for resolveLabels
Oct 13, 2023
719403a
rework getInstanceStr tests
Oct 13, 2023
252e42f
tests for saveResponse
Oct 13, 2023
9dc9384
take out old console.log
Oct 13, 2023
4d24d3e
update types
Oct 13, 2023
1977258
carry through async nature of the label functions
Oct 16, 2023
a269a55
correct precision of enketo dates
Oct 16, 2023
e12ee3d
resolve vscode errors
Oct 16, 2023
ff30d32
update test
Oct 16, 2023
0346ac0
Merge branch 'service_rewrite_2023' into expand-enketo-helper
JGreenlee Oct 16, 2023
d38745b
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
JGreenlee Oct 16, 2023
c05b204
Merge branch 'expand-enketo-helper' of https://github.com/Abby-Wheeli…
JGreenlee Oct 16, 2023
4435e99
Merge branch 'service_rewrite_2023' into expand-enketo-helper
JGreenlee Oct 17, 2023
6ef2725
move the declaration of _config
Oct 17, 2023
b480279
move the fake config, add on
Oct 17, 2023
1138d29
resolve merge conflicts by merging upstream
Oct 20, 2023
9c700df
Merge remote-tracking branch 'upstream/service_rewrite_2023' into exp…
Oct 30, 2023
ee4b390
merge upstream, resolve conflicts, verify tests
Nov 2, 2023
09021f7
merge in prettier changes, resolve conflicts, run again locally
Nov 2, 2023
01f8d2a
Merge remote-tracking branch 'upstream/service_rewrite_2023' into exp…
Nov 2, 2023
3af741c
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
JGreenlee Nov 8, 2023
159d665
support client-side transformation for enketo XMLs
JGreenlee Nov 8, 2023
2b72850
rename + move fetchSurvey to enketoHelper.ts
JGreenlee Nov 8, 2023
1008f58
merge upstream, resolve conflicts
Nov 10, 2023
e230420
prettify merge conflicted file
Nov 10, 2023
da4947d
add exception to transform
Nov 10, 2023
7521f67
merge upstream, resolve, test
Nov 10, 2023
2459821
lingering merge conflict
Nov 10, 2023
0890e23
re-run prettier after merging
Nov 10, 2023
b33ce28
Merge branch 'service_rewrite_2023' of https://github.com/e-mission/e…
JGreenlee Nov 13, 2023
7df44e9
cleanup enketo after merge
JGreenlee Nov 13, 2023
4499e24
test remaining function
Nov 13, 2023
4a000fc
re-run prettier
Nov 13, 2023
ebaa1e6
fix issue with filter
Nov 13, 2023
8f7c674
add a test case
Nov 17, 2023
7ec575e
note the issue
Nov 18, 2023
8b3ab76
check for key before resolving with this information
Nov 18, 2023
d123b4f
remove _lazyLoadConfig, move types
Nov 18, 2023
100eefb
test the version
Nov 18, 2023
22decbf
make config a parameter to mockBEMUserCache
Nov 18, 2023
80aa5ea
more test cases!!
Nov 18, 2023
0ef1db8
add survey_info to the AppConfig Type
Abby-Wheelis Nov 19, 2023
10b9546
make config optional param
Abby-Wheelis Nov 19, 2023
fd01034
fallback to fakeConfig
Nov 19, 2023
83a773e
prettier types
Nov 19, 2023
becc4af
enketoHelper: expand typings for resolveTimestamps
JGreenlee Nov 20, 2023
828ee12
enketoHelper: fix error if timestamps are null
JGreenlee Nov 21, 2023
e414c5c
Merge branch 'expand-enketo-helper' of https://github.com/Abby-Wheeli…
JGreenlee Nov 21, 2023
aee8738
Merge branch 'service_rewrite_2023' into expand-enketo-helper
shankari Nov 23, 2023
b900d1e
Merge branch 'service_rewrite_2023' into expand-enketo-helper
shankari Dec 3, 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
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +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
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
36 changes: 30 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 @@ -34,7 +35,7 @@ export const mockFile = () => {
//for consent document
const _storage = {};

export const mockBEMUserCache = () => {
export const mockBEMUserCache = (config?) => {
const _cache = {};
const messages = [];
const mockBEMUserCache = {
Expand Down Expand Up @@ -100,11 +101,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 +127,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
}
}
29 changes: 29 additions & 0 deletions www/__mocks__/messageFormatMocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//call signature MessageFormat.compile(templage)(vars);
//in - template an vars -- {... pca: 0, ...}
//out - 1 Personal Care,

export default class MessageFormat {
constructor(locale: string) {}

compile(message: string) {
return (vars: {}) => {
let label = '';
const brokenList = message.split('}{');
console.log(brokenList);

for (let key in vars) {
brokenList.forEach((item) => {
let brokenItem = item.split(',');
if (brokenItem[0] == key) {
let getLabel = brokenItem[2].split('#');
console.log(getLabel);
label = vars[key] + ' ' + getLabel[1];
return label;
}
});
}
};
}
}

exports.MessageFormat = MessageFormat;
Loading
Loading