Differential Revision: D3752878

fbshipit-source-id: f248082effde9133dd6a9edf8a2f2cfc05279eab
This commit is contained in:
Mike Grabowski 2016-08-22 13:05:34 -07:00 коммит произвёл Facebook Github Bot 7
Родитель b59fde817f
Коммит 107fc72dab
2 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -0,0 +1,20 @@
'use strict';
jest.autoMockOff();
const makeStringsPatch = require('../../android/patches/makeStringsPatch');
describe('makeStringsPatch', () => {
it('should export a patch with <string> element', () => {
const params = {
keyA: 'valueA',
};
expect(makeStringsPatch(params, 'module').patch)
.toContain('<string moduleConfig="true" name="module_keyA">valueA</string>');
});
it('should export an empty patch if no params given', () => {
expect(makeStringsPatch({}, 'module').patch).toBe('');
});
});

Просмотреть файл

@ -1,14 +1,19 @@
const toCamelCase = require('lodash').camelCase; const toCamelCase = require('lodash').camelCase;
module.exports = function makeStringsPatch(params, prefix) { module.exports = function makeStringsPatch(params, prefix) {
const patch = Object.keys(params).map(param => { const values = Object.keys(params)
const name = toCamelCase(prefix) + '_' + param; .map(param => {
return ' ' + const name = toCamelCase(prefix) + '_' + param;
`<string moduleConfig="true" name="${name}">${params[param]}</string>`; return ' ' +
}).join('\n') + '\n'; `<string moduleConfig="true" name="${name}">${params[param]}</string>`;
});
const patch = values.length > 0
? values.join('\n') + '\n'
: '';
return { return {
pattern: '<resources>\n', pattern: '<resources>\n',
patch: patch, patch,
}; };
}; };