Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Jul 30, 2024
1 parent 860bb2d commit f15040f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 70 deletions.
82 changes: 42 additions & 40 deletions packages/page-objects/src/components/editor/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export class TextEditor extends Editor {
if (await this.isLine(line)) {
break;
}
await inputArea.getDriver().actions().clear();
await inputArea.sendKeys(lineKey);
await inputArea.getDriver().sleep(500);
if (await this.isLine(line)) {
Expand All @@ -409,25 +410,25 @@ export class TextEditor extends Editor {
break;
}

try {
await this.waitForCursorPositionAtLine(nextLine);
} catch (error) {
if (await this.isLine(line)) {
break;
}
await inputArea.getDriver().actions().clear();
await inputArea.sendKeys(lineKey);
await inputArea.getDriver().sleep(500);
if (await this.isLine(line)) {
break;
}
// try {
// await this.waitForCursorPositionAtLine(nextLine);
// } catch (error) {
// if (await this.isLine(line)) {
// break;
// }
// await inputArea.getDriver().actions().clear();
// await inputArea.sendKeys(lineKey);
// await inputArea.getDriver().sleep(500);
// if (await this.isLine(line)) {
// break;
// }

if (lineKey === Key.DOWN && nextLine < line) {
await this.waitForCursorPositionAtLine(nextLine);
} else {
await this.waitForCursorPositionAtLine(line);
}
}
// if (lineKey === Key.DOWN && nextLine < line) {
// await this.waitForCursorPositionAtLine(nextLine);
// } else {
// await this.waitForCursorPositionAtLine(line);
// }
// }
}
}

Expand All @@ -447,6 +448,7 @@ export class TextEditor extends Editor {
if (await this.isColumn(column)) {
break;
}
await inputArea.getDriver().actions().clear();
await inputArea.sendKeys(columnKey);
await inputArea.getDriver().sleep(500);
if (await this.isColumn(column)) {
Expand All @@ -465,28 +467,28 @@ export class TextEditor extends Editor {
break;
}

try {
await this.waitForCursorPositionAtColumn(nextCol);
} catch (error) {
if (await this.isColumn(column)) {
break;
}
await inputArea.getDriver().actions().clear();
await inputArea.sendKeys(columnKey);
await inputArea.getDriver().sleep(500);
if (await this.isColumn(column)) {
break;
}
if ((await this.getCoordinates())[0] !== coordinates[0]) {
throw new Error(`Column number ${column} is not accessible on line ${coordinates[0]}`);
}

if (columnKey === Key.RIGHT && nextCol < column) {
await this.waitForCursorPositionAtColumn(nextCol);
} else {
await this.waitForCursorPositionAtColumn(column);
}
}
// try {
// await this.waitForCursorPositionAtColumn(nextCol);
// } catch (error) {
// if (await this.isColumn(column)) {
// break;
// }
// await inputArea.getDriver().actions().clear();
// await inputArea.sendKeys(columnKey);
// await inputArea.getDriver().sleep(500);
// if (await this.isColumn(column)) {
// break;
// }
// if ((await this.getCoordinates())[0] !== coordinates[0]) {
// throw new Error(`Column number ${column} is not accessible on line ${coordinates[0]}`);
// }

// if (columnKey === Key.RIGHT && nextCol < column) {
// await this.waitForCursorPositionAtColumn(nextCol);
// } else {
// await this.waitForCursorPositionAtColumn(column);
// }
// }
}
}

Expand Down
62 changes: 32 additions & 30 deletions tests/test-project/src/test/editor/textEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ describe('TextEditor', function () {
it('getCoordinates works', async function () {
this.timeout(20000);

await editor.moveCursor(1, 1);
await editor.setCursor(1, 1);
expect(await editor.getCoordinates()).to.deep.equal([1, 1]);

const lineCount = await editor.getNumberOfLines();
const lastLine = await editor.getTextAtLine(lineCount);

await editor.moveCursor(lineCount, lastLine.length);
await editor.setCursor(lineCount, lastLine.length);
expect(await editor.getCoordinates()).to.deep.equal([lineCount, lastLine.length]);
});

Expand Down Expand Up @@ -181,12 +181,12 @@ describe('TextEditor', function () {

describe('move/set cursor', function () {
const params = [
{ file: 'file-with-spaces.ts', spaces: 'spaces' },
{ file: 'file-with-tabs.ts', spaces: 'tabs' },
{ file: 'file-with-spaces.ts', indent: 'spaces' },
{ file: 'file-with-tabs.ts', indent: 'tabs' },
];

params.forEach((param) =>
describe(`file using ${param.spaces}`, function () {
describe(`file using ${param.indent}`, function () {
let editor: TextEditor;
let ew: EditorView;

Expand All @@ -203,27 +203,28 @@ describe('TextEditor', function () {
editor = (await ew.openEditor(param.file)) as TextEditor;
});

afterEach(async function () {
// await editor.setCursor(1, 1);
await ew.closeEditor(param.file);
});
// afterEach(async function () {
// await editor.setCursor(1, 1);
// await ew.closeEditor(param.file);
// });

[
[2, 5],
[3, 9],
].forEach((coor) =>
it(`move cursor to position [Ln ${coor[0]}, Col ${coor[1]}]`, async function () {
this.timeout(30000);
await editor.moveCursor(coor[0], coor[1]);
// await editor.getDriver().wait(
// async () => {
// const actualCoor = await editor.getCoordinates();
// return actualCoor[0] === coor[0] && actualCoor[1] === coor[1];
// },
// 15_000,
// `The cursor was not properly moved to position: ${coor}`,
// );
expect(await editor.getCoordinates()).to.deep.equal(coor);
await editor.getDriver().wait(
async () => {
await editor.moveCursor(coor[0], coor[1]);
const current = await editor.getCoordinates();
return current[0] === coor[0] && current[1] === coor[1];
},
10_000,
`Unable to move cursor at position: ${coor}`,
);
// await editor.moveCursor(coor[0], coor[1]);
// expect(await editor.getCoordinates()).to.deep.equal(coor);
}),
);

Expand All @@ -232,18 +233,19 @@ describe('TextEditor', function () {
[2, 12],
[3, 15],
].forEach((coor) =>
(param.spaces === 'tabs' ? it.skip : it)(`set cursor to position [Ln ${coor[0]}, Col ${coor[1]}]`, async function () {
(param.indent === 'tabs' ? it.skip : it)(`set cursor to position [Ln ${coor[0]}, Col ${coor[1]}]`, async function () {
this.timeout(30000);
await editor.setCursor(coor[0], coor[1]);
// await editor.getDriver().wait(
// async () => {
// const actualCoor = await editor.getCoordinates();
// return actualCoor[0] === coor[0] && actualCoor[1] === coor[1];
// },
// 15_000,
// `The cursor was not properly set to position: ${coor}`,
// );
expect(await editor.getCoordinates()).to.deep.equal(coor);
await editor.getDriver().wait(
async () => {
await editor.setCursor(coor[0], coor[1]);
const current = await editor.getCoordinates();
return current[0] === coor[0] && current[1] === coor[1];
},
10_000,
`Unable to set cursor at position: ${coor}`,
);
// await editor.setCursor(coor[0], coor[1]);
// expect(await editor.getCoordinates()).to.deep.equal(coor);
}),
);
}),
Expand Down

0 comments on commit f15040f

Please sign in to comment.