From 23fd3b29846421910e8acb0e1633247331e35fea Mon Sep 17 00:00:00 2001 From: Rafael Reggiani Manzo Date: Fri, 19 Jun 2015 08:29:52 -0300 Subject: [PATCH] Graphic JS specs refactored so they do not rely on templates --- spec/javascripts/module/graphic_spec.js.coffee | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/spec/javascripts/module/graphic_spec.js.coffee b/spec/javascripts/module/graphic_spec.js.coffee index ae18c7f..c7a8474 100644 --- a/spec/javascripts/module/graphic_spec.js.coffee +++ b/spec/javascripts/module/graphic_spec.js.coffee @@ -2,15 +2,40 @@ #= require spec_helper #= require modules #= require module/graphic +#= require sinon -describe "Graphic#constructor", -> - describe 'with a visible drawer', -> - before () -> +describe "Module.Graphic", -> + describe "constructor", -> + before -> @container = 'container404829' @metric_name = 'Pain' @module_id = '54405' - $('body').html(JST['templates/metric_results']({container: @container, metric_name: @metric_name, module_id: @module_id})) - it "should construct a graphic", -> - graphic = new Module.Graphic(@container, @metric_name, @module_id) + @drawer = sinon.stub() + sinon.stub(window, "$") + $.withArgs("tr#"+@container).returns(@drawer) + context 'when the drawer is hidden', -> + before -> + @drawer.is = sinon.stub().withArgs(':hidden').returns(true) + + it "should show the drawer and start to load a graphic", -> + @drawer.slideDown = sinon.spy() + + Module.Graphic.prototype.load = sinon.spy() + + @graphic = new Module.Graphic(@container, @metric_name, @module_id) + + assert.isTrue(@drawer.slideDown.calledOnce) + assert.isTrue(@graphic.load.calledOnce) + + context 'when the drawer is visible', -> + before -> + @drawer.is = sinon.stub().withArgs(':hidden').returns(false) + + it 'should hide the drawer', -> + @drawer.slideUp = sinon.spy() + + @graphic = new Module.Graphic(@container, @metric_name, @module_id) + + assert.isTrue(@drawer.slideUp.calledOnce) -- libgit2 0.21.2