Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/test/booleanPolicy.test.ts
4772 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { BooleanPolicy } from '../policies/booleanPolicy.ts';
8
import { type LanguageTranslations, PolicyType } from '../policies/types.ts';
9
import type { CategoryDto, PolicyDto } from '../policies/policyDto.ts';
10
11
suite('BooleanPolicy', () => {
12
const mockCategory: CategoryDto = {
13
key: 'test.category',
14
name: { value: 'Category1', key: 'test.category' },
15
};
16
17
const mockPolicy: PolicyDto = {
18
key: 'test.boolean.policy',
19
name: 'TestBooleanPolicy',
20
category: 'Category1',
21
minimumVersion: '1.0',
22
type: 'boolean',
23
localization: {
24
description: { key: 'test.policy.description', value: 'Test policy description' }
25
}
26
};
27
28
test('should create BooleanPolicy from factory method', () => {
29
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
30
31
assert.ok(policy);
32
assert.strictEqual(policy.name, 'TestBooleanPolicy');
33
assert.strictEqual(policy.minimumVersion, '1.0');
34
assert.strictEqual(policy.category.name.nlsKey, mockCategory.name.key);
35
assert.strictEqual(policy.category.name.value, mockCategory.name.value);
36
assert.strictEqual(policy.type, PolicyType.Boolean);
37
});
38
39
test('should render ADMX elements correctly', () => {
40
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
41
42
assert.ok(policy);
43
44
const admx = policy.renderADMX('TestKey');
45
46
assert.deepStrictEqual(admx, [
47
'<policy name="TestBooleanPolicy" class="Both" displayName="$(string.TestBooleanPolicy)" explainText="$(string.TestBooleanPolicy_test_policy_description)" key="Software\\Policies\\Microsoft\\TestKey" presentation="$(presentation.TestBooleanPolicy)">',
48
'\t<parentCategory ref="test.category" />',
49
'\t<supportedOn ref="Supported_1_0" />',
50
'\t<elements>',
51
'<boolean id="TestBooleanPolicy" valueName="TestBooleanPolicy">',
52
'\t<trueValue><decimal value="1" /></trueValue><falseValue><decimal value="0" /></falseValue>',
53
'</boolean>',
54
'\t</elements>',
55
'</policy>'
56
]);
57
});
58
59
test('should render ADML strings correctly', () => {
60
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
61
62
assert.ok(policy);
63
64
const admlStrings = policy.renderADMLStrings();
65
66
assert.deepStrictEqual(admlStrings, [
67
'<string id="TestBooleanPolicy">TestBooleanPolicy</string>',
68
'<string id="TestBooleanPolicy_test_policy_description">Test policy description</string>'
69
]);
70
});
71
72
test('should render ADML strings with translations', () => {
73
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
74
75
assert.ok(policy);
76
77
const translations: LanguageTranslations = {
78
'': {
79
'test.policy.description': 'Translated description'
80
}
81
};
82
83
const admlStrings = policy.renderADMLStrings(translations);
84
85
assert.deepStrictEqual(admlStrings, [
86
'<string id="TestBooleanPolicy">TestBooleanPolicy</string>',
87
'<string id="TestBooleanPolicy_test_policy_description">Translated description</string>'
88
]);
89
});
90
91
test('should render ADML presentation correctly', () => {
92
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
93
94
assert.ok(policy);
95
96
const presentation = policy.renderADMLPresentation();
97
98
assert.strictEqual(presentation, '<presentation id="TestBooleanPolicy"><checkBox refId="TestBooleanPolicy">TestBooleanPolicy</checkBox></presentation>');
99
});
100
101
test('should render JSON value correctly', () => {
102
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
103
104
assert.ok(policy);
105
106
const jsonValue = policy.renderJsonValue();
107
108
assert.strictEqual(jsonValue, false);
109
});
110
111
test('should render profile value correctly', () => {
112
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
113
114
assert.ok(policy);
115
116
const profileValue = policy.renderProfileValue();
117
118
assert.strictEqual(profileValue, '<false/>');
119
});
120
121
test('should render profile correctly', () => {
122
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
123
124
assert.ok(policy);
125
126
const profile = policy.renderProfile();
127
128
assert.strictEqual(profile.length, 2);
129
assert.strictEqual(profile[0], '<key>TestBooleanPolicy</key>');
130
assert.strictEqual(profile[1], '<false/>');
131
});
132
133
test('should render profile manifest value correctly', () => {
134
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
135
136
assert.ok(policy);
137
138
const manifestValue = policy.renderProfileManifestValue();
139
140
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<false/>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_title</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_type</key>\n<string>boolean</string>');
141
});
142
143
test('should render profile manifest value with translations', () => {
144
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
145
146
assert.ok(policy);
147
148
const translations: LanguageTranslations = {
149
'': {
150
'test.policy.description': 'Translated manifest description'
151
}
152
};
153
154
const manifestValue = policy.renderProfileManifestValue(translations);
155
156
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<false/>\n<key>pfm_description</key>\n<string>Translated manifest description</string>\n<key>pfm_name</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_title</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_type</key>\n<string>boolean</string>');
157
});
158
159
test('should render profile manifest correctly', () => {
160
const policy = BooleanPolicy.from(mockCategory, mockPolicy);
161
162
assert.ok(policy);
163
164
const manifest = policy.renderProfileManifest();
165
166
assert.strictEqual(manifest, '<dict>\n<key>pfm_default</key>\n<false/>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_title</key>\n<string>TestBooleanPolicy</string>\n<key>pfm_type</key>\n<string>boolean</string>\n</dict>');
167
});
168
});
169
170