From 2961970f598e3d5f2c356c79267e190b781dde74 Mon Sep 17 00:00:00 2001 From: oterral Date: Wed, 4 Jun 2014 10:40:02 +0200 Subject: [PATCH] Add ol.style.Icon tests for getAnchor and getOrigin --- test/spec/ol/style/iconstyle.test.js | 111 +++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/test/spec/ol/style/iconstyle.test.js b/test/spec/ol/style/iconstyle.test.js index f6d7dfdafb..e84d55aba1 100644 --- a/test/spec/ol/style/iconstyle.test.js +++ b/test/spec/ol/style/iconstyle.test.js @@ -1,5 +1,116 @@ +goog.provide('ol.test.style.Icon'); goog.provide('ol.test.style.IconImageCache'); +goog.require('ol.style.Icon'); +goog.require('ol.style.IconAnchorUnits'); +goog.require('ol.style.IconOrigin'); + + +describe('ol.style.Icon', function() { + var size = [36, 48]; + + describe('#getAnchor', function() { + var fractionAnchor = [0.25, 0.25]; + + it('uses fractional units by default', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + anchor: fractionAnchor + }); + expect(iconStyle.getAnchor()).to.eql([9, 12]); + }); + + it('uses pixels units', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + anchor: [2, 18], + anchorXUnits: ol.style.IconAnchorUnits.PIXELS, + anchorYUnits: ol.style.IconAnchorUnits.PIXELS + }); + expect(iconStyle.getAnchor()).to.eql([2, 18]); + }); + + it('uses a bottom left anchor origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + anchor: fractionAnchor, + anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT + }); + expect(iconStyle.getAnchor()).to.eql([9, 36]); + }); + + it('uses a bottom right anchor origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + anchor: fractionAnchor, + anchorOrigin: ol.style.IconOrigin.BOTTOM_RIGHT + }); + expect(iconStyle.getAnchor()).to.eql([27, 36]); + }); + + it('uses a top right anchor origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + anchor: fractionAnchor, + anchorOrigin: ol.style.IconOrigin.TOP_RIGHT + }); + expect(iconStyle.getAnchor()).to.eql([27, 12]); + }); + }); + + describe('#getOrigin', function() { + var offset = [16, 20]; + var imageSize = [144, 192]; + + it('uses a top left offset origin (default)', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + offset: offset + }); + expect(iconStyle.getOrigin()).to.eql([16, 20]); + }); + + it('uses a bottom left offset origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + offset: offset, + offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT + }); + iconStyle.iconImage_.size_ = imageSize; + expect(iconStyle.getOrigin()).to.eql([16, 124]); + }); + + it('uses a bottom right offset origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + offset: offset, + offsetOrigin: ol.style.IconOrigin.BOTTOM_RIGHT + }); + iconStyle.iconImage_.size_ = imageSize; + expect(iconStyle.getOrigin()).to.eql([92, 124]); + }); + + it('uses a top right offset origin', function() { + var iconStyle = new ol.style.Icon({ + src: 'test.png', + size: size, + offset: offset, + offsetOrigin: ol.style.IconOrigin.TOP_RIGHT + }); + iconStyle.iconImage_.size_ = imageSize; + expect(iconStyle.getOrigin()).to.eql([92, 20]); + }); + }); +}); + describe('ol.style.IconImageCache', function() { var originalMaxCacheSize;