提交 1a95439a 编写于 作者: B Benjamin Pasero

more textfileservice tests

上级 56b19635
......@@ -20,7 +20,7 @@ import {IConfigurationService, getConfigurationValue, IConfigurationValue} from
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IEditorInput, IEditorModel, Position, Direction, IEditor, IResourceInput, ITextEditorModel} from 'vs/platform/editor/common/editor';
import {IEditorInput, IEditorOptions, IEditorModel, Position, Direction, IEditor, IResourceInput, ITextEditorModel} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
import {IUntitledEditorService, UntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IMessageService, IConfirmation} from 'vs/platform/message/common/message';
......@@ -413,9 +413,9 @@ export class TestEditorGroupService implements IEditorGroupService {
export class TestEditorService implements IWorkbenchEditorService {
public _serviceBrand: any;
public activeEditorInput;
public activeEditorOptions;
public activeEditorPosition;
public activeEditorInput: IEditorInput;
public activeEditorOptions: IEditorOptions;
public activeEditorPosition: Position;
private callback: (method: string) => void;
......
......@@ -14,6 +14,8 @@ import {TestInstantiationService} from 'vs/test/utils/instantiationTestUtils';
import {TextFileEditorModel, CACHE} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {ITextFileService} from 'vs/workbench/parts/files/common/files';
import {ConfirmResult} from 'vs/workbench/common/editor';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {UntitledEditorModel} from 'vs/workbench/common/editor/untitledEditorModel';
function toResource(path) {
return URI.file(paths.join('C:\\', path));
......@@ -22,7 +24,8 @@ function toResource(path) {
class ServiceAccessor {
constructor(
@ILifecycleService public lifecycleService: TestLifecycleService,
@ITextFileService public textFileService: TestTextFileService
@ITextFileService public textFileService: TestTextFileService,
@IUntitledEditorService public untitledEditorService: IUntitledEditorService
) {
}
}
......@@ -52,6 +55,7 @@ suite('Files - TextFileServices', () => {
teardown(() => {
model.dispose();
CACHE.clear();
accessor.untitledEditorService.revertAll();
});
test('confirm onWillShutdown - no veto', function () {
......@@ -62,12 +66,13 @@ suite('Files - TextFileServices', () => {
});
test('confirm onWillShutdown - veto if user cancels', function (done) {
accessor.textFileService.setConfirmResult(ConfirmResult.CANCEL);
const service = accessor.textFileService;
service.setConfirmResult(ConfirmResult.CANCEL);
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.equal(accessor.textFileService.getDirty().length, 1);
assert.equal(service.getDirty().length, 1);
const event = new ShutdownEventImpl();
accessor.lifecycleService.fireWillShutdown(event);
......@@ -79,12 +84,13 @@ suite('Files - TextFileServices', () => {
});
test('confirm onWillShutdown - no veto if user does not want to save', function (done) {
accessor.textFileService.setConfirmResult(ConfirmResult.DONT_SAVE);
const service = accessor.textFileService;
service.setConfirmResult(ConfirmResult.DONT_SAVE);
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.equal(accessor.textFileService.getDirty().length, 1);
assert.equal(service.getDirty().length, 1);
const event = new ShutdownEventImpl();
accessor.lifecycleService.fireWillShutdown(event);
......@@ -96,12 +102,13 @@ suite('Files - TextFileServices', () => {
});
test('confirm onWillShutdown - save', function (done) {
accessor.textFileService.setConfirmResult(ConfirmResult.SAVE);
const service = accessor.textFileService;
service.setConfirmResult(ConfirmResult.SAVE);
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.equal(accessor.textFileService.getDirty().length, 1);
assert.equal(service.getDirty().length, 1);
const event = new ShutdownEventImpl();
accessor.lifecycleService.fireWillShutdown(event);
......@@ -114,4 +121,101 @@ suite('Files - TextFileServices', () => {
});
});
});
test('isDirty/getDirty - files and untitled', function (done) {
const service = accessor.textFileService;
model.load().then(() => {
assert.ok(!service.isDirty(model.getResource()));
model.textEditorModel.setValue('foo');
assert.ok(service.isDirty(model.getResource()));
assert.equal(service.getDirty().length, 1);
assert.equal(service.getDirty([model.getResource()])[0].toString(), model.getResource().toString());
const untitled = accessor.untitledEditorService.createOrGet();
return untitled.resolve().then((model: UntitledEditorModel) => {
assert.ok(!service.isDirty(untitled.getResource()));
assert.equal(service.getDirty().length, 1);
model.setValue('changed');
assert.ok(service.isDirty(untitled.getResource()));
assert.equal(service.getDirty().length, 2);
assert.equal(service.getDirty([untitled.getResource()])[0].toString(), untitled.getResource().toString());
done();
});
});
});
test('save - file', function (done) {
const service = accessor.textFileService;
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.ok(service.isDirty(model.getResource()));
return service.save(model.getResource()).then(res => {
assert.ok(res);
assert.ok(!service.isDirty(model.getResource()));
done();
});
});
});
test('saveAll - file', function (done) {
const service = accessor.textFileService;
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.ok(service.isDirty(model.getResource()));
return service.saveAll([model.getResource()]).then(res => {
assert.ok(res);
assert.ok(!service.isDirty(model.getResource()));
assert.equal(res.results.length, 1);
assert.equal(res.results[0].source.toString(), model.getResource().toString());
done();
});
});
});
test('saveAs - file', function (done) {
const service = accessor.textFileService;
service.setPromptPath(model.getResource().fsPath);
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.ok(service.isDirty(model.getResource()));
return service.saveAs(model.getResource()).then(res => {
assert.equal(res.toString(), model.getResource().toString());
assert.ok(!service.isDirty(model.getResource()));
done();
});
});
});
test('revert - file', function (done) {
const service = accessor.textFileService;
service.setPromptPath(model.getResource().fsPath);
model.load().then(() => {
model.textEditorModel.setValue('foo');
assert.ok(service.isDirty(model.getResource()));
return service.revert(model.getResource()).then(res => {
assert.ok(res);
assert.ok(!service.isDirty(model.getResource()));
done();
});
});
});
});
\ No newline at end of file
......@@ -25,6 +25,9 @@ suite('Workbench - Untitled Editor', () => {
setup(() => {
instantiationService = workbenchInstantiationService();
accessor = instantiationService.createInstance(ServiceAccessor);
});
teardown(() => {
accessor.untitledEditorService.revertAll();
});
......@@ -33,6 +36,8 @@ suite('Workbench - Untitled Editor', () => {
assert.equal(service.getAll().length, 0);
const input1 = service.createOrGet();
assert.equal(input1, service.createOrGet(input1.getResource()));
const input2 = service.createOrGet();
// get() / getAll()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册