Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/filesConfiguration/test/browser/filesConfigurationService.test.ts
13405 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 { DisposableStore } from '../../../../../base/common/lifecycle.js';
8
import { URI } from '../../../../../base/common/uri.js';
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
10
import { TestFilesConfigurationService, TestServiceAccessor, workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';
11
12
suite('FilesConfigurationService', () => {
13
14
const disposables = new DisposableStore();
15
let service: TestFilesConfigurationService;
16
17
setup(() => {
18
const instantiationService = workbenchInstantiationService(undefined, disposables);
19
service = instantiationService.createInstance(TestServiceAccessor).filesConfigurationService;
20
});
21
22
teardown(() => {
23
disposables.clear();
24
});
25
26
ensureNoDisposablesAreLeakedInTestSuite();
27
28
test('updateReadonly with single resource fires onDidChangeReadonly once', async () => {
29
const resource = URI.file('/test/file.txt');
30
let eventCount = 0;
31
disposables.add(service.onDidChangeReadonly(() => eventCount++));
32
33
await service.updateReadonly(resource, true);
34
35
assert.strictEqual(eventCount, 1);
36
assert.strictEqual(!!service.isReadonly(resource), true);
37
});
38
39
test('updateReadonly with array of resources fires onDidChangeReadonly once', async () => {
40
const resources = [
41
URI.file('/test/file1.txt'),
42
URI.file('/test/file2.txt'),
43
URI.file('/test/file3.txt'),
44
];
45
let eventCount = 0;
46
disposables.add(service.onDidChangeReadonly(() => eventCount++));
47
48
await service.updateReadonly(resources, true);
49
50
assert.strictEqual(eventCount, 1);
51
for (const resource of resources) {
52
assert.strictEqual(!!service.isReadonly(resource), true);
53
}
54
});
55
56
test('updateReadonly with empty array does not fire onDidChangeReadonly', async () => {
57
let eventCount = 0;
58
disposables.add(service.onDidChangeReadonly(() => eventCount++));
59
60
await service.updateReadonly([], true);
61
62
assert.strictEqual(eventCount, 0);
63
});
64
65
test('updateReadonly with array supports reset', async () => {
66
const resources = [
67
URI.file('/test/file1.txt'),
68
URI.file('/test/file2.txt'),
69
];
70
71
await service.updateReadonly(resources, true);
72
for (const resource of resources) {
73
assert.strictEqual(!!service.isReadonly(resource), true);
74
}
75
76
await service.updateReadonly(resources, 'reset');
77
for (const resource of resources) {
78
assert.strictEqual(service.isReadonly(resource), false);
79
}
80
});
81
82
test('multiple single updateReadonly calls fire onDidChangeReadonly multiple times', async () => {
83
const resources = [
84
URI.file('/test/file1.txt'),
85
URI.file('/test/file2.txt'),
86
URI.file('/test/file3.txt'),
87
];
88
let eventCount = 0;
89
disposables.add(service.onDidChangeReadonly(() => eventCount++));
90
91
for (const resource of resources) {
92
await service.updateReadonly(resource, true);
93
}
94
95
assert.strictEqual(eventCount, 3);
96
});
97
});
98
99