-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Alert } from 'react-native'; | ||
import { DefaultOnError } from './DefaultOnError'; | ||
import { TrackerDetailsError } from '../services/TrackTileService'; | ||
|
||
const alertSpy = jest.spyOn(Alert, 'alert'); | ||
|
||
describe('DefaultOnError', () => { | ||
it('should display user error message if provided', () => { | ||
const error = new TrackerDetailsError(); | ||
error.userErrorMessage = 'unit test'; | ||
DefaultOnError(error); | ||
expect(alertSpy).toHaveBeenCalledWith(error.userErrorMessage); | ||
}); | ||
|
||
it('should display generic error message if userMessage not provided', () => { | ||
const error = new Error(); | ||
DefaultOnError(error); | ||
expect(alertSpy).toHaveBeenCalledWith( | ||
'Error saving tracker details. Please try again.', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Alert } from 'react-native'; | ||
import { t } from '../../../../lib/i18n'; | ||
import { TrackerDetailsError } from '../services/TrackTileService'; | ||
|
||
export function DefaultOnError(error: any) { | ||
console.warn('Error in tracker details', error); | ||
let message = t( | ||
'generic-tracker-error-message', | ||
'Error saving tracker details. Please try again.', | ||
); | ||
if (error instanceof TrackerDetailsError && error.userErrorMessage) { | ||
message = error.userErrorMessage; | ||
} | ||
Alert.alert(message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import TrackTileTrackerScreen from './TrackTileTrackerScreen'; | ||
import { | ||
TRACKER_CODE_SYSTEM, | ||
TrackTileServiceProvider, | ||
} from '../components/TrackTile/main'; | ||
import { TrackerDetails } from '../components/TrackTile/TrackerDetails/TrackerDetails'; | ||
|
||
jest.mock('../components/TrackTile/TrackerDetails/TrackerDetails', () => ({ | ||
TrackerDetails: jest.fn(() => null), | ||
})); | ||
|
||
const TrackerDetailsMock = TrackerDetails as any as jest.Mock; | ||
const navSetOptions = jest.fn(); | ||
const tracker = { | ||
account: 'account-id', | ||
description: 'desc', | ||
lifePoints: 0, | ||
installed: true, | ||
system: TRACKER_CODE_SYSTEM, | ||
id: 'activity', | ||
metricId: 'activity', | ||
name: 'activity', | ||
icon: 'running', | ||
color: '#CD335E', | ||
resourceType: 'Procedure', | ||
code: 'activity', | ||
order: 1, | ||
units: [ | ||
{ | ||
code: 'activity', | ||
default: true, | ||
display: 'min', | ||
system: 'http://lifeomic.com/fhir/track-tile-pillar-value/activity', | ||
target: 30, | ||
unit: 'min', | ||
}, | ||
], | ||
}; | ||
|
||
const valuesContext = {}; | ||
const referenceDate = {}; | ||
const navigation: any = { setOptions: navSetOptions }; | ||
const route: any = { | ||
params: { | ||
tracker, | ||
valuesContext, | ||
referenceDate, | ||
}, | ||
}; | ||
|
||
const renderInContext = () => { | ||
return render( | ||
<TrackTileTrackerScreen navigation={navigation as any} route={route} />, | ||
{ | ||
wrapper: ({ children }) => ( | ||
<TrackTileServiceProvider value={{} as any}> | ||
{children} | ||
</TrackTileServiceProvider> | ||
), | ||
}, | ||
); | ||
}; | ||
|
||
describe('TrackTileTrackerScreen', () => { | ||
it('should render', () => { | ||
renderInContext(); | ||
expect(TrackerDetailsMock).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters