Skip to content

Commit

Permalink
Merge branch 'expand-enketo-helper' of https://github.com/Abby-Wheeli…
Browse files Browse the repository at this point in the history
…s/e-mission-phone into expand-enketo-helper
  • Loading branch information
JGreenlee committed Nov 21, 2023
2 parents 828ee12 + becc4af commit e414c5c
Show file tree
Hide file tree
Showing 99 changed files with 3,075 additions and 2,086 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ www/dist
www/manual_lib
www/json

# Ignore all HTML files:
**/*.html

# This is the pattern to check only www directory
# Ignore all
/*
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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"],
Expand Down
3 changes: 2 additions & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.2",
"cordova-plugin-em-settings": "git+https://github.com/e-mission/cordova-connection-settings.git#v1.2.3",
"cordova-plugin-em-unifiedlogger": "git+https://github.com/e-mission/cordova-unified-logger.git#v1.3.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.6",
"cordova-plugin-em-usercache": "git+https://github.com/e-mission/cordova-usercache.git#v1.1.7",
"cordova-plugin-email-composer": "git+https://github.com/katzer/cordova-plugin-email-composer.git#0.10.1",
"cordova-plugin-file": "8.0.0",
"cordova-plugin-inappbrowser": "5.0.0",
Expand All @@ -142,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 Down
1 change: 1 addition & 0 deletions package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,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 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
75 changes: 70 additions & 5 deletions www/__mocks__/cordovaMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,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 @@ -66,6 +66,7 @@ export const mockBEMUserCache = () => {
return new Promise<void>((rs, rj) =>
setTimeout(() => {
for (let p in _cache) delete _cache[p];
for (let doc in _storage) delete _storage[doc];
rs();
}, 100),
);
Expand Down Expand Up @@ -100,13 +101,11 @@ export const mockBEMUserCache = () => {
);
},
getDocument: (key: string, withMetadata?: boolean) => {
// this was mocked specifically for enketoHelper's use, could be expanded if needed
const fakeSurveyConfig = fakeConfig;

//returns the config provided as a paramenter to this mock!
if (key == 'config/app_ui_config') {
return new Promise<any>((rs, rj) =>
setTimeout(() => {
rs(fakeSurveyConfig);
rs(config || fakeConfig);
}, 100),
);
} else {
Expand All @@ -128,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 All @@ -141,7 +154,59 @@ export const mockBEMDataCollection = () => {
_storage['config/consent'] = consentDoc;
}, 100);
},
getConfig: () => {
return new Promise<any>((rs, rj) => {
setTimeout(() => {
rs({ ios_use_remote_push_for_sync: true });
}, 100);
});
},
handleSilentPush: () => {
return new Promise<void>((rs, rj) =>
setTimeout(() => {
rs();
}, 100),
);
},
};
window['cordova'] ||= {};
window['cordova'].plugins.BEMDataCollection = mockBEMDataCollection;
};

export const mockBEMServerCom = () => {
const mockBEMServerCom = {
postUserPersonalData: (actionString, typeString, updateDoc, rs, rj) => {
setTimeout(() => {
console.log('set in mock', updateDoc);
_storage['user_data'] = updateDoc;
rs();
}, 100);
},

getUserPersonalData: (actionString, rs, rj) => {
setTimeout(() => {
rs(_storage['user_data']);
}, 100);
},
};
window['cordova'].plugins.BEMServerComm = mockBEMServerCom;
};

let _url_stash = '';

export const mockInAppBrowser = () => {
const mockInAppBrowser = {
open: (url: string, mode: string, options: {}) => {
_url_stash = url;
},
};
window['cordova'].InAppBrowser = mockInAppBrowser;
};

export const getURL = () => {
return _url_stash;
};

export const clearURL = () => {
_url_stash = '';
};
16 changes: 16 additions & 0 deletions www/__mocks__/globalMocks.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
export const mockLogger = () => {
window['Logger'] = { log: console.log };
};

let alerts = [];

export const mockAlert = () => {
window['alert'] = (message) => {
alerts.push(message);
};
};

export const clearAlerts = () => {
alerts = [];
};

export const getAlerts = () => {
return alerts;
};
33 changes: 33 additions & 0 deletions www/__mocks__/pushNotificationMocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let notifSettings;
let onList: any = {};
let called = null;

export const mockPushNotification = () => {
window['PushNotification'] = {
init: (settings: Object) => {
notifSettings = settings;
return {
on: (event: string, callback: Function) => {
onList[event] = callback;
},
finish: (content: any, errorFcn: Function, notID: any) => {
called = notID;
},
};
},
};
};

export const clearNotifMock = function () {
notifSettings = {};
onList = {};
called = null;
};

export const getOnList = function () {
return onList;
};

export const getCalled = function () {
return called;
};
2 changes: 1 addition & 1 deletion www/__tests__/commHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockLogger } from '../__mocks__/globalMocks';
import { fetchUrlCached } from '../js/commHelper';
import { fetchUrlCached } from '../js/services/commHelper';

mockLogger();

Expand Down
Loading

0 comments on commit e414c5c

Please sign in to comment.