import React from "react"
import ReactDOM from "react-dom"
import ReactTestUtils from "react-addons-test-utils"

import * as Testdown from "../index.js"

import exampleSuite from "./example-suite.md"

let state

class App extends React.Component {
  render() {
    return (
      <div data-role="app">
        <button data-role="button">Click me</button>
      </div>
    )
  }
}

document.body.innerHTML += '<div id="app"/>'

function setState(newState) {
  state = newState
  ReactDOM.render(<App state={state}/>, app)
}

setState({})

window.test = function test() {
  const suite = Testdown.parseSuite(exampleSuite)
  Testdown.runSuiteSequentially(suite, {
    root: app,
    locate: Testdown.locate,
    ...Testdown.reactConfiguration({ ReactTestUtils }),
  }).then(x => console.info(x))
}

test()

@@ -205,16 +205,98 @@
  state%0A%0A
+const actions = %7B%0A  increment: () =%3E setState(%7B counter: state.counter + 1 %7D),%0A%7D%0A%0A
 class Ap
@@ -390,172 +390,489 @@
    %3C
-button data-role=%22button%22%3EClick me%3C/button%3E%0A      %3C/div%3E%0A    )%0A  %7D%0A%7D%0A%0Adocument.body.innerHTML += '%3Cdiv id=%22app%22/%3E'%0A%0Afunction setState(newState) %7B%0A  state = newState
+span data-role=%22counter%22%3E%0A          %7Bthis.props.counter%7D%0A        %3C/span%3E%0A        %3Cbutton%0A          data-role=%22button%22%0A          onClick=%7Bactions.increment%7D%0A        %3E%0A          Click me%0A        %3C/button%3E%0A      %3C/div%3E%0A    )%0A  %7D%0A%7D%0A%0Adocument.body.innerHTML += '%3Cdiv id=%22app%22/%3E'%0A%0Afunction setState(newState) %7B%0A  location.hash = JSON.stringify(%7B ...state, ...newState %7D)%0A%7D%0A%0Awindow.onhashchange = function(hash) %7B%0A  console.info(%22hashchange%22)%0A  state = JSON.parse(location.hash.substr(1))
 %0A  R
@@ -895,15 +895,12 @@
 App 
-state=%7B
+%7B...
 stat
@@ -917,20 +917,83 @@
 %0A%7D%0A%0A
-setState(%7B%7D)
+if (location.hash) %7B%0A  onhashchange()%0A%7D else %7B%0A  setState(%7B counter: 0 %7D)%0A%7D
 %0A%0Awi
@@ -1248,15 +1248,28 @@
 (x))%0A%7D%0A%0A
+setTimeout(
 test
-(
+, 0
 )%0A

Add state routing to example