1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | var rewire = require('rewire');
|
21 | var et = require('elementtree');
|
22 | var xml = require('cordova-common').xmlHelpers;
|
23 | var ConfigParser = require('../../template/cordova/lib/ConfigParser');
|
24 | var ConfigParserOrig = require('cordova-common').ConfigParser;
|
25 | var AppxManifest = require('../../template/cordova/lib/AppxManifest');
|
26 |
|
27 | var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?><widget/>';
|
28 |
|
29 | describe('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 |
|
37 |
|
38 |
|
39 |
|
40 | describe('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 |
|
106 | describe('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 | });
|