From 5d41421e81a1b1e1aafdbcf7655826451cbe208d Mon Sep 17 00:00:00 2001 From: ido Date: Mon, 10 Nov 2014 16:23:17 +0200 Subject: [PATCH] more tests --- src/reactTemplates.js | 5 ++--- test/data/div.html | 3 +++ test/data/div.js | 6 ++++++ test/data/test.html | 29 ++++++++++++++++++++++++- test/data/test.js | 49 ++++++++++++++++++++++++++++++++++++++++++- test/src/test.js | 20 +++++++++++------- 6 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 test/data/div.html create mode 100644 test/data/div.js diff --git a/src/reactTemplates.js b/src/reactTemplates.js index 94c7157..aa02fba 100644 --- a/src/reactTemplates.js +++ b/src/reactTemplates.js @@ -53,7 +53,7 @@ function convertText(txt) { var start = txt.indexOf('{'); var pre = txt.substr(0,start); if (pre) { - res += (first?"":"+") + JSON.stringify(pre); + res += (first ? "" : "+") + JSON.stringify(pre); first = false; } var curlyCounter = 1; @@ -175,9 +175,8 @@ function convertHtmlToReact(node, context) { } else if (node.type === "text") { if (node.data.trim()) { return convertText(node.data.trim()); - } else { - return ""; } + return ""; } } diff --git a/test/data/div.html b/test/data/div.html new file mode 100644 index 0000000..5ab1014 --- /dev/null +++ b/test/data/div.html @@ -0,0 +1,3 @@ + +
+
\ No newline at end of file diff --git a/test/data/div.js b/test/data/div.js new file mode 100644 index 0000000..16fd325 --- /dev/null +++ b/test/data/div.js @@ -0,0 +1,6 @@ +define([ + 'react', + 'lodash' +], function (React, _) { + return React.DOM.div.apply(this, _.flatten([{}].concat([]))); +}); \ No newline at end of file diff --git a/test/data/test.html b/test/data/test.html index a09f66a..c6db047 100644 --- a/test/data/test.html +++ b/test/data/test.html @@ -1,4 +1,31 @@ -
+
+
+
{category.name}
+
+
+
+
{entry.name}
+
+
    +
  • +
    {node.title}
    +
      +
    • +
      {child.title}
      +
    • +
    +
  • +
+
+
+
+
+ + +
\ No newline at end of file diff --git a/test/data/test.js b/test/data/test.js index 16fd325..784fd3f 100644 --- a/test/data/test.js +++ b/test/data/test.js @@ -2,5 +2,52 @@ define([ 'react', 'lodash' ], function (React, _) { - return React.DOM.div.apply(this, _.flatten([{}].concat([]))); + function generated1() { + this.props.controller.onQueryItemClicked(entry); + } + function generated2() { + this.props.controller.onTreeItemClicked(entry, node); + } + function generated3() { + this.props.controller.onTreeItemClicked(entry, child); + } + function generated4() { + this.openAddItem(typeInfo.collectionId, typeInfo.typeName); + } + return React.DOM.div.apply(this, _.flatten([{ 'className': 'nav' }].concat([React.DOM.div.apply(this, _.flatten([{ 'jsx-repeat': 'category in this.props.model.nav' }].concat([ + React.DOM.div.apply(this, _.flatten([{ 'className': 'category-title' }].concat([category.name]))), + React.DOM.div.apply(this, _.flatten([{ 'className': 'category-entries' }].concat([React.DOM.div.apply(this, _.flatten([{ 'jsx-if': 'category.items.length > 0' }].concat([React.DOM.div.apply(this, _.flatten([{ 'jsx-repeat': 'entry in category.items' }].concat([ + React.DOM.div.apply(this, _.flatten([{ + 'jsx-if': 'entry.type == \'query\'', + 'className': this.cs({ + selected: entry.name == this.props.model.selected.name, + navlink: true + }), + 'onClick': generated1.bind(this) + }].concat([entry.name]))), + React.DOM.div.apply(this, _.flatten([{ 'jsx-if': 'entry.type == \'tree\'' }].concat([React.DOM.ul.apply(this, _.flatten([{}].concat([React.DOM.li.apply(this, _.flatten([{ 'jsx-repeat': 'node in entry.model' }].concat([ + React.DOM.div.apply(this, _.flatten([{ + 'onClick': generated2.bind(this), + 'className': this.cs({ + selected: this.isNodeSelected(entry, node), + treelink1: true + }) + }].concat([node.title]))), + React.DOM.ul.apply(this, _.flatten([{ 'jsx-if': 'node.children.length > 0' }].concat([React.DOM.li.apply(this, _.flatten([{ + 'jsx-repeat': 'child in node.children', + 'onClick': generated3.bind(this) + }].concat([React.DOM.div.apply(this, _.flatten([{ + 'className': this.cs({ + selected: this.isNodeSelected(entry, child), + treelink2: true + }) + }].concat([child.title])))])))]))) + ])))])))]))) + ])))])))]))), + React.DOM.button.apply(this, _.flatten([{ + 'className': 'new-item-btn', + 'jsx-repeat': 'typeInfo in category.newTypes', + 'onClick': generated4.bind(this) + }].concat([React.DOM.span.apply(this, _.flatten([{}].concat(['Add ' + typeInfo.friendlyName])))]))) + ])))]))); }); \ No newline at end of file diff --git a/test/src/test.js b/test/src/test.js index a62d29d..aa07700 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -8,11 +8,17 @@ var path = require('path'); var dataPath = path.resolve(__dirname, '..', 'data'); test('timing test', function (t) { - t.plan(1); + t.plan(2); + + check('div.html'); + check('test.html'); + + function check(testFile) { + var filename = path.join(dataPath, testFile); + var html = fs.readFileSync(filename).toString(); + var expected = fs.readFileSync(filename.replace(".html", ".js")).toString(); + var actual = reactTemplates.convertTemplateToReact(html); + t.equal(actual, expected); + } +}); - var filename = path.join(dataPath, 'test.html'); - var html = fs.readFileSync(filename).toString(); - var expected = fs.readFileSync(filename.replace(".html", ".js")).toString(); - var actual = reactTemplates.convertTemplateToReact(html); - t.equal(actual, expected); -}); \ No newline at end of file