Path: blob/main/src/vs/workbench/services/filesConfiguration/test/browser/filesConfigurationService.test.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import { DisposableStore } from '../../../../../base/common/lifecycle.js';7import { URI } from '../../../../../base/common/uri.js';8import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';9import { TestFilesConfigurationService, TestServiceAccessor, workbenchInstantiationService } from '../../../../test/browser/workbenchTestServices.js';1011suite('FilesConfigurationService', () => {1213const disposables = new DisposableStore();14let service: TestFilesConfigurationService;1516setup(() => {17const instantiationService = workbenchInstantiationService(undefined, disposables);18service = instantiationService.createInstance(TestServiceAccessor).filesConfigurationService;19});2021teardown(() => {22disposables.clear();23});2425ensureNoDisposablesAreLeakedInTestSuite();2627test('updateReadonly with single resource fires onDidChangeReadonly once', async () => {28const resource = URI.file('/test/file.txt');29let eventCount = 0;30disposables.add(service.onDidChangeReadonly(() => eventCount++));3132await service.updateReadonly(resource, true);3334assert.strictEqual(eventCount, 1);35assert.strictEqual(!!service.isReadonly(resource), true);36});3738test('updateReadonly with array of resources fires onDidChangeReadonly once', async () => {39const resources = [40URI.file('/test/file1.txt'),41URI.file('/test/file2.txt'),42URI.file('/test/file3.txt'),43];44let eventCount = 0;45disposables.add(service.onDidChangeReadonly(() => eventCount++));4647await service.updateReadonly(resources, true);4849assert.strictEqual(eventCount, 1);50for (const resource of resources) {51assert.strictEqual(!!service.isReadonly(resource), true);52}53});5455test('updateReadonly with empty array does not fire onDidChangeReadonly', async () => {56let eventCount = 0;57disposables.add(service.onDidChangeReadonly(() => eventCount++));5859await service.updateReadonly([], true);6061assert.strictEqual(eventCount, 0);62});6364test('updateReadonly with array supports reset', async () => {65const resources = [66URI.file('/test/file1.txt'),67URI.file('/test/file2.txt'),68];6970await service.updateReadonly(resources, true);71for (const resource of resources) {72assert.strictEqual(!!service.isReadonly(resource), true);73}7475await service.updateReadonly(resources, 'reset');76for (const resource of resources) {77assert.strictEqual(service.isReadonly(resource), false);78}79});8081test('multiple single updateReadonly calls fire onDidChangeReadonly multiple times', async () => {82const resources = [83URI.file('/test/file1.txt'),84URI.file('/test/file2.txt'),85URI.file('/test/file3.txt'),86];87let eventCount = 0;88disposables.add(service.onDidChangeReadonly(() => eventCount++));8990for (const resource of resources) {91await service.updateReadonly(resource, true);92}9394assert.strictEqual(eventCount, 3);95});96});979899