 _ = require 'underscore'
+moment = require 'moment'
 
 Builder = require '../../../src/components/task-plan/builder'
 {TaskPlanActions, TaskPlanStore} = require '../../../src/flux/task-plan'


{CourseListingActions, CourseListingStore} = require '../../../src/flux/course-listing'
{CourseStore} = require '../../../src/flux/course'

yesterday = (new Date(Date.now() - 1000 * 3600 * 24)).toString()
tomorrow = (new Date(Date.now() + 1000 * 3600 * 24)).toString()

COURSES = require '../../../api/user/courses.json'
NEW_READING = ExtendBasePlan({id: "_CREATING_1", settings: {page_ids: []}})

      element.setAllPeriods()
      dueAt = TaskPlanStore.getDueAt(NEW_READING.id)
      expect(dueAt).to.be.falsy

  it 'can update open date', ->
    helper(NEW_READING).then ({dom, element}) ->
      element.setOpensAt(dayAfter)
      opensAt = TaskPlanStore.getOpensAt(NEW_READING.id)
      expect(getDateString(opensAt)).to.be.equal(getDateString(dayAfter))

  it 'can update due date', ->
    helper(NEW_READING).then ({dom, element}) ->
      element.setDueAt(dayAfter)
      opensAt = TaskPlanStore.getDueAt(NEW_READING.id)
      expect(getDateString(opensAt)).to.be.equal(getDateString(dayAfter))

  it 'can update open date for individual period', ->
    periodId = COURSES[0].periods[0].id
    helper(NEW_READING).then ({dom, element}) ->
      element.setOpensAt(dayAfter)
      opensAt = TaskPlanStore.getOpensAt(NEW_READING.id)
      expect(getDateString(opensAt)).to.be.falsy
      opensAt = TaskPlanStore.getOpensAt(NEW_READING.id, periodId)
      expect(getDateString(opensAt)).to.be.equal(getDateString(dayAfter))

  it 'can update due date for individual period', ->
    periodId = COURSES[0].periods[0].id
    helper(NEW_READING).then ({dom, element}) ->
      element.setDueAt(tomorrow)
      dueAt = TaskPlanStore.getDueAt(NEW_READING.id)
      expect(getDateString(dueAt)).to.be.falsy
      dueAt = TaskPlanStore.getDueAt(NEW_READING.id, periodId)
      expect(getDateString(dueAt)).to.be.equal(getDateString(tomorrow))

