UNPKG

@theia-extension-tester/tests

Version:

Tests for theia-extension-tester package.

211 lines 10.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const page_objects_1 = require("@theia-extension-tester/page-objects"); const File_1 = require("./utils/File"); const path = require("path"); const repeat_1 = require("@theia-extension-tester/repeat"); const lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`; describe('TextEditor', function () { this.timeout(40000); let editorView; let tree; let editor; let menu; const FILE = "quarkus-quickstarts/Editor.ts"; let filePath; before(function () { return __awaiter(this, void 0, void 0, function* () { editorView = new page_objects_1.EditorView(); tree = yield File_1.getExplorerSection(); yield editorView.closeAllEditors(); yield File_1.deleteFiles(FILE); editor = (yield tree.createFile(FILE)); filePath = path.join(File_1.getProjectPath(), FILE); }); }); beforeEach(function () { return __awaiter(this, void 0, void 0, function* () { yield editor.clearText(); }); }); afterEach(function () { return __awaiter(this, void 0, void 0, function* () { yield (menu === null || menu === void 0 ? void 0 : menu.close()); menu = undefined; }); }); after(function () { return __awaiter(this, void 0, void 0, function* () { yield editor.save(); yield File_1.deleteFiles(FILE); yield editorView.closeAllEditors(); }); }); it('getTitle', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getTitle()).equals(path.basename(FILE)); }); }); it('getTab', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield (yield editor.getTab()).getTitle()).equals(path.basename(FILE)); }); }); it('openContextMenu', function () { return __awaiter(this, void 0, void 0, function* () { menu = (yield editor.openContextMenu()); const titles = yield Promise.all((yield menu.getItems()).map((item) => item.getLabel())); chai_1.expect(titles).to.include.members(['Call Hierarchy', 'Peek', 'Change All Occurrences', 'Redo', 'Copy']); chai_1.expect(titles).not.to.include.members(['']); }); }); it('isDirty', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.isDirty()).to.be.false; yield editor.setTextAtLine(1, 'Hello world'); yield repeat_1.repeat(() => editor.isDirty(), { timeout: this.timeout() - 2000, message: 'Expected editor to be dirty.' }); }); }); it('save', function () { return __awaiter(this, void 0, void 0, function* () { this.timeout(100000); yield repeat_1.repeat(() => __awaiter(this, void 0, void 0, function* () { return (yield editor.isDirty()) === false; }), { timeout: this.timeout() - 2000, message: 'Expected editor not to be dirty. #1' }); yield editor.setTextAtLine(1, 'Hello world'); yield repeat_1.repeat(() => editor.isDirty(), { timeout: this.timeout() - 2000, message: 'Expected editor to be dirty.' }); yield editor.save(90000); yield repeat_1.repeat(() => __awaiter(this, void 0, void 0, function* () { return (yield editor.isDirty()) === false; }), { timeout: this.timeout() - 2000, message: 'Expected editor not to be dirty. #2' }); }); }); it('getFileUri', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getFileUri()).equals(`file://${filePath}`); }); }); it('getFilePath', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getFilePath()).equals(filePath); }); }); it('toggleContentAssist - open', function () { return __awaiter(this, void 0, void 0, function* () { const assist = yield editor.toggleContentAssist(true); yield assist.getDriver().wait(() => assist.isLoaded(), this.timeout() - 1000, 'Could not load assist.'); menu = assist; chai_1.expect(yield assist.isDisplayed()).to.be.true; chai_1.expect(yield assist.isLoaded()).to.be.true; }); }); it('toggleContentAssist - close', function () { return __awaiter(this, void 0, void 0, function* () { menu = (yield editor.toggleContentAssist(true)); chai_1.expect(yield menu.isDisplayed()).to.be.true; yield editor.toggleContentAssist(false); menu = new page_objects_1.ContentAssist(undefined, editor); chai_1.expect(yield menu.isDisplayed()).to.be.false; }); }); it('getText', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem.trimEnd()); }); }); it('setText', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); yield editor.clearText(); yield editor.setText(''); chai_1.expect(yield editor.getText()).equals('\n'); }); }); it('clearText', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); yield editor.clearText(); chai_1.expect(yield editor.getText()).equals('\n'); }); }); it('getTextAtLine', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); const lines = lorem.split('\n'); for (let i = 0; i < lines.length; i++) { const line = lines[i]; chai_1.expect(yield editor.getTextAtLine(i + 1)).equals(line); } }); }); it('setTextAtLine', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); yield editor.setTextAtLine(2, 'Hello world'); chai_1.expect(yield editor.getTextAtLine(2)).equals('Hello world'); }); }); it('typeText', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); const lines = lorem.split('\n'); const startPhrase = 'start'; const middlePhrase = 'middle'; const endPhrase = 'end'; for (let i = 0; i < lines.length; i++) { const editorLine = yield editor.getTextAtLine(i + 1); const median = Math.floor(editorLine.length / 2); yield editor.typeText(i + 1, 1, 'start'); yield editor.typeText(i + 1, median + 1, 'middle'); yield editor.typeText(i + 1, editorLine.length + startPhrase.length + middlePhrase.length + 1, 'end'); const finalLine = yield editor.getTextAtLine(i + 1); chai_1.expect(finalLine.slice(0, startPhrase.length)).equals(startPhrase); chai_1.expect(finalLine.substr(median, middlePhrase.length)).equals(middlePhrase); chai_1.expect(finalLine.slice(-endPhrase.length)).equals(endPhrase); } }); }); it('moveCursor', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); yield editor.moveCursor(2, 5); }); }); it('getNumberOfLines', function () { return __awaiter(this, void 0, void 0, function* () { chai_1.expect(yield editor.getText()).equals('\n'); yield editor.setText(lorem); chai_1.expect(yield editor.getText()).equals(lorem); chai_1.expect(yield editor.getNumberOfLines()).equals(lorem.split('\n').length); }); }); it.skip('formatDocument', function () { return __awaiter(this, void 0, void 0, function* () { }); }); }); //# sourceMappingURL=TextEditor.test.js.map