forked from sap-labs-france/ev-mobile
-
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.
Merge pull request sap-labs-france#524 from sap-labs-france/tests
Working test config with first tests
- Loading branch information
Showing
18 changed files
with
25,440 additions
and
20,525 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,7 @@ ios/GoogleService-Info.plist | |
|
||
assets/config.json | ||
*.log | ||
|
||
# tests | ||
coverage/ | ||
__tests__/__snapshots__/ |
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,4 @@ | ||
const findBestAvailableLanguage = () => null; | ||
const usesMetricSystem = () => null; | ||
|
||
export { findBestAvailableLanguage, usesMetricSystem }; |
Empty file.
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import 'react-native'; | ||
|
||
import React from 'react'; | ||
// Note: test renderer must be required after react-native. | ||
import renderer from 'react-test-renderer'; | ||
|
||
import App from '../App'; | ||
import { View } from 'react-native'; | ||
|
||
it('renders correctly', () => { | ||
renderer.create(<App />); | ||
test('renders correctly', () => { | ||
const tree = renderer.create(<View />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
expect(3).toBeTruthy(); | ||
}); |
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,212 @@ | ||
// Note: test renderer must be required after react-native. | ||
|
||
jest.mock('../src/utils/Utils'); | ||
import I18nManager, { | ||
FormatNumberOptions, | ||
MetricCompactEnum, | ||
NumberFormatCompactStyleEnum, | ||
NumberFormatNotationEnum | ||
} from '../src/I18n/I18nManager'; | ||
|
||
test('computeMetricCompact', () => { | ||
expect(I18nManager.computeMetricCompact(1000)).toEqual(MetricCompactEnum.KILO); | ||
expect(I18nManager.computeMetricCompact(10000)).toEqual(MetricCompactEnum.KILO); | ||
expect(I18nManager.computeMetricCompact(100000)).toEqual(MetricCompactEnum.KILO); | ||
expect(I18nManager.computeMetricCompact(1000000)).toEqual(MetricCompactEnum.MEGA); | ||
expect(I18nManager.computeMetricCompact(10000000)).toEqual(MetricCompactEnum.MEGA); | ||
expect(I18nManager.computeMetricCompact(100000000)).toEqual(MetricCompactEnum.MEGA); | ||
expect(I18nManager.computeMetricCompact(1000000000)).toEqual(MetricCompactEnum.GIGA); | ||
expect(I18nManager.computeMetricCompact(10000000000)).toEqual(MetricCompactEnum.GIGA); | ||
expect(I18nManager.computeMetricCompact(100000000000)).toEqual(MetricCompactEnum.GIGA); | ||
expect(I18nManager.computeMetricCompact(1000000000000)).toEqual(MetricCompactEnum.TERA); | ||
expect(I18nManager.computeMetricCompact(10000000000000)).toEqual(MetricCompactEnum.TERA); | ||
expect(I18nManager.computeMetricCompact(100000000000000)).toEqual(MetricCompactEnum.TERA); | ||
}); | ||
|
||
test('getNumberFormatPartValue', () => { | ||
const numberFormatParts = [ | ||
{type: 'currency', value: 'EUR'}, | ||
{type: 'compact', value: 'million'}, | ||
{type: 'integer', 'value': '756000000'} | ||
] | ||
expect(I18nManager.getNumberFormatPartValue(numberFormatParts as Intl.NumberFormatPart[], 'currency')).toEqual('EUR'); | ||
expect(I18nManager.getNumberFormatPartValue(numberFormatParts as Intl.NumberFormatPart[], 'compact')).toEqual('million'); | ||
expect(I18nManager.getNumberFormatPartValue(numberFormatParts as Intl.NumberFormatPart[], 'integer')).toEqual('756000000'); | ||
expect(I18nManager.getNumberFormatPartValue(numberFormatParts as Intl.NumberFormatPart[], 'group')).toEqual(undefined); | ||
}); | ||
|
||
test('concatenateNumberFormatParts', () => { | ||
const numberFormatParts = [ | ||
{type: 'minusSign', 'value': '-'}, | ||
{type: 'integer', 'value': '756'}, | ||
{type: 'group', 'value': ' '}, | ||
{type: 'integer', 'value': '000'}, | ||
{type: 'group', 'value': ' '}, | ||
{type: 'integer', 'value': '000'}, | ||
{type: 'decimal', 'value': ','}, | ||
{type: 'fraction', 'value': '234'}, | ||
{type: 'unit', 'value': 'Watt'} | ||
] | ||
expect(I18nManager.concatenateNumberFormatParts(numberFormatParts as Intl.NumberFormatPart[])).toEqual('-756 000 000,234') | ||
}) | ||
|
||
test('formatNumberWithCompacts MetricShortCompact', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactStyle: NumberFormatCompactStyleEnum.METRIC, | ||
compactDisplay: 'short', | ||
} | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('k'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('M'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('G'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000000.457, formatNumberOptions); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('T'); | ||
}); | ||
|
||
test('formatNumberWithCompacts FinanceShortCompact', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactStyle: NumberFormatCompactStyleEnum.FINANCE, | ||
compactDisplay: 'short', | ||
} | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions, 'en'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('K'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('k'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('mil'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'en'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('M'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('M'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('M'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'en'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('B'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('Md'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('mil\u00a0M'); | ||
}); | ||
|
||
test('formatNumberWithCompacts FinanceLongCompact', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactStyle: NumberFormatCompactStyleEnum.FINANCE, | ||
compactDisplay: 'long', | ||
} | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('thousand'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('mille'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('mil'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'en'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('million'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('millions'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('millones'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'en'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('billion'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'fr'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('milliards'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(127486000000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('127'); | ||
expect(formattedNumber?.compact).toEqual('mil millones'); | ||
}); | ||
|
||
test('formatNumberWithCompacts CompactThreshold', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactDisplay: 'long', | ||
compactThreshold: 1200000 | ||
} | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(1000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1000,457'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(1000000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1.000.000,457'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(1200000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1,2'); | ||
}); | ||
|
||
test('formatNumberWithCompacts MaxDigits', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactStyle: NumberFormatCompactStyleEnum.FINANCE, | ||
compactDisplay: 'long', | ||
maximumFractionDigits: 0 | ||
} as FormatNumberOptions | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(1200000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1'); | ||
expect(formattedNumber?.compact).toEqual('millón'); | ||
|
||
formatNumberOptions.maximumFractionDigits = 9 | ||
formattedNumber = I18nManager.formatNumberWithCompacts(1200000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1,200000457'); | ||
expect(formattedNumber?.compact).toEqual('millones'); | ||
}); | ||
|
||
test('formatNumberWithCompacts MinDigits', () => { | ||
const formatNumberOptions = { | ||
notation: NumberFormatNotationEnum.COMPACT, | ||
compactStyle: NumberFormatCompactStyleEnum.FINANCE, | ||
compactDisplay: 'long', | ||
maximumFractionDigits: 9, | ||
minimumFractionDigits: 3 | ||
} as FormatNumberOptions | ||
let formattedNumber = I18nManager.formatNumberWithCompacts(1200000.00, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1,200'); | ||
expect(formattedNumber?.compact).toEqual('millones'); | ||
|
||
formattedNumber = I18nManager.formatNumberWithCompacts(1200000.457, formatNumberOptions, 'es'); | ||
expect(formattedNumber?.value).toEqual('1,200000457'); | ||
expect(formattedNumber?.compact).toEqual('millones'); | ||
}); | ||
|
||
jest.unmock('../src/utils/Utils') |
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
module.exports = { | ||
presets: ['module:metro-react-native-babel-preset'], | ||
}; | ||
plugins: [ | ||
"@babel/plugin-transform-runtime", | ||
["@babel/plugin-proposal-class-properties", { loose: true }], | ||
], | ||
env: { | ||
testing: { | ||
presets: [ | ||
[ "@babel/plugin-transform-runtime", { targets: { node: "current" }}], | ||
], | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
module.exports = { | ||
preset: 'react-native', | ||
reporters: [ "default", "jest-junit" ], | ||
testResultsProcessor: "jest-junit", | ||
globals: { | ||
'ts-jest': { | ||
// Tell ts-jest about our typescript config. | ||
tsconfig: 'tsconfig.spec.json' | ||
}, | ||
}, | ||
// Transforms tell jest how to process our non-javascript files. | ||
// Here we're using babel for .js and .jsx files, and ts-jest for | ||
// .ts and .tsx files. You *can* just use babel-jest for both, if | ||
// you already have babel set up to compile typescript files. | ||
transform: { | ||
"^.+\\.jsx?$": "babel-jest", | ||
"^.+\\.js?$": "babel-jest", | ||
'^.+\\.tsx?$': 'ts-jest', | ||
'^.+\\.ts?$': 'ts-jest' | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
// Tells Jest what folders to ignore for tests | ||
testPathIgnorePatterns: [`node_modules`, `\\.cache`], | ||
transformIgnorePatterns: [ | ||
'node_modules/(?!(jest-)?@?react-native|@react-native-community|@react-navigation)', | ||
] | ||
} |
Oops, something went wrong.