diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tests/Strategy/Paging.html | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-0.0.4.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tests/Strategy/Paging.html')
-rw-r--r-- | misc/openlayers/tests/Strategy/Paging.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Strategy/Paging.html b/misc/openlayers/tests/Strategy/Paging.html new file mode 100644 index 0000000..a85167e --- /dev/null +++ b/misc/openlayers/tests/Strategy/Paging.html @@ -0,0 +1,113 @@ +<html> +<head> + <script src="../OLLoader.js"></script> + <script type="text/javascript"> + + function test_activate(t) { + t.plan(2); + + var strategy = new OpenLayers.Strategy.Paging(); + t.eq(strategy.active, false, "not active after construction"); + + var layer = new OpenLayers.Layer.Vector("Vector Layer", { + strategies: [strategy] + }); + var map = new OpenLayers.Map('map'); + map.addLayer(layer); + + t.eq(strategy.active, true, "active after adding to map"); + } + + function test_paging(t) { + t.plan(18); + + var strategy = new OpenLayers.Strategy.Paging(); + var layer = new OpenLayers.Layer.Vector("Vector Layer", { + strategies: [strategy], + drawFeature: function() {} + }); + var map = new OpenLayers.Map('map'); + map.addLayer(layer); + + var features = new Array(25); + for(var i=0; i<features.length; ++i) { + features[i] = {destroy: function() {}}; + } + + function featuresEq(got, exp) { + var eq = false; + if(got instanceof Array && exp instanceof Array) { + if(got.length === exp.length) { + for(var i=0; i<got.length; ++i) { + if(got[i] !== exp[i]) { + console.log(got[i], exp[i]); + break; + } + } + eq = (i == got.length); + } + } + return eq; + } + + var len = strategy.pageLength(); + t.eq(len, 10, "page length defaults to 10"); + + // add 25 features to the layer + layer.addFeatures(features); + t.eq(strategy.features.length, features.length, "strategy caches all features"); + t.eq(layer.features.length, len, "layer gets one page of features"); + t.ok(featuresEq(layer.features, features.slice(0, len)), "layer gets first page initially"); + t.eq(strategy.pageNum(), 0, "strategy reports 0 based page number"); + t.eq(strategy.pageCount(), Math.ceil(features.length / len), "strategy reports correct number of pages"); + + // load next page of features + var changed = strategy.pageNext(); + t.eq(changed, true, "(1) strategy reports change"); + t.eq(strategy.pageNum(), 1, "second page"); + t.ok(featuresEq(layer.features, features.slice(len, 2*len)), "layer has second page of features"); + + // load next page of features (half page) + changed = strategy.pageNext(); + t.eq(changed, true, "(2) strategy reports change"); + t.eq(strategy.pageNum(), 2, "third page"); + + // try to change forward again + changed = strategy.pageNext(); + t.eq(changed, false, "strategy reports no change"); + t.eq(layer.features.length, features.length % len, "layer has partial page"); + t.ok(featuresEq(layer.features, features.slice(2*len, 3*len)), "layer has third page of features"); + t.eq(strategy.pageNum(), 2, "still on third page"); + + // change back a page + changed = strategy.pagePrevious(); + t.eq(changed, true, "(3) strategy reports change"); + t.eq(strategy.pageNum(), 1, "back on second page"); + t.ok(featuresEq(layer.features, features.slice(len, 2*len)), "layer has second page of features again"); + + layer.destroy(); + + } + + function test_deactivate(t) { + t.plan(2); + + var strategy = new OpenLayers.Strategy.Paging(); + var layer = new OpenLayers.Layer.Vector("Vector Layer", { + strategies: [strategy] + }); + var map = new OpenLayers.Map('map'); + map.addLayer(layer); + + t.eq(strategy.active, true, "active after adding to map"); + + map.removeLayer(layer); + t.eq(strategy.active, false, "not active after removing from map"); + } + + </script> +</head> +<body> + <div id="map" style="width: 400px; height: 200px" /> +</body> +</html> |