Skip to content

Commit

Permalink
Merge branch 'master-qa' of https://github.com/sap-labs-france/ev-mobile
Browse files Browse the repository at this point in the history
 into ui

# Conflicts:
#	src/App.tsx
#	src/custom-theme/theme/theme-light.tsx
#	src/types/Theme.tsx
  • Loading branch information
AlixH committed Nov 15, 2021
2 parents d9c0ad0 + f8943f6 commit 5d4d0ba
Show file tree
Hide file tree
Showing 15 changed files with 25,437 additions and 20,522 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build CI
name: CI

on:
push:
Expand All @@ -10,7 +10,7 @@ on:
- master-qa

jobs:
build-android:
Build-android:
runs-on: ubuntu-latest

strategy:
Expand All @@ -32,7 +32,7 @@ jobs:
npm run build:prepare
npm run android:assembleDebug
build-ios:
Build-ios:
runs-on: macos-latest

strategy:
Expand All @@ -54,3 +54,27 @@ jobs:
npm run build:prepare
cd ios && xcodebuild -workspace eMobility.xcworkspace -scheme eMobility -configuration Debug CODE_SIGNING_ALLOWED=NO
Test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 14.x ]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: NDK install
run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;22.1.7171670"
- name: npm install
run: npm ci
- name: npm test
run: npm test
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: test-results/**/*.xml
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,7 @@ ios/GoogleService-Info.plist

assets/config.json
*.log

# tests
coverage/
__tests__/__snapshots__/
4 changes: 4 additions & 0 deletions __mocks__/react-native-localize.js
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.
10 changes: 5 additions & 5 deletions __tests__/App-test.tsx
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();
});
212 changes: 212 additions & 0 deletions __tests__/I18nManagerTests.tsx
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')
13 changes: 12 additions & 1 deletion babel.config.js
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" }}],
],
},
}
}
23 changes: 23 additions & 0 deletions jest.config.js
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)',
]
}
Loading

0 comments on commit 5d4d0ba

Please sign in to comment.