UNPKG

4.74 kBJavaScriptView Raw
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
20var rewire = require('rewire');
21var et = require('elementtree');
22var xml = require('cordova-common').xmlHelpers;
23var ConfigParser = require('../../template/cordova/lib/ConfigParser');
24var ConfigParserOrig = require('cordova-common').ConfigParser;
25var AppxManifest = require('../../template/cordova/lib/AppxManifest');
26
27var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?><widget/>';
28
29describe('Windows ConfigParser', function () {
30 it('should extend ConfigParser from cordova-common', function () {
31 expect(ConfigParser.prototype instanceof ConfigParserOrig).toBe(true);
32 });
33});
34
35/***
36 * Unit tests for validating that min/max versions are correctly obtained
37 * (for the function getAllMinMaxUAPVersions) from prepare.js.
38 **/
39
40describe('getAllMinMaxUAPVersions method', function () {
41
42 var mockConfig;
43 beforeEach(function () {
44 spyOn(xml, 'parseElementtreeSync').and.returnValue(new et.ElementTree(et.XML(TEST_XML)));
45
46 mockConfig = new ConfigParser('/some/file');
47 });
48
49 it('should correctly transform all versions as a baseline.', function () {
50 spyOn(mockConfig, 'getMatchingPreferences').and.returnValue([
51 { name: 'Windows.Universal-MinVersion', value: '10.0.9910.0' },
52 { name: 'Windows.Universal-MaxVersionTested', value: '10.0.9917.0' },
53 { name: 'Windows.Desktop-MinVersion', value: '10.0.9910.0' },
54 { name: 'Microsoft.Xbox-MaxVersionTested', value: '10.0.9917.0' }
55 ]);
56
57 var versionSet = mockConfig.getAllMinMaxUAPVersions();
58 var ver9910 = '10.0.9910.0';
59 var ver9917 = '10.0.9917.0';
60
61 expect(versionSet.length).toBe(3);
62
63 expect(versionSet[0].Name).toBe('Windows.Universal');
64 expect(versionSet[0].MinVersion).toBe(ver9910);
65 expect(versionSet[0].MaxVersionTested).toBe(ver9917);
66
67 expect(versionSet[1].Name).toBe('Windows.Desktop');
68 expect(versionSet[1].MinVersion).toBe(ver9910);
69 expect(versionSet[1].MaxVersionTested).toBe(ver9910);
70
71 expect(versionSet[2].Name).toBe('Microsoft.Xbox');
72 expect(versionSet[2].MinVersion).toBe(ver9917);
73 expect(versionSet[2].MaxVersionTested).toBe(ver9917);
74 });
75
76 it('should produce versions correctly even when the config file has no settings.', function () {
77 spyOn(mockConfig, 'getMatchingPreferences').and.returnValue([]);
78
79 var versionSet = mockConfig.getAllMinMaxUAPVersions();
80 var verBaseline = rewire('../../template/cordova/lib/ConfigParser')
81 .__get__('BASE_UAP_VERSION').toString();
82
83 expect(versionSet.length).toBe(1);
84 expect(versionSet[0].Name).toBe('Windows.Universal');
85 expect(versionSet[0].MinVersion).toBe(verBaseline);
86 expect(versionSet[0].MaxVersionTested).toBe(verBaseline);
87
88 });
89
90 it('should fail with a RangeError if version specified incorrectly', function () {
91 spyOn(mockConfig, 'getMatchingPreferences')
92 .and.returnValue([
93 { name: 'Windows.Universal-MinVersion', value: '10.0.9910.f' },
94 { name: 'Windows.Universal-MaxVersionTested', value: '10.0.9917.0' }
95 ]);
96
97 try {
98 mockConfig.getAllMinMaxUAPVersions();
99 expect(false).toBe(true);
100 } catch (ex) {
101 expect(ex.constructor).toBe(RangeError);
102 }
103 });
104});
105
106describe('getConfigFiles method', function () {
107 var mockConfig;
108 beforeEach(function () {
109 spyOn(xml, 'parseElementtreeSync').and.returnValue(new et.ElementTree(et.XML(TEST_XML)));
110 mockConfig = new ConfigParser('/some/file');
111 });
112
113 it('should call AppxManifest.processChanges to distribute changes across manifests', function () {
114 spyOn(AppxManifest, 'processChanges').and.callThrough();
115 mockConfig.getConfigFiles('windows');
116 expect(AppxManifest.processChanges).toHaveBeenCalled();
117 });
118});