Skip to content

Commit

Permalink
Merge branch 'service_rewrite_2023' into metrics-services-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
shankari authored Dec 3, 2023
2 parents 9a5753b + 54b73f6 commit bc2543b
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 132 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/serve-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ jobs:
run: |
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' }}

# 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

1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ module.exports = {
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
moduleDirectories: ["node_modules", "src"],
collectCoverage: true,
};
10 changes: 6 additions & 4 deletions www/__tests__/LoadMoreButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ describe('LoadMoreButton', () => {
await waitFor(() => {
expect(screen.getByTestId('load-button')).toBeTruthy();
});
});
}, 15000);

it('calls onPressFn when clicked', () => {
it('calls onPressFn when clicked', async () => {
const mockFn = jest.fn();
const { getByTestId } = render(<LoadMoreButton onPressFn={mockFn}>{}</LoadMoreButton>);
const loadButton = getByTestId('load-button');
fireEvent.press(loadButton);
expect(mockFn).toHaveBeenCalled();
});
await waitFor(() => {
expect(mockFn).toHaveBeenCalled();
});
}, 15000);
});
6 changes: 4 additions & 2 deletions www/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
.question.non-select {
display: inline-block;
}
.question input[name*='_date'],
.question input[name*='_time'] {
.question input[name$='Start_date'],
.question input[name$='Start_time'],
.question input[name$='End_date'],
.question input[name$='End_time'] {
width: calc(40vw - 10px);
margin-right: 5px;
display: flex;
Expand Down
1 change: 0 additions & 1 deletion www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ import './js/main.js';
import './js/diary.js';
import './js/diary/services.js';
import './js/survey/enketo/answer.js';
import './js/control/emailService.js';
import './js/plugin/logger.ts';
4 changes: 2 additions & 2 deletions www/js/control/LogPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { useTranslation } from 'react-i18next';
import { FlashList } from '@shopify/flash-list';
import moment from 'moment';
import AlertBar from './AlertBar';
import { sendEmail } from './emailService';

type loadStats = { currentStart: number; gotMaxIndex: boolean; reachedEnd: boolean };

const LogPage = ({ pageVis, setPageVis }) => {
const { t } = useTranslation();
const { colors } = useTheme();
const EmailHelper = getAngularService('EmailHelper');

const [loadStats, setLoadStats] = useState<loadStats>();
const [entries, setEntries] = useState([]);
Expand Down Expand Up @@ -96,7 +96,7 @@ const LogPage = ({ pageVis, setPageVis }) => {
};

const emailLog = function () {
EmailHelper.sendEmail('loggerDB');
sendEmail('loggerDB');
};

const separator = () => <View style={{ height: 8 }} />;
Expand Down
5 changes: 2 additions & 3 deletions www/js/control/ProfileSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useAppConfig from '../useAppConfig';
import AlertBar from './AlertBar';
import DataDatePicker from './DataDatePicker';
import PrivacyPolicyModal from './PrivacyPolicyModal';

import { sendEmail } from './emailService';
import { uploadFile } from './uploadService';
import ActionMenu from '../components/ActionMenu';
import SensedPage from './SensedPage';
Expand Down Expand Up @@ -43,7 +43,6 @@ const ProfileSettings = () => {
const { setPermissionsPopupVis } = useContext(AppContext);

//angular services needed
const EmailHelper = getAngularService('EmailHelper');
const NotificationScheduler = getAngularService('NotificationScheduler');
const ControlHelper = getAngularService('ControlHelper');

Expand Down Expand Up @@ -251,7 +250,7 @@ const ProfileSettings = () => {

const emailLog = function () {
// Passing true, we want to send logs
EmailHelper.sendEmail('loggerDB');
sendEmail('loggerDB');
};

async function updatePrefReminderTime(storeNewVal = true, newTime) {
Expand Down
4 changes: 2 additions & 2 deletions www/js/control/SensedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import { getAngularService } from '../angular-react-helper';
import { useTranslation } from 'react-i18next';
import { FlashList } from '@shopify/flash-list';
import moment from 'moment';
import { sendEmail } from './emailService';

const SensedPage = ({ pageVis, setPageVis }) => {
const { t } = useTranslation();
const { colors } = useTheme();
const EmailHelper = getAngularService('EmailHelper');

/* Let's keep a reference to the database for convenience */
const [DB, setDB] = useState();
const [entries, setEntries] = useState([]);

const emailCache = function () {
EmailHelper.sendEmail('userCacheDB');
sendEmail('userCacheDB');
};

async function updateEntries() {
Expand Down
114 changes: 0 additions & 114 deletions www/js/control/emailService.js

This file was deleted.

52 changes: 52 additions & 0 deletions www/js/control/emailService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import i18next from 'i18next';
import { logDebug, logInfo, logWarn } from '../plugin/logger';

async function hasAccount(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
window['cordova'].plugins['email'].hasAccount((hasAct) => {
resolve(hasAct);
});
});
}

export async function sendEmail(database: string) {
let parentDir = 'unknown';

if (window['cordova'].platformId == 'ios' && !(await hasAccount())) {
alert(i18next.t('email-service.email-account-not-configured'));
return;
}

if (window['cordova'].platformId == 'android') {
parentDir = 'app://databases';
}

if (window['cordova'].platformId == 'ios') {
alert(i18next.t('email-service.email-account-mail-app'));
logDebug(window['cordova'].file.dataDirectory);
parentDir = window['cordova'].file.dataDirectory + '../LocalDatabase';
}

if (parentDir === 'unknown') {
alert('parentDir unexpectedly = ' + parentDir + '!');
}

logInfo('Going to email ' + database);
parentDir = parentDir + '/' + database;

alert(i18next.t('email-service.going-to-email', { parentDir: parentDir }));

let emailConfig = `[email protected]`;

let emailData = {
to: emailConfig,
attachments: [parentDir],
subject: i18next.t('email-service.email-log.subject-logs'),
body: i18next.t('email-service.email-log.body-please-fill-in-what-is-wrong'),
};

window['cordova'].plugins['email'].open(emailData, () => {
logWarn(`Email app closed while sending,
emailData = ${JSON.stringify(emailData)}`);
});
}
1 change: 0 additions & 1 deletion www/js/ngApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ angular
'emission.services',
'emission.plugin.logger',
'emission.splash.referral',
'emission.services.email',
'emission.main',
'pascalprecht.translate',
'LocalStorageModule',
Expand Down
3 changes: 0 additions & 3 deletions www/json/emailConfig.json.sample

This file was deleted.

0 comments on commit bc2543b

Please sign in to comment.