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