File tree Expand file tree Collapse file tree 2 files changed +31
-6
lines changed
Expand file tree Collapse file tree 2 files changed +31
-6
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ jest . autoMockOff ( ) ;
4+
5+ const makeStringsPatch = require ( '../../android/patches/makeStringsPatch' ) ;
6+
7+ describe ( 'makeStringsPatch' , ( ) => {
8+ it ( 'should export a patch with <string> element' , ( ) => {
9+ const params = {
10+ keyA : 'valueA' ,
11+ } ;
12+
13+ expect ( makeStringsPatch ( params , 'module' ) . patch )
14+ . toContain ( '<string moduleConfig="true" name="module_keyA">valueA</string>' ) ;
15+ } ) ;
16+
17+ it ( 'should export an empty patch if no params given' , ( ) => {
18+ expect ( makeStringsPatch ( { } , 'module' ) . patch ) . toBe ( '' ) ;
19+ } ) ;
20+ } ) ;
Original file line number Diff line number Diff line change 11const toCamelCase = require ( 'lodash' ) . camelCase ;
22
33module . exports = function makeStringsPatch ( params , prefix ) {
4- const patch = Object . keys ( params ) . map ( param => {
5- const name = toCamelCase ( prefix ) + '_' + param ;
6- return ' ' +
7- `<string moduleConfig="true" name="${ name } ">${ params [ param ] } </string>` ;
8- } ) . join ( '\n' ) + '\n' ;
4+ const values = Object . keys ( params )
5+ . map ( param => {
6+ const name = toCamelCase ( prefix ) + '_' + param ;
7+ return ' ' +
8+ `<string moduleConfig="true" name="${ name } ">${ params [ param ] } </string>` ;
9+ } ) ;
10+
11+ const patch = values . length > 0
12+ ? values . join ( '\n' ) + '\n'
13+ : '' ;
914
1015 return {
1116 pattern : '<resources>\n' ,
12- patch : patch ,
17+ patch,
1318 } ;
1419} ;
You can’t perform that action at this time.
0 commit comments