|
| 1 | +/** |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +const path = require('path'); |
| 21 | +const fs = require('fs-extra'); |
| 22 | +const EventEmitter = require('events').EventEmitter; |
| 23 | +const ConfigParser = require('cordova-common').ConfigParser; |
| 24 | +const PluginInfo = require('cordova-common').PluginInfo; |
| 25 | +const Api = require('../../../bin/templates/scripts/cordova/Api'); |
| 26 | + |
| 27 | +const FIXTURES = path.join(__dirname, 'fixtures'); |
| 28 | +const DUMMY_PLUGIN = 'org.test.plugins.dummyplugin'; |
| 29 | + |
| 30 | +const iosProjectFixture = path.join(FIXTURES, 'ios-config-xml'); |
| 31 | +const iosProject = path.join(FIXTURES, 'dummyProj'); |
| 32 | +const iosPlatform = path.join(iosProject, 'platforms/ios'); |
| 33 | +const dummyPlugin = path.join(FIXTURES, DUMMY_PLUGIN); |
| 34 | + |
| 35 | +describe('plugin add', () => { |
| 36 | + let api; |
| 37 | + |
| 38 | + beforeEach(() => { |
| 39 | + fs.ensureDirSync(iosPlatform); |
| 40 | + fs.copySync(iosProjectFixture, iosPlatform); |
| 41 | + api = new Api('ios', iosPlatform, new EventEmitter()); |
| 42 | + }); |
| 43 | + |
| 44 | + afterEach(() => { |
| 45 | + fs.removeSync(iosPlatform); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should handle plugin preference default values', () => { |
| 49 | + return api.addPlugin(new PluginInfo(dummyPlugin)) |
| 50 | + .then(() => { |
| 51 | + const cfg = new ConfigParser(api.locations.configXml); |
| 52 | + expect(cfg.getPreference('PluginPackageName', 'ios')).toEqual('com.example.friendstring'); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should handle plugin preference provided values', () => { |
| 57 | + return api.addPlugin(new PluginInfo(dummyPlugin), { variables: { NAME_SPACE: 'com.mycompany.myapp' } }) |
| 58 | + .then(() => { |
| 59 | + const cfg = new ConfigParser(api.locations.configXml); |
| 60 | + expect(cfg.getPreference('PluginNameSpace', 'ios')).toEqual('com.mycompany.myapp'); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments