From dbc8e1bcf1950e2f2cfb4cae134a6896a8be1748 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 20 Mar 2014 15:09:10 +1100 Subject: [PATCH] Reworking the tests for the new app --- .../checkout_controller_spec.js.coffee | 34 +++++++++++++++++ .../ordercycle_controller_spec.js.coffee | 18 +++++++++ .../products_controller_spec.js.coffee} | 38 +------------------ .../sidebar_controller_spec.js.coffee | 24 ++++++++++++ .../unit/darkswarm/order_cycle_spec.js.coffee | 4 +- .../unit/darkswarm/product_spec.js.coffee | 2 +- 6 files changed, 81 insertions(+), 39 deletions(-) create mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee create mode 100644 spec/javascripts/unit/darkswarm/controllers/ordercycle_controller_spec.js.coffee rename spec/javascripts/unit/darkswarm/{controllers_spec.js.coffee => controllers/products_controller_spec.js.coffee} (58%) create mode 100644 spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee new file mode 100644 index 0000000000..fae814e4e8 --- /dev/null +++ b/spec/javascripts/unit/darkswarm/controllers/checkout_controller_spec.js.coffee @@ -0,0 +1,34 @@ +describe "CheckoutCtrl", -> + ctrl = null + scope = null + order = null + + beforeEach -> + module("Darkswarm") + order = + id: 3102 + shipping_method_id: "7" + ship_address_same_as_billing: true + payment_method_id: null + shipping_methods: + 7: + require_ship_address: true + price: 0.0 + + 25: + require_ship_address: false + price: 13 + inject ($controller) -> + scope = {} + ctrl = $controller 'CheckoutCtrl', {$scope: scope, order: order} + + + it 'Gets the ship address automatically', -> + expect(scope.require_ship_address).toEqual true + + it 'Gets the current shipping price', -> + expect(scope.shippingPrice()).toEqual 0.0 + scope.order.shipping_method_id = 25 + expect(scope.shippingPrice()).toEqual 13 + + diff --git a/spec/javascripts/unit/darkswarm/controllers/ordercycle_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/ordercycle_controller_spec.js.coffee new file mode 100644 index 0000000000..260f51982a --- /dev/null +++ b/spec/javascripts/unit/darkswarm/controllers/ordercycle_controller_spec.js.coffee @@ -0,0 +1,18 @@ +describe 'OrderCycleCtrl', -> + ctrl = null + scope = null + event = null + product_ctrl = null + OrderCycle = null + + beforeEach -> + module 'Darkswarm' + scope = {} + OrderCycle = + order_cycle: "test" + inject ($controller) -> + scope = {} + ctrl = $controller 'OrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle} + + it "puts the order cycle in scope", -> + expect(scope.order_cycle).toEqual "test" diff --git a/spec/javascripts/unit/darkswarm/controllers_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee similarity index 58% rename from spec/javascripts/unit/darkswarm/controllers_spec.js.coffee rename to spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee index 5b6b364971..269c8385b8 100644 --- a/spec/javascripts/unit/darkswarm/controllers_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/products_controller_spec.js.coffee @@ -6,7 +6,7 @@ describe 'All controllers', -> Product = null beforeEach -> - module('Shop') + module('Darkswarm') Product = all: -> update: -> @@ -40,42 +40,8 @@ describe 'All controllers', -> OrderCycle = null beforeEach -> - module 'Shop' + module 'Darkswarm' scope = {} inject ($controller) -> scope = {} ctrl = $controller 'OrderCycleCtrl', {$scope: scope} - - describe "CheckoutCtrl", -> - ctrl = null - scope = null - order = null - - beforeEach -> - module("Checkout") - order = - id: 3102 - shipping_method_id: "7" - ship_address_same_as_billing: true - payment_method_id: null - shipping_methods: - 7: - require_ship_address: true - price: 0.0 - - 25: - require_ship_address: false - price: 13 - inject ($controller) -> - scope = {} - ctrl = $controller 'CheckoutCtrl', {$scope: scope, order: order} - - - it 'Gets the ship address automatically', -> - expect(scope.require_ship_address).toEqual true - - it 'Gets the current shipping price', -> - expect(scope.shippingPrice()).toEqual 0.0 - scope.order.shipping_method_id = 25 - expect(scope.shippingPrice()).toEqual 13 - diff --git a/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee new file mode 100644 index 0000000000..d9348021d7 --- /dev/null +++ b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee @@ -0,0 +1,24 @@ +describe "SidebarCtrl", -> + ctrl = null + scope = null + location = null + + beforeEach -> + module("Darkswarm") + location = + path: -> + "/test" + inject ($controller, $rootScope) -> + scope = $rootScope + ctrl = $controller 'SidebarCtrl', {$scope: scope, $location: location} + scope.$apply() + + it 'tracks the active sidebar from the $location', -> + expect(scope.active_sidebar).toEqual "/test" + + it 'is active when a location is set', -> + expect(scope.active()).toEqual "active" + + it 'is inactive no location is set', -> + scope.active_sidebar = null + expect(scope.active()).toEqual null diff --git a/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee b/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee index e7ef7f60b1..395b51512e 100644 --- a/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee @@ -6,8 +6,8 @@ describe 'OrderCycle service', -> } beforeEach -> - angular.module('Shop').value('orderCycleData', {}) - module 'Shop', ($provide)-> + angular.module('Darkswarm').value('orderCycleData', {}) + module 'Darkswarm', ($provide)-> $provide.value "Product", mockProduct null # IMPORTANT # You must return null because module() is a bit dumb diff --git a/spec/javascripts/unit/darkswarm/product_spec.js.coffee b/spec/javascripts/unit/darkswarm/product_spec.js.coffee index fd2a8f4edb..7108d819af 100644 --- a/spec/javascripts/unit/darkswarm/product_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/product_spec.js.coffee @@ -3,7 +3,7 @@ describe 'Product service', -> Product = null beforeEach -> - module 'Shop' + module 'Darkswarm' inject ($injector, _$httpBackend_)-> Product = $injector.get("Product") $httpBackend = _$httpBackend_