From fb8d4028dd012e1decfc6d741afd7b607f8eb524 Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Thu, 7 Jul 2016 13:52:23 +0200 Subject: [PATCH] Test for react-native 0.29.0 --- .../listViewAndCustomTemplate.rt.v029.js | 23 +++++++++++++++++ test/data/native/listViewTemplate.rt.v029.js | 13 ++++++++++ test/data/native/nativeView.rt.v029.js | 7 ++++++ test/src/rt.valid.spec.js | 25 ++++++++++++++++--- 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 test/data/native/listViewAndCustomTemplate.rt.v029.js create mode 100644 test/data/native/listViewTemplate.rt.v029.js create mode 100644 test/data/native/nativeView.rt.v029.js 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 => {