CB-10662 Add tests for ConfigParser.getStaticResources
Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/cda2b72b Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/cda2b72b Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/cda2b72b Branch: refs/heads/common-1.1.x Commit: cda2b72b81bf26670674b8965381ee4534bdc8e9 Parents: 84d4ea0 Author: Vladimir Kotikov <v-vlk...@microsoft.com> Authored: Fri Feb 26 17:41:03 2016 +0300 Committer: Vladimir Kotikov <v-vlk...@microsoft.com> Committed: Fri Feb 26 17:43:44 2016 +0300 ---------------------------------------------------------------------- .../spec/ConfigParser/ConfigParser.spec.js | 49 ++++++++++++++++++++ cordova-common/spec/fixtures/test-config.xml | 7 +++ 2 files changed, 56 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cda2b72b/cordova-common/spec/ConfigParser/ConfigParser.spec.js ---------------------------------------------------------------------- diff --git a/cordova-common/spec/ConfigParser/ConfigParser.spec.js b/cordova-common/spec/ConfigParser/ConfigParser.spec.js index f4eace7..097fe61 100644 --- a/cordova-common/spec/ConfigParser/ConfigParser.spec.js +++ b/cordova-common/spec/ConfigParser/ConfigParser.spec.js @@ -228,5 +228,54 @@ describe('config.xml parser', function () { expect(navigations.length).not.toEqual(0); }); }); + describe('static resources', function() { + var hasPlatformPropertyDefined = function (e) { return !!e.platform; }; + var hasSrcPropertyDefined = function (e) { return !!e.src; }; + var hasTargetPropertyDefined = function (e) { return !!e.target; }; + var hasDensityPropertyDefined = function (e) { return !!e.density; }; + var hasPlatformPropertyUndefined = function (e) { return !e.platform; }; + + it('should fetch shared resources if platform parameter is not specified', function() { + expect(cfg.getStaticResources(null, 'icon').length).toBe(2); + expect(cfg.getStaticResources(null, 'icon').every(hasPlatformPropertyUndefined)).toBeTruthy(); + }); + + it('should fetch platform-specific resources along with shared if platform parameter is specified', function() { + expect(cfg.getStaticResources('android', 'icon').length).toBe(5); + expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyDefined)).toBeTruthy(); + expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).length).toBe(3); + expect(cfg.getStaticResources('android', 'icon').some(hasPlatformPropertyUndefined)).toBeTruthy(); + }); + + it('should parse resources\' attributes', function() { + expect(cfg.getStaticResources(null, 'icon').every(hasSrcPropertyDefined)).toBeTruthy(); + expect(cfg.getStaticResources('windows', 'icon').filter(hasPlatformPropertyDefined).every(hasTargetPropertyDefined)).toBeTruthy(); + expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).every(hasDensityPropertyDefined)).toBeTruthy(); + expect(cfg.getStaticResources('android', 'icon').filter(hasPlatformPropertyDefined).every(hasDensityPropertyDefined)).toBeTruthy(); + }); + + it('should have defaultResource property', function() { + expect(cfg.getStaticResources(null, 'icon').defaultResource).toBeDefined(); + expect(cfg.getStaticResources(null, 'icon').defaultResource.src).toBe('icon.png'); + }); + + it('should have getDefault method returning defaultResource property', function() { + expect(cfg.getStaticResources(null, 'icon').defaultResource).toEqual(cfg.getStaticResources(null, 'icon').getDefault()); + }); + + it('should have getBySize method returning resource with size specified or null', function() { + expect(cfg.getStaticResources('windows', 'icon').getBySize(128)).toBe(null); + expect(cfg.getStaticResources('windows', 'icon').getBySize(72)).toBeDefined(); + expect(cfg.getStaticResources('windows', 'icon').getBySize(72).width).toBe(72); + expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48)).toBeDefined(); + expect(cfg.getStaticResources('windows', 'icon').getBySize(null, 48).height).toBe(48); + }); + + it('should have getByDensity method returning resource with density specified or null', function() { + expect(cfg.getStaticResources('android', 'icon').getByDensity('hdpi')).toBe(null); + expect(cfg.getStaticResources('android', 'icon').getByDensity('mdpi')).toBeDefined(); + expect(cfg.getStaticResources('android', 'icon').getByDensity('mdpi').src).toBe('logo-android.png'); + }); + }); }); }); http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cda2b72b/cordova-common/spec/fixtures/test-config.xml ---------------------------------------------------------------------- diff --git a/cordova-common/spec/fixtures/test-config.xml b/cordova-common/spec/fixtures/test-config.xml index 2f14f32..df47948 100644 --- a/cordova-common/spec/fixtures/test-config.xml +++ b/cordova-common/spec/fixtures/test-config.xml @@ -81,9 +81,16 @@ <icon height="255" id="logo" src="logo.png" width="255" /> <platform name="android"> <icon density="mdpi" height="255" src="logo-android.png" width="255" /> + <icon gap:density="mdpi" height="255" src="logo-android-gap.png" width="255" /> + <icon cdv:density="mdpi" height="255" src="logo-android-cdv.png" width="255" /> <preference name="android-minSdkVersion" value="10" /> <preference name="orientation" value="landscape" /> </platform> + <platform name="windows"> + <icon src="res/windows/logo.scale-200.png" target="logo.png"/> + <icon src="res/windows/logo-small.scale-400.png" width="72" target="logo.png"/> + <icon src="res/windows/logo-small.scale-400_48.png" height="48" target="logo.png"/> + </platform> <plugin name="org.apache.cordova.pluginwithvars"> <variable name="var" value="varvalue" /> </plugin> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org