Skip to content

Commit c2dc6c5

Browse files
javier-godoypaodb
authored andcommitted
test: add TestBench element for XTerm
1 parent edcf814 commit c2dc6c5

File tree

8 files changed

+184
-194
lines changed

8 files changed

+184
-194
lines changed

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/AbstractXTermTest.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/ClipboardFeatureIT.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,29 @@
2121

2222
import static org.hamcrest.Matchers.is;
2323
import static org.junit.Assert.assertThat;
24-
import com.vaadin.testbench.TestBenchElement;
24+
import java.util.List;
2525
import org.junit.Test;
2626
import org.openqa.selenium.interactions.Actions;
2727

28-
public class ClipboardFeatureIT extends AbstractXTermTest {
28+
public class ClipboardFeatureIT extends AbstractViewTest {
29+
30+
private static int[] intArray(Object obj) {
31+
return ((List<?>) obj).stream().mapToInt(i -> ((Long) i).intValue()).toArray();
32+
}
2933

3034
@Test
3135
public void testFeature() {
32-
TestBenchElement term = $("fc-xterm").first();
36+
XTermElement term = $(XTermElement.class).first();
3337

34-
write(term, "\\x1bcTEXT");
38+
term.write("\\x1bcTEXT");
3539

3640
int[] size =
3741
intArray(
3842
getCommandExecutor()
3943
.executeScript(
4044
"return [arguments[0].clientWidth, arguments[0].clientHeight]", term));
41-
getCommandExecutor()
42-
.executeScript("arguments[0].useSystemClipboard='false'", $("fc-xterm").first());
45+
46+
term.setUseSystemClipboard(false);
4347

4448
new Actions(driver)
4549
.moveToElement(term, -size[0] / 2, -size[1] / 2 + 10)
@@ -49,6 +53,6 @@ public void testFeature() {
4953
.perform();
5054

5155
new Actions(driver).contextClick().perform();
52-
assertThat(currentLine(term), is("TEXTTEXT"));
56+
assertThat(term.currentLine(), is("TEXTTEXT"));
5357
}
5458
}

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/ConsoleFeatureIT.java

Lines changed: 53 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,93 +19,89 @@
1919
*/
2020
package com.flowingcode.vaadin.addons.xterm.integration;
2121

22+
import static com.flowingcode.vaadin.addons.xterm.integration.Position.at;
2223
import static org.hamcrest.Matchers.is;
2324
import static org.hamcrest.Matchers.isEmptyString;
2425
import static org.junit.Assert.assertThat;
25-
import com.vaadin.testbench.TestBenchElement;
2626
import org.apache.commons.lang3.StringUtils;
2727
import org.junit.Test;
2828
import org.openqa.selenium.Keys;
29-
import org.openqa.selenium.WebElement;
3029

31-
public class ConsoleFeatureIT extends AbstractXTermTest {
30+
public class ConsoleFeatureIT extends AbstractViewTest {
3231

3332
@Test
3433
public void testFeature() throws InterruptedException {
35-
TestBenchElement term = $("fc-xterm").first();
34+
XTermElement term = $(XTermElement.class).first();
3635

37-
WebElement input =
38-
(WebElement) getCommandExecutor().executeScript("return document.activeElement");
36+
int y = term.cursorPosition().y;
3937

40-
int y = cursorPosition(term).y;
38+
term.sendKeys("HELLO");
39+
assertThat(term.currentLine(), is("HELLO"));
40+
assertThat(term.cursorPosition(), is(at(5, y)));
4141

42-
input.sendKeys("HELLO");
43-
assertThat(currentLine(term), is("HELLO"));
44-
assertThat(cursorPosition(term), is(at(5, y)));
42+
term.sendKeys(Keys.ARROW_LEFT);
43+
assertThat(term.cursorPosition(), is(at(4, y)));
4544

46-
input.sendKeys(Keys.ARROW_LEFT);
47-
assertThat(cursorPosition(term), is(at(4, y)));
45+
term.sendKeys(Keys.ARROW_RIGHT);
46+
assertThat(term.cursorPosition(), is(at(5, y)));
4847

49-
input.sendKeys(Keys.ARROW_RIGHT);
50-
assertThat(cursorPosition(term), is(at(5, y)));
48+
term.sendKeys(Keys.HOME);
49+
assertThat(term.cursorPosition(), is(at(0, y)));
5150

52-
input.sendKeys(Keys.HOME);
53-
assertThat(cursorPosition(term), is(at(0, y)));
51+
term.sendKeys(Keys.END);
52+
assertThat(term.cursorPosition(), is(at(5, y)));
5453

55-
input.sendKeys(Keys.END);
56-
assertThat(cursorPosition(term), is(at(5, y)));
54+
term.sendKeys(Keys.BACK_SPACE);
55+
assertThat(term.currentLine(), is("HELL"));
56+
assertThat(term.cursorPosition(), is(at(4, y)));
5757

58-
input.sendKeys(Keys.BACK_SPACE);
59-
assertThat(currentLine(term), is("HELL"));
60-
assertThat(cursorPosition(term), is(at(4, y)));
58+
term.sendKeys(Keys.HOME, Keys.DELETE);
59+
assertThat(term.currentLine(), is("ELL"));
60+
assertThat(term.cursorPosition(), is(at(0, y)));
6161

62-
input.sendKeys(Keys.HOME, Keys.DELETE);
63-
assertThat(currentLine(term), is("ELL"));
64-
assertThat(cursorPosition(term), is(at(0, y)));
62+
term.sendKeys("A");
63+
assertThat(term.currentLine(), is("AELL"));
6564

66-
input.sendKeys("A");
67-
assertThat(currentLine(term), is("AELL"));
65+
term.sendKeys(Keys.INSERT, "B");
66+
assertThat(term.currentLine(), is("ABLL"));
6867

69-
input.sendKeys(Keys.INSERT, "B");
70-
assertThat(currentLine(term), is("ABLL"));
71-
72-
input.sendKeys(Keys.INSERT, "C");
73-
assertThat(currentLine(term), is("ABCLL"));
68+
term.sendKeys(Keys.INSERT, "C");
69+
assertThat(term.currentLine(), is("ABCLL"));
7470

7571
// long line
7672

77-
int cols = getColumnWidth(term);
73+
int cols = term.getColumnWidth();
7874
String text = StringUtils.repeat("0123456789", cols / 10 + 1).substring(0, cols);
7975

80-
input.sendKeys("\n");
81-
assertThat(currentLine(term), is(""));
82-
assertThat(cursorPosition(term), is(at(0, ++y)));
76+
term.sendKeys("\n");
77+
assertThat(term.currentLine(), is(""));
78+
assertThat(term.cursorPosition(), is(at(0, ++y)));
8379

84-
input.sendKeys(text);
85-
input.sendKeys(Keys.HOME);
86-
assertThat(cursorPosition(term), is(at(0, y)));
87-
assertThat(currentLine(term), is(text));
80+
term.sendKeys(text);
81+
term.sendKeys(Keys.HOME);
82+
assertThat(term.cursorPosition(), is(at(0, y)));
83+
assertThat(term.currentLine(), is(text));
8884

89-
input.sendKeys("A");
90-
assertThat(currentLine(term), is("A" + text.substring(0, cols - 1)));
91-
assertThat(lineAtOffset(term, +1), is(text.substring(cols - 1)));
85+
term.sendKeys("A");
86+
assertThat(term.currentLine(), is("A" + text.substring(0, cols - 1)));
87+
assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1)));
9288

93-
input.sendKeys("B");
94-
assertThat(currentLine(term), is("AB" + text.substring(0, cols - 2)));
95-
assertThat(lineAtOffset(term, +1), is(text.substring(cols - 2)));
89+
term.sendKeys("B");
90+
assertThat(term.currentLine(), is("AB" + text.substring(0, cols - 2)));
91+
assertThat(term.lineAtOffset(+1), is(text.substring(cols - 2)));
9692

97-
input.sendKeys(Keys.END);
98-
assertThat(cursorPosition(term), is(at(2, y + 1)));
93+
term.sendKeys(Keys.END);
94+
assertThat(term.cursorPosition(), is(at(2, y + 1)));
9995

100-
input.sendKeys(Keys.HOME);
101-
assertThat(cursorPosition(term), is(at(0, y)));
96+
term.sendKeys(Keys.HOME);
97+
assertThat(term.cursorPosition(), is(at(0, y)));
10298

103-
input.sendKeys(Keys.DELETE);
104-
assertThat(currentLine(term), is("B" + text.substring(0, cols - 1)));
105-
assertThat(lineAtOffset(term, +1), is(text.substring(cols - 1)));
99+
term.sendKeys(Keys.DELETE);
100+
assertThat(term.currentLine(), is("B" + text.substring(0, cols - 1)));
101+
assertThat(term.lineAtOffset(+1), is(text.substring(cols - 1)));
106102

107-
input.sendKeys(Keys.DELETE);
108-
assertThat(currentLine(term), is(text));
109-
assertThat(lineAtOffset(term, +1), isEmptyString());
103+
term.sendKeys(Keys.DELETE);
104+
assertThat(term.currentLine(), is(text));
105+
assertThat(term.lineAtOffset(+1), isEmptyString());
110106
}
111107
}

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/FitFeatureIT.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@
2121

