var test = require('tape')
var React = require('react')
var d = require('..')(React)

var render = function(domTree) {
    return React.renderToStaticMarkup(domTree)
}

var Greeting = React.createClass({
    displayName: 'Greeting',    // Used to auto-generate a "key" prop
    render: function() {
        return React.DOM.div(null, this.props.text || 'hi')
    }
});


test('trees of elements render correctly', function(t) {
    var tree = d('form.foo', {}, [
                  d('input:email'),
                  d('input:password'),
                  d('button:submit', {}, 'Submit')
               ])
    t.equal(render(tree), '<form class="foo"><input type="email">' +
                          '<input type="password"><button type="submit">Submit</button>' +
                          '</form>')
    t.end()
});

test('rendering custom components works correctly', function(t) {
    var tree = d('section#stuff', [
                d(Greeting, { text: 'yo'}),
                d('span', '!')
               ])
    t.equal(render(tree), '<section id="stuff"><div>yo</div><span>!</span></section>')
    t.end()
});

test('rendering custom components works correctly without props', function(t) {
    var tree = d('section#stuff', [
                d(Greeting),
                d('span', '!')
               ])
    t.equal(render(tree), '<section id="stuff"><div>hi</div><span>!</span></section>')
    t.end()
});

test('Readme example', function(t) {
    var noop = function() {}
    var tree = d('form[method=POST]', { onSubmit: noop }, [
        d('h1.form-header', 'Login'),
        d('input:email[name=email]', { placeholder: 'Email' }),
        d('input:password[name=pass]', { placeholder: 'Password' }),
        d(Greeting, { text: 'yo' }),
        d('button:submit', 'Login')
    ])

    var expected = '<form method="POST"><h1 class="form-header">Login</h1><input type="email" name="email" placeholder="Email"><input type="password" name="pass" placeholder="Password"><div>yo</div><button type="submit">Login</button></form>';
    t.equal(render(tree), expected)
    t.end()
});

@@ -848,31 +848,30 @@
 ponents 
-works correctly
+and text nodes
 ', funct
@@ -907,32 +907,63 @@
 ction#stuff', %5B%0A
+                'a greeting:',%0A
                 
@@ -1086,23 +1086,332 @@
 %22stuff%22%3E
-%3Cdiv%3Eyo
+a greeting:%3Cdiv%3Eyo%3C/div%3E%3Cspan%3E!%3C/span%3E%3C/section%3E')%0A    t.end()%0A%7D);%0A%0Atest('rendering custom components works correctly without props', function(t) %7B%0A    var tree = d('section#stuff', %5B%0A                d(Greeting),%0A                d('span', '!')%0A               %5D)%0A    t.equal(render(tree), '%3Csection id=%22stuff%22%3E%3Cdiv%3Ehi
 %3C/div%3E%3Cs

Add test for text nodes that are siblings of custom components.