Skip to content

Commit 107fc72

Browse files
grabbouFacebook Github Bot 7
authored andcommitted
Differential Revision: D3752878 fbshipit-source-id: f248082effde9133dd6a9edf8a2f2cfc05279eab
1 parent b59fde8 commit 107fc72

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
});
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
const toCamelCase = require('lodash').camelCase;
22

33
module.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
};

0 commit comments

Comments
 (0)