Commit 23fd3b29846421910e8acb0e1633247331e35fea

Authored by Rafael Manzo
1 parent 763b2381

Graphic JS specs refactored so they do not rely on templates

Showing 1 changed file with 31 additions and 6 deletions   Show diff stats
spec/javascripts/module/graphic_spec.js.coffee
... ... @@ -2,15 +2,40 @@
2 2 #= require spec_helper
3 3 #= require modules
4 4 #= require module/graphic
  5 +#= require sinon
5 6  
6   -describe "Graphic#constructor", ->
7   - describe 'with a visible drawer', ->
8   - before () ->
  7 +describe "Module.Graphic", ->
  8 + describe "constructor", ->
  9 + before ->
9 10 @container = 'container404829'
10 11 @metric_name = 'Pain'
11 12 @module_id = '54405'
12   - $('body').html(JST['templates/metric_results']({container: @container, metric_name: @metric_name, module_id: @module_id}))
13 13  
14   - it "should construct a graphic", ->
15   - graphic = new Module.Graphic(@container, @metric_name, @module_id)
  14 + @drawer = sinon.stub()
  15 + sinon.stub(window, "$")
  16 + $.withArgs("tr#"+@container).returns(@drawer)
16 17  
  18 + context 'when the drawer is hidden', ->
  19 + before ->
  20 + @drawer.is = sinon.stub().withArgs(':hidden').returns(true)
  21 +
  22 + it "should show the drawer and start to load a graphic", ->
  23 + @drawer.slideDown = sinon.spy()
  24 +
  25 + Module.Graphic.prototype.load = sinon.spy()
  26 +
  27 + @graphic = new Module.Graphic(@container, @metric_name, @module_id)
  28 +
  29 + assert.isTrue(@drawer.slideDown.calledOnce)
  30 + assert.isTrue(@graphic.load.calledOnce)
  31 +
  32 + context 'when the drawer is visible', ->
  33 + before ->
  34 + @drawer.is = sinon.stub().withArgs(':hidden').returns(false)
  35 +
  36 + it 'should hide the drawer', ->
  37 + @drawer.slideUp = sinon.spy()
  38 +
  39 + @graphic = new Module.Graphic(@container, @metric_name, @module_id)
  40 +
  41 + assert.isTrue(@drawer.slideUp.calledOnce)
... ...