 
 {CourseActions, CourseStore} = require '../../src/flux/course'
 {TaskActions, TaskStore} = require '../../src/flux/task'
+{TaskStepActions, TaskStepStore} = require '../../src/flux/task-step'
 
 {SinglePractice, Tasks} = require '../../src/components'
 {routes} = require '../../src/router'


  it 'should render next screen when Continue is clicked', (done) ->
    tests = (node) ->
      continueButton = node.querySelector('button.btn-primary')
      introScreenText = node.innerText

      React.addons.TestUtils.Simulate.click(continueButton);
      expect(node.innerText).to.not.be.equal(introScreenText)

      done()

VALID_MODEL = require '../../api/courses/1/practice.json'



routerHelper = (route, tests) ->
  history = new Router.TestLocation([route])

  div = document.createElement('div')
  Router.run routes, history, (Handler, state)->
    router = @
    React.render(<Handler/>, div, ()->
      component = @
      tests?(div, component, state, router, history)
      React.unmountComponentAtNode(div)
    )

tasksHelper = (courseId, tests) ->
  routerHelper('/courses/' + courseId + '/tasks/', tests)

courseHelper = (model, courseId, tests) ->
  # Load practice in CourseStore
  CourseActions.loaded(model, courseId)
  routerHelper('/courses/' + courseId + '/practice/', tests)



exerciseTestActions = 
  fillFreeResponse: (node) ->
    textarea = node.querySelector('textarea')
    textarea.value = 'Test Response'
    React.addons.TestUtils.Simulate.focus(textarea)
    React.addons.TestUtils.Simulate.keyDown(textarea, {key: 'Enter'})
    React.addons.TestUtils.Simulate.change(textarea)

    textarea

  clickContinueButton: (node) ->
    continueButton = node.querySelector('button.btn-primary')
    React.addons.TestUtils.Simulate.click(continueButton)
    continueButton = node.querySelector('button.btn-primary')



describe 'Practice Widget', ->
  beforeEach ->
    CourseActions.reset()

  it 'should load the practice button on the course tasks page', (done) ->
    tests = (node) ->

      buttons = Array.prototype.slice.call(node.querySelectorAll('button.btn-primary'))
      practiceButton = _.last(buttons)
      expect(practiceButton.innerText).to.equal('Practice')
      done()

    tasksHelper(1, tests)
