Permalink
Browse files

New tests to map previously working functionalities

  • Loading branch information...
1 parent 2f6e633 commit 050e86b119740c8b7ad2f25368f89ce88132ab39 @decioferreira decioferreira committed Apr 13, 2012
@@ -9,13 +9,21 @@ class BIPIndicatorsPage.Models.Indicator extends Backbone.Model
link: null
targets: []
focal_areas: []
+ partners: []
# extra fields for interface
show: false
class BIPIndicatorsPage.Collections.IndicatorsCollection extends Backbone.Collection
model: BIPIndicatorsPage.Models.Indicator
url: '/indicators'
+ filters:
+ headline: null
+ focalArea: null
+ goal: null
+ target: null
+ partner: null
+
filterByHeadline: (headline) ->
if headline?
_.each @models, (indicator) ->
@@ -43,3 +51,7 @@ class BIPIndicatorsPage.Collections.IndicatorsCollection extends Backbone.Collec
else
_.each @models, (indicator) ->
indicator.set({'show': false })
+
+ filterByPartner: (partner) ->
+ _.each @models, (indicator) ->
+ indicator.set({'show': (_.pluck(indicator.get('partners'), 'id').indexOf(partner.get('id')) != -1 ) })
@@ -15,6 +15,10 @@ class BIPIndicatorsPage.Routers.IndicatorsRouter extends Backbone.Router
@focal_areas = new BIPIndicatorsPage.Collections.FocalAreasCollection()
@focal_areas.reset options.focal_areas
+ # Partners
+ @partners = new BIPIndicatorsPage.Collections.PartnersCollection()
+ @partners.reset options.partners
+
routes:
".*" : "index"
@@ -30,6 +34,10 @@ class BIPIndicatorsPage.Routers.IndicatorsRouter extends Backbone.Router
@headlinesView = new BIPIndicatorsPage.Views.Headlines.IndexView(headlines: @headlines)
$("#headlines").html(@headlinesView.render().el)
+ # Partners
+ @partnersView = new BIPIndicatorsPage.Views.Partners.IndexView(partners: @partners)
+ $("#partners").append(@partnersView.render().el)
+
# Click event on tabs
$('a[data-toggle="tab"]').on('shown', @switchContext)
@@ -84,3 +92,7 @@ class BIPIndicatorsPage.Routers.IndicatorsRouter extends Backbone.Router
filterByTarget: (target) ->
@indicators.filterByTarget(target)
+
+ filterByPartner: (partnerId) ->
+ partner = @partners.get(partnerId)
+ @indicators.filterByPartner(partner)
@@ -1,14 +1 @@
-<h1>Listing partners</h1>
-
-<table id="partners-table">
- <tr>
- <th>Name</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-</table>
-
-<br/>
-
-<a href="#/new">New Partner</a>
+<option></option>
@@ -1,5 +1 @@
-<td><%= name %></td>
-
-<td><a href="#/<%= id %>">Show</td>
-<td><a href="#/<%= id %>/edit">Edit</td>
-<td><a href="#/<%= id %>/destroy" class="destroy">Destroy</a></td>
+<%= name %>
@@ -1,2 +1,2 @@
-<div class="keyword<% if(selected) { %> selected<% } %>"><%= index %></div>
+<div class="keyword<% if(selected) { %> selected<% } %>"><%= keyword %></div>
<div class="title"><%= title %></div>
@@ -3,6 +3,11 @@ BIPIndicatorsPage.Views.Partners ||= {}
class BIPIndicatorsPage.Views.Partners.IndexView extends Backbone.View
template: JST["backbone/templates/partners/index"]
+ tagName: 'select'
+
+ events:
+ 'change': 'select'
+
initialize: () ->
@options.partners.bind('reset', @addAll)
@@ -11,10 +16,15 @@ class BIPIndicatorsPage.Views.Partners.IndexView extends Backbone.View
addOne: (partner) =>
view = new BIPIndicatorsPage.Views.Partners.PartnerView({model : partner})
- @$("tbody").append(view.render().el)
+ @$el.append(view.render().el)
render: =>
- $(@el).html(@template(partners: @options.partners.toJSON() ))
+ @$el.attr('id', 'partner')
+ @$el.html(@template(partners: @options.partners.toJSON() ))
@addAll()
return this
+
+ select: =>
+ partnerId = @$el.find("option:selected").val()
+ router.filterByPartner(partnerId)
@@ -3,17 +3,9 @@ BIPIndicatorsPage.Views.Partners ||= {}
class BIPIndicatorsPage.Views.Partners.PartnerView extends Backbone.View
template: JST["backbone/templates/partners/partner"]
- events:
- "click .destroy" : "destroy"
-
- tagName: "tr"
-
- destroy: () ->
- @model.destroy()
- this.remove()
-
- return false
+ tagName: "option"
render: ->
- $(@el).html(@template(@model.toJSON() ))
+ @$el.val(@model.get('id'))
+ @$el.html(@template(@model.toJSON() ))
return this
@@ -1,3 +1,10 @@
+<div id="filters" class="well">
+ <h3>Filter</h3>
+ <div id="partners">
+ <label for="partner">Partner</label>
+ </div>
+</div>
+
<ul class="nav nav-tabs">
<li class="active"><a href="#matrix" data-toggle="tab">Matrix</a></li>
<li><a href="#graphic" data-toggle="tab">Graphic</a></li>
@@ -33,7 +40,7 @@
<script type="text/javascript">
$(function() {
- window.router = new BIPIndicatorsPage.Routers.IndicatorsRouter({indicators: <%= @indicators.to_json(:include => [:targets, :focal_areas], :methods => :link).html_safe -%>, goals: <%= @goals.to_json(:include => :targets).html_safe -%>, headlines: <%= @headlines.to_json.html_safe -%>, focal_areas: <%= @focal_areas.to_json.html_safe -%>, partners: <%= @partners.to_json.html_safe -%>});
+ window.router = new BIPIndicatorsPage.Routers.IndicatorsRouter({indicators: <%= @indicators.to_json(:include => [:targets, :focal_areas, :partners], :methods => :link).html_safe -%>, goals: <%= @goals.to_json(:include => :targets).html_safe -%>, headlines: <%= @headlines.to_json.html_safe -%>, focal_areas: <%= @focal_areas.to_json.html_safe -%>, partners: <%= @partners.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
View
@@ -14,26 +14,26 @@
]
targets = [
- {:index => 1, :title =>'Target 1 - People aware of the values of biodiversity and the steps they can take'},
- {:index => 2, :title =>'Target 2 - Biodiversity values integrated into development strategies and planning processes'},
- {:index => 3, :title =>'Target 3 - Harmful incentives phased out or reformed and positive incentives developed and applied'},
- {:index => 4, :title =>'Target 4 - Plans for sustainable production and consumption implemented'},
- {:index => 5, :title =>'Target 5 - The rate of loss of all natural habitats at least halved'},
- {:index => 6, :title =>'Target 6 - Overfishing avoided, fisheries managed sustainably with no significant adverse impacts'},
- {:index => 7, :title =>'Target 7 - Areas under agriculture, aquaculture and forestry managed sustainably'},
- {:index => 8, :title =>'Target 8 - Pollution brought to levels that are not detrimental to biodiversity'},
- {:index => 9, :title =>'Target 9 - Invasive alien species and pathways identified and controlled or eradicated'},
- {:index => 10, :title =>'Target 10 - The multiple anthropogenic pressures on vulnerable ecosystems minimized'},
- {:index => 11, :title =>'Target 11 - Terrestrial, inland water, and coastal and marine areas conserved through protected areas'},
- {:index => 12, :title =>'Target 12 - The extinction of known threatened species prevented'},
- {:index => 13, :title =>'Target 13 - Genetic diversity of cultivated plants and farmed and domesticated animals maintained'},
- {:index => 14, :title =>'Target 14 - Ecosystems that provide essential services, are restored and safeguarded'},
- {:index => 15, :title =>'Target 15 - Ecosystem resilience and carbon stocks enhanced through conservation and restoration'},
- {:index => 16, :title =>'Target 16 - The Nagoya Protocol is in force and operational'},
- {:index => 17, :title =>'Target 17 - National biodiversity strategy and action plans developed and implemented'},
- {:index => 18, :title =>'Target 18 - Traditional knowledge and customary use respected and reflected in CBD implementation'},
- {:index => 19, :title =>'Target 19 - Knowledge relating to biodiversity, improved, shared, transferred, and applied'},
- {:index => 20, :title =>'Target 20 - The mobilization of financial resources increased substantially'}
+ {:index => 1, keyword: 1, :title =>'Target 1 - People aware of the values of biodiversity and the steps they can take'},
+ {:index => 2, keyword: 2, :title =>'Target 2 - Biodiversity values integrated into development strategies and planning processes'},
+ {:index => 3, keyword: 3, :title =>'Target 3 - Harmful incentives phased out or reformed and positive incentives developed and applied'},
+ {:index => 4, keyword: 4, :title =>'Target 4 - Plans for sustainable production and consumption implemented'},
+ {:index => 5, keyword: 5, :title =>'Target 5 - The rate of loss of all natural habitats at least halved'},
+ {:index => 6, keyword: 6, :title =>'Target 6 - Overfishing avoided, fisheries managed sustainably with no significant adverse impacts'},
+ {:index => 7, keyword: 7, :title =>'Target 7 - Areas under agriculture, aquaculture and forestry managed sustainably'},
+ {:index => 8, keyword: 8, :title =>'Target 8 - Pollution brought to levels that are not detrimental to biodiversity'},
+ {:index => 9, keyword: 9, :title =>'Target 9 - Invasive alien species and pathways identified and controlled or eradicated'},
+ {:index => 10, keyword: 10, :title =>'Target 10 - The multiple anthropogenic pressures on vulnerable ecosystems minimized'},
+ {:index => 11, keyword: 11, :title =>'Target 11 - Terrestrial, inland water, and coastal and marine areas conserved through protected areas'},
+ {:index => 12, keyword: 12, :title =>'Target 12 - The extinction of known threatened species prevented'},
+ {:index => 13, keyword: 13, :title =>'Target 13 - Genetic diversity of cultivated plants and farmed and domesticated animals maintained'},
+ {:index => 14, keyword: 14, :title =>'Target 14 - Ecosystems that provide essential services, are restored and safeguarded'},
+ {:index => 15, keyword: 15, :title =>'Target 15 - Ecosystem resilience and carbon stocks enhanced through conservation and restoration'},
+ {:index => 16, keyword: 16, :title =>'Target 16 - The Nagoya Protocol is in force and operational'},
+ {:index => 17, keyword: 17, :title =>'Target 17 - National biodiversity strategy and action plans developed and implemented'},
+ {:index => 18, keyword: 18, :title =>'Target 18 - Traditional knowledge and customary use respected and reflected in CBD implementation'},
+ {:index => 19, keyword: 19, :title =>'Target 19 - Knowledge relating to biodiversity, improved, shared, transferred, and applied'},
+ {:index => 20, keyword: 20, :title =>'Target 20 - The mobilization of financial resources increased substantially'}
]
headlines = [
View
@@ -1,8 +1,16 @@
FactoryGirl.define do
+ # Focal area
+ factory :focal_area do
+ end
+
# Goal
factory :goal do
end
+ # Headline
+ factory :headline do
+ end
+
# Indicator
factory :indicator do
end
@@ -66,16 +66,61 @@
visit '/'
page.find('#matrix').should have_content('ABC')
end
+
+ it 'shows indicators associated with the clicked target', js: true do
+ goal = FactoryGirl.create(:goal, code: 'ABBA')
+
+ target_1 = FactoryGirl.create(:target, keyword: 'ABC', goal: goal)
+ target_2 = FactoryGirl.create(:target, keyword: 'XYZ', goal: goal)
+
+ FactoryGirl.create(:indicator, title: 'This one should appear', targets: [target_1])
+ FactoryGirl.create(:indicator, title: 'This one should also appear', targets: [target_1])
+ FactoryGirl.create(:indicator, title: 'This one should not', targets: [target_2])
+
+ visit '/'
+ page.execute_script('$("div.keyword:contains(\'ABC\')").click()')
+ page.find('#indicators-container').should have_content('This one should appear')
+ page.find('#indicators-container').should have_content('This one should also appear')
+ page.find('#indicators-container').should_not have_content('This one should not appear')
+ end
end
end
describe 'graph' do
+ it 'shows indicators associated with the clicked focal_area', js: true, :driver => :selenium do
+ focal_area_1 = FactoryGirl.create(:focal_area, name: 'A')
+ focal_area_2 = FactoryGirl.create(:focal_area, name: 'B')
+
+ FactoryGirl.create(:indicator, title: 'This one should appear', focal_areas: [focal_area_1])
+ FactoryGirl.create(:indicator, title: 'This one should also appear', focal_areas: [focal_area_1])
+ FactoryGirl.create(:indicator, title: 'This one should not', focal_areas: [focal_area_2])
+
+ visit '/'
+ click_link('Graphic')
+ # Workaround to test clicking on the image map
+ page.execute_script('window.router.filterByFocalArea("A");return false')
+ page.find('#indicators-container').should have_content('This one should appear')
+ page.find('#indicators-container').should have_content('This one should also appear')
+ page.find('#indicators-container').should_not have_content('This one should not appear')
+ end
end
describe 'headlines list' do
- end
+ it 'shows indicators associated with the clicked headline', js: true do
+ headline_1 = FactoryGirl.create(:headline, title: 'The first headline ever')
+ headline_2 = FactoryGirl.create(:headline, title: 'The last headline ever')
- describe 'indicators list' do
+ FactoryGirl.create(:indicator, title: 'This one should appear', headline: headline_1)
+ FactoryGirl.create(:indicator, title: 'This one should also appear', headline: headline_1)
+ FactoryGirl.create(:indicator, title: 'This one should not', headline: headline_2)
+
+ visit '/'
+ click_link('Headlines')
+ page.execute_script('$(".title:contains(\'The first headline ever\')").siblings("button").click()')
+ page.find('#indicators-container').should have_content('This one should appear')
+ page.find('#indicators-container').should have_content('This one should also appear')
+ page.find('#indicators-container').should_not have_content('This one should not appear')
+ end
end
end
end

0 comments on commit 050e86b

Please sign in to comment.