Skip to content

Commit

Permalink
ci(front): unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Nov 2, 2023
1 parent 1d7028b commit 4ba00c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
29 changes: 1 addition & 28 deletions src/front/components/reports/PhotoCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,9 @@ import {
useAsyncError,
} from '../../services/utilities';
import Spinner from '../Spinner';
import { getCoordinatesFromExif, getDateFromExif } from './photoUtils';

const THUMBNAIL_SIZE = 110;
export function getCoordinatesFromExif(exif) {
if (exif?.GPSLatitude && exif?.GPSLongitude) {
let longitude = parseFloat(exif.GPSLongitude, 10);
let latitude = parseFloat(exif.GPSLatitude, 10);
longitude = longitude < 0 ? longitude : -longitude;

return { latitude, longitude };
}

return null;
}

export function getDateFromExif(exif) {
if (exif?.DateTimeOriginal) {
const parts = exif.DateTimeOriginal.split(' ');
const dateString = `${parts[0].replace(/:/g, '-')}T${parts[1]}Z`;

const date = new Date(dateString);

// exif date string is in the current timezone of the device
// we need to adjust it to UTC
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

return date.toISOString();
}

return null;
}

const displayCameraActivityFailedAlert = () => {
Alert.alert(
Expand Down
28 changes: 28 additions & 0 deletions src/front/components/reports/photoUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export function getCoordinatesFromExif(exif) {
if (exif?.GPSLatitude && exif?.GPSLongitude) {
let longitude = parseFloat(exif.GPSLongitude, 10);
let latitude = parseFloat(exif.GPSLatitude, 10);
longitude = longitude < 0 ? longitude : -longitude;

return { latitude, longitude };
}

return null;
}

export function getDateFromExif(exif) {
if (exif?.DateTimeOriginal) {
const parts = exif.DateTimeOriginal.split(' ');
const dateString = `${parts[0].replace(/:/g, '-')}T${parts[1]}Z`;

const date = new Date(dateString);

// exif date string is in the current timezone of the device
// we need to adjust it to UTC
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());

return date.toISOString();
}

return null;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCoordinatesFromExif, getDateFromExif } from './PhotoCapture';
import { getCoordinatesFromExif, getDateFromExif } from './photoUtils';

describe('PhotoCapture', () => {
describe('getCoordinatesFromExif', () => {
Expand Down

0 comments on commit 4ba00c1

Please sign in to comment.