2222
import static org.junit.Assert.assertEquals;
2323
import static org.junit.Assert.assertTrue;
24-
import com.vaadin.testbench.TestBenchElement;
2524
import org.junit.Test;
2625
import org.openqa.selenium.Dimension;
2726

28-
public class FitFeatureIT extends AbstractXTermTest {
27+
public class FitFeatureIT extends AbstractViewTest {
2928

3029
@Test
3130
public void testFeature() {
32-
TestBenchElement term = $("fc-xterm").first();
31+
XTermElement term = $(XTermElement.class).first();
3332

34-
int colsBefore = getColumnWidth(term);
33+
int colsBefore = term.getColumnWidth();
3534
Dimension dimension = getDriver().manage().window().getSize();
3635

3736
getDriver().manage().window().setSize(new Dimension(dimension.width / 2, dimension.height));
38-
int colsAfter = getColumnWidth(term);
37+
int colsAfter = term.getColumnWidth();
3938

4039
assertTrue(colsAfter * 2 <= colsBefore);
4140

4241
getDriver().manage().window().setSize(dimension);
43-
int colsRestored = getColumnWidth(term);
42+
int colsRestored = term.getColumnWidth();
4443
assertEquals(colsBefore, colsRestored);
4544
}
4645
}

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/Position.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
@EqualsAndHashCode
2929
class Position {
3030
int x, y;
31+
32+
static Position at(int x, int y) {
33+
return new Position(x, y);
34+
}
35+
3136
}

0 commit comments

Comments
 (0)