Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/test/stringEnumPolicy.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 { StringEnumPolicy } from '../policies/stringEnumPolicy.ts';
8
import { PolicyType, type LanguageTranslations } from '../policies/types.ts';
9
import type { CategoryDto, PolicyDto } from '../policies/policyDto.ts';
10
11
suite('StringEnumPolicy', () => {
12
const mockCategory: CategoryDto = {
13
key: 'test.category',
14
name: { value: 'Category1', key: 'test.category' },
15
};
16
17
const mockPolicy: PolicyDto = {
18
key: 'test.stringenum.policy',
19
name: 'TestStringEnumPolicy',
20
category: 'Category1',
21
minimumVersion: '1.0',
22
type: 'string',
23
localization: {
24
description: { key: 'test.policy.description', value: 'Test policy description' },
25
enumDescriptions: [
26
{ key: 'test.option.one', value: 'Option One' },
27
{ key: 'test.option.two', value: 'Option Two' },
28
{ key: 'test.option.three', value: 'Option Three' }
29
]
30
},
31
enum: ['auto', 'manual', 'disabled']
32
};
33
34
test('should create StringEnumPolicy from factory method', () => {
35
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
36
37
assert.ok(policy);
38
assert.strictEqual(policy.name, 'TestStringEnumPolicy');
39
assert.strictEqual(policy.minimumVersion, '1.0');
40
assert.strictEqual(policy.category.name.nlsKey, mockCategory.name.key);
41
assert.strictEqual(policy.category.name.value, mockCategory.name.value);
42
assert.strictEqual(policy.type, PolicyType.StringEnum);
43
});
44
45
test('should render ADMX elements correctly', () => {
46
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
47
48
assert.ok(policy);
49
50
const admx = policy.renderADMX('TestKey');
51
52
assert.deepStrictEqual(admx, [
53
'<policy name="TestStringEnumPolicy" class="Both" displayName="$(string.TestStringEnumPolicy)" explainText="$(string.TestStringEnumPolicy_test_policy_description)" key="Software\\Policies\\Microsoft\\TestKey" presentation="$(presentation.TestStringEnumPolicy)">',
54
'\t<parentCategory ref="test.category" />',
55
'\t<supportedOn ref="Supported_1_0" />',
56
'\t<elements>',
57
'<enum id="TestStringEnumPolicy" valueName="TestStringEnumPolicy">',
58
'\t<item displayName="$(string.TestStringEnumPolicy_test_option_one)"><value><string>auto</string></value></item>',
59
'\t<item displayName="$(string.TestStringEnumPolicy_test_option_two)"><value><string>manual</string></value></item>',
60
'\t<item displayName="$(string.TestStringEnumPolicy_test_option_three)"><value><string>disabled</string></value></item>',
61
'</enum>',
62
'\t</elements>',
63
'</policy>'
64
]);
65
});
66
67
test('should render ADML strings correctly', () => {
68
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
69
70
assert.ok(policy);
71
72
const admlStrings = policy.renderADMLStrings();
73
74
assert.deepStrictEqual(admlStrings, [
75
'<string id="TestStringEnumPolicy">TestStringEnumPolicy</string>',
76
'<string id="TestStringEnumPolicy_test_policy_description">Test policy description</string>',
77
'<string id="TestStringEnumPolicy_test_option_one">Option One</string>',
78
'<string id="TestStringEnumPolicy_test_option_two">Option Two</string>',
79
'<string id="TestStringEnumPolicy_test_option_three">Option Three</string>'
80
]);
81
});
82
83
test('should render ADML strings with translations', () => {
84
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
85
86
assert.ok(policy);
87
88
const translations: LanguageTranslations = {
89
'': {
90
'test.policy.description': 'Translated description',
91
'test.option.one': 'Translated Option One',
92
'test.option.two': 'Translated Option Two'
93
}
94
};
95
96
const admlStrings = policy.renderADMLStrings(translations);
97
98
assert.deepStrictEqual(admlStrings, [
99
'<string id="TestStringEnumPolicy">TestStringEnumPolicy</string>',
100
'<string id="TestStringEnumPolicy_test_policy_description">Translated description</string>',
101
'<string id="TestStringEnumPolicy_test_option_one">Translated Option One</string>',
102
'<string id="TestStringEnumPolicy_test_option_two">Translated Option Two</string>',
103
'<string id="TestStringEnumPolicy_test_option_three">Option Three</string>'
104
]);
105
});
106
107
test('should render ADML presentation correctly', () => {
108
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
109
110
assert.ok(policy);
111
112
const presentation = policy.renderADMLPresentation();
113
114
assert.strictEqual(presentation, '<presentation id="TestStringEnumPolicy"><dropdownList refId="TestStringEnumPolicy" /></presentation>');
115
});
116
117
test('should render JSON value correctly', () => {
118
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
119
120
assert.ok(policy);
121
122
const jsonValue = policy.renderJsonValue();
123
124
assert.strictEqual(jsonValue, 'auto');
125
});
126
127
test('should render profile value correctly', () => {
128
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
129
130
assert.ok(policy);
131
132
const profileValue = policy.renderProfileValue();
133
134
assert.strictEqual(profileValue, '<string>auto</string>');
135
});
136
137
test('should render profile correctly', () => {
138
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
139
140
assert.ok(policy);
141
142
const profile = policy.renderProfile();
143
144
assert.strictEqual(profile.length, 2);
145
assert.strictEqual(profile[0], '<key>TestStringEnumPolicy</key>');
146
assert.strictEqual(profile[1], '<string>auto</string>');
147
});
148
149
test('should render profile manifest value correctly', () => {
150
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
151
152
assert.ok(policy);
153
154
const manifestValue = policy.renderProfileManifestValue();
155
156
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<string>auto</string>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_title</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n<key>pfm_range_list</key>\n<array>\n\t<string>auto</string>\n\t<string>manual</string>\n\t<string>disabled</string>\n</array>');
157
});
158
159
test('should render profile manifest value with translations', () => {
160
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
161
162
assert.ok(policy);
163
164
const translations: LanguageTranslations = {
165
'': {
166
'test.policy.description': 'Translated manifest description'
167
}
168
};
169
170
const manifestValue = policy.renderProfileManifestValue(translations);
171
172
assert.strictEqual(manifestValue, '<key>pfm_default</key>\n<string>auto</string>\n<key>pfm_description</key>\n<string>Translated manifest description</string>\n<key>pfm_name</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_title</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n<key>pfm_range_list</key>\n<array>\n\t<string>auto</string>\n\t<string>manual</string>\n\t<string>disabled</string>\n</array>');
173
});
174
175
test('should render profile manifest correctly', () => {
176
const policy = StringEnumPolicy.from(mockCategory, mockPolicy);
177
178
assert.ok(policy);
179
180
const manifest = policy.renderProfileManifest();
181
182
assert.strictEqual(manifest, '<dict>\n<key>pfm_default</key>\n<string>auto</string>\n<key>pfm_description</key>\n<string>Test policy description</string>\n<key>pfm_name</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_title</key>\n<string>TestStringEnumPolicy</string>\n<key>pfm_type</key>\n<string>string</string>\n<key>pfm_range_list</key>\n<array>\n\t<string>auto</string>\n\t<string>manual</string>\n\t<string>disabled</string>\n</array>\n</dict>');
183
});
184
});
185
186