From 680ba379c10c666d54042ed3c5c388b5d012bfc3 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 20 Nov 2014 10:29:48 +1100 Subject: [PATCH] User can select a hub --- .../override_variants_controller.js.coffee | 4 +++ .../products/override_variants.html.haml | 2 ++ spec/features/admin/override_variants_spec.rb | 8 ++++++ ...verride_variants_controller_spec.js.coffee | 26 +++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee diff --git a/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee index 980256f90f..69bc5fb8cd 100644 --- a/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/override_variants_controller.js.coffee @@ -1,2 +1,6 @@ angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, hubs) -> $scope.hubs = hubs + $scope.hub = null + + $scope.selectHub = -> + $scope.hub = (hub for hub in hubs when hub.id == $scope.hub_id)[0] \ No newline at end of file diff --git a/app/views/spree/admin/products/override_variants.html.haml b/app/views/spree/admin/products/override_variants.html.haml index 6f9ffafb31..51c6e6d0d4 100644 --- a/app/views/spree/admin/products/override_variants.html.haml +++ b/app/views/spree/admin/products/override_variants.html.haml @@ -3,3 +3,5 @@ %div{ ng: { app: 'ofn.admin', controller: 'AdminOverrideVariantsCtrl', init: 'initialise()' } } = render 'spree/admin/products/override_variants/hub_choice' + + %h2{ng: {show: 'hub'}} {{ hub.name }} diff --git a/spec/features/admin/override_variants_spec.rb b/spec/features/admin/override_variants_spec.rb index e67eae34ce..0e84321a97 100644 --- a/spec/features/admin/override_variants_spec.rb +++ b/spec/features/admin/override_variants_spec.rb @@ -23,5 +23,13 @@ feature %q{ visit '/admin/products/override_variants' page.should have_select2 'hub_id', options: ['', hub.name] end + + it "displays the hub" do + visit '/admin/products/override_variants' + select2_select hub.name, from: 'hub_id' + click_button 'Go' + + page.should have_selector 'h2', text: hub.name + end end end diff --git a/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee b/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee new file mode 100644 index 0000000000..6a3d895256 --- /dev/null +++ b/spec/javascripts/unit/admin/controllers/override_variants_controller_spec.js.coffee @@ -0,0 +1,26 @@ +describe "OverrideVariantsCtrl", -> + ctrl = null + scope = null + hubs = [{id: 1, name: 'Hub'}] + + beforeEach -> + module 'ofn.admin' + scope = {} + + inject ($controller)-> + ctrl = $controller 'AdminOverrideVariantsCtrl', {$scope: scope, hubs: hubs} + + it "initialises the hub list and the chosen hub", -> + expect(scope.hubs).toEqual hubs + expect(scope.hub).toBeNull + + describe "selecting a hub", -> + it "sets the chosen hub", -> + scope.hub_id = 1 + scope.selectHub() + expect(scope.hub).toEqual hubs[0] + + it "does nothing when no selection has been made", -> + scope.hub_id = '' + scope.selectHub + expect(scope.hub).toBeNull \ No newline at end of file