Skip to content

Commit

Permalink
Merge pull request #333 from unepwcmc/review-indicator-fields
Browse files Browse the repository at this point in the history
Review indicator properties
  • Loading branch information
th3james committed May 7, 2014
2 parents f550281 + b3c8ced commit b30f404
Show file tree
Hide file tree
Showing 48 changed files with 526 additions and 528 deletions.
8 changes: 4 additions & 4 deletions client/src/collections/indicator_collection.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Backbone.Collections.IndicatorCollection extends Backbone.Collection
url += "?withData=true"
url

filterByTitle: (title='') ->
title = title.trim()
filterByName: (name='') ->
name = name.trim()

regexp = new RegExp(".*#{title}.*", 'i')
regexp = new RegExp(".*#{name}.*", 'i')
@filter( (indicator) ->
regexp.test indicator.get('title')
regexp.test indicator.get('name')
)

filterByTheme: (theme) ->
Expand Down
4 changes: 2 additions & 2 deletions client/src/templates/indicator_selector_item.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<h4>{{short_name}}</h4>
<p>{{title}}</p>
<h4>{{shortName}}</h4>
<p>{{name}}</p>
2 changes: 1 addition & 1 deletion client/src/templates/report_edit_visualisation.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="editor">
<span class="close">{{{t "report/modal/close"}}}<i class="icon-remove-circle"></i></span>
<header>
<h2>{{indicator.title}}</h2>
<h2>{{indicator.name}}</h2>
</header>
<div class="visualisation">
<div class='controls'>
Expand Down
2 changes: 1 addition & 1 deletion client/src/templates/table.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<table>
<caption>{{indicatorTitle}}</caption>
<caption>{{indicatorName}}</caption>
<thead>
<tr>
<th>{{xAxis}}</th>
Expand Down
2 changes: 1 addition & 1 deletion client/src/templates/visualisation.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h4>{{indicator.title}}</h4>
<h4>{{indicator.name}}</h4>

