diff --git a/test/data/native/listViewAndCustomTemplate.rt.v029.js b/test/data/native/listViewAndCustomTemplate.rt.v029.js new file mode 100644 index 0000000..c2aec7b --- /dev/null +++ b/test/data/native/listViewAndCustomTemplate.rt.v029.js @@ -0,0 +1,23 @@ +'use strict'; +var ReactNative = require('react-native'); +var React = require('react'); +var _ = require('lodash'); +module.exports = function () { + function renderRow1(rowData) { + return React.createElement(ReactNative.Text, {}, rowData); + } + function renderRow2(item) { + return React.createElement(ReactNative.Text, {}, item); + } + return React.createElement(ReactNative.View, {}, React.createElement(ReactNative.ListView, { + 'dataSource': this.state.dataSource, + 'renderRow': renderRow1.bind(this) + }), React.createElement(MyComp, { + 'data': [ + 1, + 2, + 3 + ], + 'renderRow': renderRow2.bind(this) + })); +}; \ No newline at end of file diff --git a/test/data/native/listViewTemplate.rt.v029.js b/test/data/native/listViewTemplate.rt.v029.js new file mode 100644 index 0000000..124fd5d --- /dev/null +++ b/test/data/native/listViewTemplate.rt.v029.js @@ -0,0 +1,13 @@ +'use strict'; +var ReactNative = require('react-native'); +var React = require('react'); +var _ = require('lodash'); +module.exports = function () { + function renderRow1(rowData) { + return React.createElement(ReactNative.Text, {}, rowData); + } + return React.createElement(ReactNative.View, {}, React.createElement(ReactNative.ListView, { + 'dataSource': this.state.dataSource, + 'renderRow': renderRow1.bind(this) + })); +}; \ No newline at end of file diff --git a/test/data/native/nativeView.rt.v029.js b/test/data/native/nativeView.rt.v029.js new file mode 100644 index 0000000..9095fa0 --- /dev/null +++ b/test/data/native/nativeView.rt.v029.js @@ -0,0 +1,7 @@ +'use strict'; +var ReactNative = require('react-native'); +var React = require('react'); +var _ = require('lodash'); +module.exports = function () { + return React.createElement(ReactNative.View, {}); +}; \ No newline at end of file diff --git a/test/src/rt.valid.spec.js b/test/src/rt.valid.spec.js index 52168ee..3d7a344 100644 --- a/test/src/rt.valid.spec.js +++ b/test/src/rt.valid.spec.js @@ -1,4 +1,5 @@ 'use strict'; +const _ = require('lodash'); const reactTemplates = require('../../src/reactTemplates'); const testUtils = require('./testUtils'); const readFileNormalized = testUtils.readFileNormalized; @@ -54,9 +55,27 @@ module.exports = { } }, native: true - }; - const files = ['native/nativeView.rt', 'native/listViewTemplate.rt', 'native/listViewAndCustomTemplate.rt']; - testFiles(t, files, options); + }; + const optionsNew = _.assign({nativeTargetVersion: '0.29.0'}, options); + + const files = [ + {source: 'native/nativeView.rt', expected: 'native/nativeView.rt.js', options}, + {source: 'native/listViewTemplate.rt', expected: 'native/listViewTemplate.rt.js', options}, + {source: 'native/listViewAndCustomTemplate.rt', expected: 'native/listViewAndCustomTemplate.rt.js', options}, + {source: 'native/nativeView.rt', expected: 'native/nativeView.rt.v029.js', options: optionsNew}, + {source: 'native/listViewTemplate.rt', expected: 'native/listViewTemplate.rt.v029.js', options: optionsNew}, + {source: 'native/listViewAndCustomTemplate.rt', expected: 'native/listViewAndCustomTemplate.rt.v029.js', options: optionsNew} + ]; + t.plan(files.length); + files.forEach(check); + + function check(testData) { + const filename = path.join(dataPath, testData.source); + const html = readFileNormalized(filename); + const expected = readFileNormalized(path.join(dataPath, testData.expected)); + const actual = reactTemplates.convertTemplateToReact(html, testData.options).replace(/\r/g, '').trim(); + compareAndWrite(t, actual, expected, filename); + } }); test('convert div with all module types', t => {