Skip to content
Permalink
Browse files
refactor(ConfigParser): cleanup & simplify (#133)
* refactor: ConfigParser

* make use of et API

* factor out CDV_XMLNS_URI

* shorten some setters

* simplify addPlugin

* test: extend preferences tests

* fix & DRY preferences code

- fixes setGlobalPreference to be case-insensitive
- fixes setGlobalPreference to use the last preference if multiple exist

* simplify getCordovaNamespacePrefix

* simplify access methods

* DRY & simplify getFileResources

* simplify getHookScripts

* get rid of superfluous variables

* improve JSDocs

* destructure parseElementtreeSync

* simplify getPlugin

* introduce Resource types

* Add some platform remarks to JSDocs

Co-authored-by: Erisu <ellis.bryan@gmail.com>
  • Loading branch information
raphinesse and erisu committed Mar 14, 2020
1 parent b779a34 commit f6e8cabe9b16c992417eceeb08cfd1a1458665f6
Showing 2 changed files with 303 additions and 310 deletions.
@@ -104,6 +104,10 @@ describe('config.xml parser', function () {
it('Test 011 : should return the value of a platform-specific preference', function () {
expect(cfg.getPreference('android-minSdkVersion', 'android')).toEqual('10');
});
it('returns the global preference if no platform-specific preference exists', () => {
expect(cfg.doc.find('./platform/preference[@name="fullscreen"]')).toBe(null);
expect(cfg.getPreference('fullscreen', 'atari')).toEqual('true');
});
it('Test 012 : should return an empty string for a non-existing preference', function () {
expect(cfg.getPreference('zimzooo!')).toEqual('');
});
@@ -115,6 +119,14 @@ describe('config.xml parser', function () {
cfg.setPreference('android-minSdkVersion', 'android', '11');
expect(cfg.getPreference('android-minSdkVersion', 'android')).toEqual('11');
});
it('should overwrite an existing preference', () => {
const children = [...cfg.doc.getroot().getchildren()];
expect(cfg.getPreference('fullscreen')).toEqual('true');

cfg.setPreference('fullscreen', 'false');
expect(cfg.getPreference('fullscreen')).toEqual('false');
expect(cfg.doc.getroot().getchildren()).toEqual(children);
});
});
describe('global preference', function () {
it('Test 013 : should return the value of a global preference', function () {

0 comments on commit f6e8cab

Please sign in to comment.