{{#if isEditable}}
<button class="delete delete-visualisation">
Expand Down
6 changes: 3 additions & 3 deletions client/src/views/indicator_selector_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Backbone.Views.IndicatorSelectorView extends Backbone.Diorama.NestingView
events:
"click .close": "close"
"click .clear-search": "clearSearch"
"keyup input": "filterByTitle"
"keyup input": "filterByName"

initialize: (options = {}) ->
@currentIndicator = options.currentIndicator
Expand Down Expand Up @@ -55,7 +55,7 @@ class Backbone.Views.IndicatorSelectorView extends Backbone.Diorama.NestingView

@filterIndicators()

filterByTitle: (event) =>
filterByName: (event) =>
searchTerm = $(event.target).val()

@updateClearSearchButton()
Expand All @@ -75,7 +75,7 @@ class Backbone.Views.IndicatorSelectorView extends Backbone.Diorama.NestingView
results = @indicators.filterBySource(@filter.sourceName)
@results.set(results)

results = @results.filterByTitle(@filter.searchTerm)
results = @results.filterByName(@filter.searchTerm)
@textFilteredIndicators.reset(results)
@results.set(results)

Expand Down
4 changes: 2 additions & 2 deletions client/src/views/section_navigation_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Backbone.Views.SectionNavigationView extends Backbone.View
sections: @sections.map (section)->
title = section.get('title')
if section.get('indicator')?
title = section.get('indicator').get('title')
title = section.get('indicator').get('name')

return {
cid: section.cid
_id: section.get('_id')
Expand Down
2 changes: 1 addition & 1 deletion client/src/views/table_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Backbone.Views.TableView extends Backbone.View
xAxis: @visualisation.getXAxis()
yAxis: @visualisation.getYAxis()
dataRows: @visualisation.mapDataToXAndY()
indicatorTitle: @visualisation.get('indicator').get('title')
indicatorName: @visualisation.get('indicator').get('name')
))

onClose: ->
Expand Down
8 changes: 4 additions & 4 deletions client/test/src/models/section_model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("When intialising a section with a nested visualisation,

test("When calling .toJSON on a section with an indicator model attribute,
the indicator model should be deserialized to the indicator _id", ->
indicatorAttributes = _id: 5, title: 'hat'
indicatorAttributes = _id: 5, name: 'hat'

section = new Backbone.Models.Section(indicator: indicatorAttributes)
assert.equal section.toJSON().indicator, indicatorAttributes._id
Expand Down Expand Up @@ -56,7 +56,7 @@ test(".hasTitleOrIndicator returns true if there is a title present", ->
)

test(".hasTitleOrIndicator returns true if there is an indicator present", ->
section = new Backbone.Models.Section(indicator: {title: 'an indicator'})
section = new Backbone.Models.Section(indicator: {name: 'an indicator'})

assert.ok section.hasTitleOrIndicator()
)
Expand All @@ -81,12 +81,12 @@ test("When initialised with narrative attributes,

test("When setting 'indicator' with indicator attributes,
it creates a Backbone.Models.Indicator model in the indicator attribute", ->
indicatorAttributes = title: "I'm an indicator"
indicatorAttributes = name: "I'm an indicator"
section = new Backbone.Models.Section()
section.set('indicator', indicatorAttributes)

assert.equal section.get('indicator').constructor.name, 'Indicator'
assert.equal section.get('indicator').get('title'), indicatorAttributes.title
assert.equal section.get('indicator').get('name'), indicatorAttributes.name
)

test(".save should actually call save on the parent page model", (done)->
Expand Down
4 changes: 2 additions & 2 deletions client/test/src/models/visualisation_model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('.toJSON returns the indicator: as indicator._id instead of the model attri
visualisation = new Backbone.Models.Visualisation(
indicator: {
_id: indicatorId
title: 'hey'
name: 'hey'
}
)

Expand Down Expand Up @@ -200,7 +200,7 @@ test(".mapDataToXAndY should return data as an array of X and Y objects, with
"Expected the formatted attribute to include the y axis"
)

test('.setFilterParameter when filter is undefined
test('.setFilterParameter when filter is undefined
creates the object and insert the correct values', ->
visualisation = Factory.visualisation()

Expand Down
12 changes: 6 additions & 6 deletions client/test/src/views/indicator_selector_results_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ assert = chai.assert
suite('IndicatorSelectorResultsView')

test('renders an IndicatorSelectorItem sub view for each result in the given collection ', ->
indicator = Factory.indicator(title: 'test indicator')
indicator = Factory.indicator(name: 'test indicator')
indicators = new Backbone.Collections.IndicatorCollection([indicator])

view = new Backbone.Views.IndicatorSelectorResultsView(indicators: indicators)

assert.match view.$el.text(), new RegExp(indicator.get('title')),
"Expected to see the indicator title"
assert.match view.$el.text(), new RegExp(indicator.get('name')),
"Expected to see the indicator name"

for key, v of view.subViews
subView = v
Expand All @@ -23,7 +23,7 @@ test('renders an IndicatorSelectorItem sub view for each result in the given col
)

test('re-renders when the indicator collection resets', ->
indicator = Factory.indicator(title: 'test indicator')
indicator = Factory.indicator(name: 'test indicator')
indicators = new Backbone.Collections.IndicatorCollection([])

view = new Backbone.Views.IndicatorSelectorResultsView(indicators: indicators)
Expand All @@ -33,8 +33,8 @@ test('re-renders when the indicator collection resets', ->

indicators.reset([indicator])

assert.match view.$el.text(), new RegExp(indicator.get('title')),
"Expected to see the indicator title"
assert.match view.$el.text(), new RegExp(indicator.get('name')),
"Expected to see the indicator name"

for key, v of view.subViews
subView = v
Expand Down
52 changes: 26 additions & 26 deletions client/test/src/views/indicator_selector_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dummyFetch = ->
test('populateCollections populates indicators from the server', (done)->
server = sinon.fakeServer.create()

indicators = [title: 'hat']
indicators = [name: 'hat']

indicatorSelector =
indicators: new Backbone.Collections.IndicatorCollection([], withData: true)
Expand All @@ -20,7 +20,7 @@ test('populateCollections populates indicators from the server', (done)->
Helpers.Assertions.assertPathVisited(server, new RegExp("/api/indicators"))

assert.strictEqual(
indicatorSelector.indicators.at(0).get('title'), indicators[0].title
indicatorSelector.indicators.at(0).get('name'), indicators[0].name
)

done()
Expand All @@ -46,8 +46,8 @@ test('.initialize populates the indicators collection,
_id: Factory.findNextFreeId('Section')
)

indicatorTitle = 'An indicator'
indicators = [{_id: 1, title: indicatorTitle}]
indicatorName = 'An indicator'
indicators = [{_id: 1, name: indicatorName}]

@stub(Backbone.Collections.IndicatorCollection::, 'fetch', ->
Helpers.promisify(=>
Expand Down Expand Up @@ -86,7 +86,7 @@ test('Renders a ThemeFilters sub view with the collection of indicators', sinon.
_id: Factory.findNextFreeId('Section')
)

indicators = [{_id: 1, title: "Such Theme"}]
indicators = [{_id: 1, name: "Such Indicator"}]

@stub(Backbone.Collections.IndicatorCollection::, 'fetch', ->
Helpers.promisify(=>
Expand Down Expand Up @@ -154,10 +154,10 @@ test("When 'indicator_selector:theme_selected' is triggered,

test('When `indicator_selector:indicator_selected` event is fired on backbone
it triggers the `indicatorSelected` event on itself', (done)->
indicatorText = 'hats'
indicatorName = 'hats'
indicatorAttributes = [{
type: 'cartodb'
title: indicatorText
name: indicatorName
}]

sandbox = sinon.sandbox.create()
Expand All @@ -177,7 +177,7 @@ test('When `indicator_selector:indicator_selected` event is fired on backbone

indicatorSelectedCallback = (indicator) ->
try
assert.strictEqual indicator.get('title'), indicatorText
assert.strictEqual indicator.get('name'), indicatorName
done()
catch err
done(err)
Expand Down Expand Up @@ -223,8 +223,8 @@ test(".filterByTheme given a theme sets the results object to only
assert.isTrue collectionFilterByThemeStub.calledWith(filterTheme)
)

test(".filterByTitle given an input event sets the results object to only
indicators with a matching title", ->
test(".filterByName given an input event sets the results object to only
indicators with a matching name", ->
view =
indicators: new Backbone.Collections.IndicatorCollection([])
results: new Backbone.Collections.IndicatorCollection()
Expand All @@ -234,30 +234,30 @@ test(".filterByTitle given an input event sets the results object to only

event = target: '<input value="hats and boats and cats">'

filterTitleIndicator = Factory.indicator()
collectionFilterByTitleStub = sinon.stub(
Backbone.Collections.IndicatorCollection::, 'filterByTitle', ->
return [filterTitleIndicator]
filterNameIndicator = Factory.indicator()
collectionfilterByNameStub = sinon.stub(
Backbone.Collections.IndicatorCollection::, 'filterByName', ->
return [filterNameIndicator]
)

Backbone.Views.IndicatorSelectorView::filterByTitle.call(
Backbone.Views.IndicatorSelectorView::filterByName.call(
view, event
)

try
assert.ok(
collectionFilterByTitleStub.calledOnce,
"Expected filterByTitle to be called once but was called
#{collectionFilterByTitleStub.callCount} times"
collectionfilterByNameStub.calledOnce,
"Expected filterByName to be called once but was called
#{collectionfilterByNameStub.callCount} times"
)

assert.lengthOf view.results.models, 1,
"Expected the collection to be filtered to only the correct indicator"

assert.deepEqual view.results.at(0), filterTitleIndicator,
assert.deepEqual view.results.at(0), filterNameIndicator,
"Expected the result indicator to be the correct one for the given theme"
finally
collectionFilterByTitleStub.restore()
collectionfilterByNameStub.restore()
)

test('.filterBySource sets a sourceName attribute on the @filter', ->
Expand All @@ -276,7 +276,7 @@ test('.filterBySource sets a sourceName attribute on the @filter', ->
"Expected filterIndicators to be called with the new filters"
)

test("When the data origin sub view triggers 'selected',
test("When the data origin sub view triggers 'selected',
filterBySource is triggered", sinon.test(->

section = new Backbone.Models.Section(
Expand Down Expand Up @@ -345,22 +345,22 @@ sinon.test(->

theme = Factory.theme()
matchingIndicator = Factory.indicator(
title: "Matching title, theme and type"
name: "Matching name, theme and type"
theme: theme.get('_id')
source: name: 'cygnet'
)

indicators = [
matchingIndicator
{
title: "Matching title and theme only", theme: theme.get('_id')}
name: "Matching name and theme only", theme: theme.get('_id')}
{
title: "Matches theme and source only",
name: "Matches theme and source only",
theme: theme.get('_id'),
source: name: 'cygnet'
},
{
title: "Matching title and source only",
name: "Matching name and source only",
theme: Factory.findNextFreeId('Theme'),
source: name: 'cygnet'
}
Expand All @@ -378,7 +378,7 @@ sinon.test(->
)

view.filterByTheme(theme)
view.filterByTitle({target: '<input value="Matching">'})
view.filterByName({target: '<input value="Matching">'})
view.filterBySource('cygnet')

try
Expand Down
8 changes: 4 additions & 4 deletions client/test/src/views/report_edit_visualisation_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ createAndShowVisualisationViewForOptions = (options) ->

suite('ReportEditVisualisationView')

test("Shows the given indicator title", ->
indicatorTitle = "my lovely indicator"
test("Shows the given indicator name", ->
indicatorName = "my lovely indicator"
indicator = Factory.indicator()
indicator.set('title', indicatorTitle)
indicator.set('name', indicatorName)

section = new Backbone.Models.Section(
indicator: indicator
Expand All @@ -26,7 +26,7 @@ test("Shows the given indicator title", ->

assert.match(
$('#test-container').text(),
new RegExp(".*#{indicatorTitle}.*")
new RegExp(".*#{indicatorName}.*")
)
view.close()
)
Expand Down
4 changes: 2 additions & 2 deletions client/test/src/views/table_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ test('Should render formatted visualisation data into a table', ->
indicatorDefinition:
xAxis: 'year'
yAxis: 'value'
title: 'An indicatr'
name: 'An indicator'
)

view = new Backbone.Views.TableView(visualisation: visualisation)
Helpers.renderViewToTestContainer(view)

assert.strictEqual(
$('#test-container').find('table caption').text(),
indicator.get('title')
indicator.get('name')
)

headerText = $('#test-container').find('table thead').text()
Expand Down
8 changes: 4 additions & 4 deletions client/test/src/views/visualisation_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ createAndShowVisualisationViewForVisualisation = (visualisation) ->

suite('Visualisation View')

test("Shows the title of the indicator", ->
test("Shows the name of the indicator", ->
indicator = Factory.indicator(
title: "Such indicator"
name: "Such indicator"
)

view = new Backbone.Views.VisualisationView(
Expand All @@ -23,8 +23,8 @@ test("Shows the title of the indicator", ->

assert.match(
view.$el.find('h4').text(),
new RegExp(".*#{indicator.get('title')}.*"),
"Expected to see the indicator title"
new RegExp(".*#{indicator.get('name')}.*"),
"Expected to see the indicator name"
)

view.close()
Expand Down
Loading

0 comments on commit b30f404

Please sign in to comment.