Commit d2ce5963 authored by Mikaël Salson's avatar Mikaël Salson
Browse files

model.js: displayTop checks the value we give to it.

A top cannot be negative nor larger than the total number of (real) clones.
We add a function telling the number of real clones (for the moment length of the array minus one due to the 'other' clone).

Unit tests added
parent 088616e3
...@@ -1147,6 +1147,11 @@ Model.prototype = { ...@@ -1147,6 +1147,11 @@ Model.prototype = {
* */ * */
displayTop: function (top) { displayTop: function (top) {
top = typeof top !== 'undefined' ? top : this.top; top = typeof top !== 'undefined' ? top : this.top;
if (top < 0)
top = 0
if (top > this.countRealClones())
top = this.countRealClones()
this.top = top; this.top = top;
var html_slider = document.getElementById('top_slider'); var html_slider = document.getElementById('top_slider');
...@@ -1166,6 +1171,14 @@ Model.prototype = { ...@@ -1166,6 +1171,14 @@ Model.prototype = {
this.update(); this.update();
}, },
/**
* @return the number of real clones (excluded the fake clones internally
* added)
*/
countRealClones: function() {
return this.clones.length - 1
},
/* /*
* *
* */ * */
......
...@@ -36,6 +36,17 @@ test("model : time control", function() { ...@@ -36,6 +36,17 @@ test("model : time control", function() {
}); });
test("model : top clones", function() {
var m = new Model();
m.parseJsonData(json_data,100)
equal(m.countRealClones(), 3, "Real clones, expected 3")
m.displayTop(-10)
equal(m.top, 0, "Top cannot be negative")
m.displayTop(m.countRealClones() * 2 + 10)
equal(m.top, m.countRealClones(), "Top cannot be greater than the number of real clones")
});
test("model : select/focus", function() { test("model : select/focus", function() {
var m = new Model(); var m = new Model();
m.parseJsonData(json_data,100) m.parseJsonData(json_data,100)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment