it('should call graftXMLOverwrite for every new config.xml config munge with mode \'overwrite\' it introduces', function () { const platformJson = PlatformJson.load(plugins_dir, 'android'); const spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson); munger.add_config_changes(cfg, true); expect(spy.calls.count()).toEqual(1); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/uses-sdk'); });
describe('generateAndSaveMetadata method', function () { it('should save generated metadata', function () { // Needs to use graceful-fs, since that is used by fs-extra const spy = spyOn(require('graceful-fs'), 'writeFileSync'); const dest = require('path').join(__dirname, 'test-destination'); platformJson.addPluginMetadata(fakePlugin).generateAndSaveMetadata(dest); expect(spy).toHaveBeenCalledTimes(1); const [file, data] = spy.calls.argsFor(0); expect(file).toBe(dest); const mod = evaluateCordovaDefineStatement(data); expect(mod.exports).toEqual(expectedMetadata()); }); });
it('Test 020 : should call graftXMLOverwrite for every new config munge with mode \'overwrite\' it introduces', function () { install_plugin(editconfigplugin); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {}); const spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(1); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity'); });
it('Test 032 : should call pruneXMLRestore for every config munge with mode \'merge\' or \'overwrite\' it removes from the app', function () { fs.copySync(android_two_project, temp); install_plugin(editconfigplugin); // Run through an "install" const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {}); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); // Now set up an uninstall and make sure pruneXMLMerge is called properly platformJson.addUninstalledPluginToPrepareQueue('org.test.editconfigtest'); const spy = spyOn(xml_helpers, 'pruneXMLRestore').and.returnValue(true); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(2); expect(spy.calls.argsFor(0)[1]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']'); expect(spy.calls.argsFor(1)[1]).toEqual('/manifest/application/activity'); });
it('Test 019 : should call graftXMLMerge with --force for every new config munge with mode \'merge\' it introduces', function () { install_plugin(editconfigplugin); install_plugin(editconfigplugin_two); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {}); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true); const spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(3); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']'); expect(spy.calls.argsFor(1)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']'); expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/uses-sdk'); });
expect(logSpy).toHaveBeenCalledWith('test message #1'); logSpy.calls.reset();
it('Test 015 : should call graftXML for every new config munge it introduces (every leaf in config munge that does not exist)', function () { const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.root.prepare_queue.installed = [{ plugin: 'org.test.plugins.dummyplugin', vars: {} }]; const spy = spyOn(xml_helpers, 'graftXML').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(4); expect(spy.calls.argsFor(0)[2]).toEqual('/*'); expect(spy.calls.argsFor(1)[2]).toEqual('/*'); expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/application'); expect(spy.calls.argsFor(3)[2]).toEqual('/cordova/plugins'); });
$httpBackend.flush(); var accounts = responseHandler.calls.argsFor(0)[0]; var accountsCopy = accounts.clone();
it('Test 028 : should generate a config munge that interpolates variables into config changes, if applicable', function () { fs.copySync(android_two_project, temp); install_plugin(varplugin); // Run through an "install" const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('com.adobe.vars', { API_KEY: 'canucks' }); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); // Now set up an uninstall and make sure prunexml is called properly platformJson.addUninstalledPluginToPrepareQueue('com.adobe.vars'); const spy = spyOn(munger, 'generate_plugin_config_munge').and.returnValue({}); munger.process(plugins_dir); const munge_params = spy.calls.argsFor(0); expect(munge_params[0]).toEqual(jasmine.any(PluginInfo)); expect(munge_params[0].dir).toEqual(path.join(plugins_dir, 'com.adobe.vars')); expect(munge_params[1].API_KEY).toEqual('canucks'); });
it('Test 027 : should call pruneXML for every config munge it completely removes from the app (every leaf that is decremented to 0)', function () { fs.copySync(android_two_project, temp); // Run through an "install" const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.plugins.dummyplugin', {}); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); // Now set up an uninstall and make sure prunexml is called properly platformJson.addUninstalledPluginToPrepareQueue('org.test.plugins.dummyplugin'); const spy = spyOn(xml_helpers, 'pruneXML').and.returnValue(true); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(4); expect(spy.calls.argsFor(0)[2]).toEqual('/*'); expect(spy.calls.argsFor(1)[2]).toEqual('/*'); expect(spy.calls.argsFor(2)[2]).toEqual('/manifest/application'); expect(spy.calls.argsFor(3)[2]).toEqual('/cordova/plugins'); });
it('Test 016 : should not call graftXML for a config munge that already exists from another plugin', function () { install_plugin(configplugin); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.configtest', {}); const spy = spyOn(xml_helpers, 'graftXML').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(1); });
it('Test 021 : should call graftXMLOverwrite with --force for every new config munge with mode \'overwrite\' it introduces', function () { install_plugin(editconfigplugin); install_plugin(editconfigplugin_two); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {}); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true); const spy = spyOn(xml_helpers, 'graftXMLOverwrite').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(2); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity'); expect(spy.calls.argsFor(1)[2]).toEqual('/manifest/application/activity[@android:name=\'ChildApp\']'); });
it('Test 018 : should call graftXMLMerge for every new config munge with mode \'merge\' it introduces', function () { install_plugin(editconfigplugin); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest', {}); const spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); expect(spy.calls.count()).toEqual(1); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/application/activity[@android:name=\'org.test.DroidGap\']'); });
it('should call graftXMLMerge for every new config.xml config munge with mode \'merge\' it introduces', function () { const platformJson = PlatformJson.load(plugins_dir, 'android'); const spy = spyOn(xml_helpers, 'graftXMLMerge').and.returnValue(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson); munger.add_config_changes(cfg, true); expect(spy.calls.count()).toEqual(1); expect(spy.calls.argsFor(0)[2]).toEqual('/manifest/uses-sdk'); });