require '../spec_helper'

describe "Freakset Acceptance", ->

  beforeEach ->
    @stackLine = []
    @freakset = new Freakset()

    @freakset.step "step1", (set) =>
      @stackLine.push(1)
      set.commit()

    @freakset.step "step2", (set) =>
      @stackLine.push(2)
      set.commit()

    @freakset.step "step3", (set) =>
      @stackLine.push(3)
      set.commit()

    @set = null


  it 'should run the stack in the normal order', ->
    @set = @freakset.compile {}

    waitsFor -> !@set.isRunning()

    runs ->
      expect(@stackLine).toEqual [1, 2, 3]


  it 'should modify the stack before compiling it', ->

    @freakset.step { insertAtTop: yes }, (set) =>
      @stackLine.push(0.5)
      set.commit()

    @freakset.group { insertBefore: "step2" }, (set) =>
      set.step (set) =>
        @stackLine.push(1.25)
        set.commit()

      set.step (set) =>
        @stackLine.push(1.75)
        set.commit()

    @freakset.step { insertAfter: "step2" }, (set) =>
      @stackLine.push(2.5)
      set.commit()

    @freakset.step { replace: "step3" }, (set) =>
      @stackLine.push(5)
      set.commit()

    @set = @freakset.compile {}

    waitsFor -> !@set.isRunning()
    runs ->
      expect(@stackLine).toEqual [0.5, 1, 1.25, 1.75, 2, 2.5, 5]
