Skip to content

Commit 38f10e8

Browse files
javier-godoypaodb
authored andcommitted
test: add integration test for ClientTerminalAddon
1 parent 7eb7aa8 commit 38f10e8

5 files changed

Lines changed: 203 additions & 0 deletions

File tree

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
<groupId>com.vaadin</groupId>
102102
<artifactId>vaadin-testbench</artifactId>
103103
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.flowingcode.vaadin.test</groupId>
107+
<artifactId>testbench-rpc</artifactId>
108+
<version>1.4.0</version>
109+
<scope>test</scope>
104110
</dependency>
105111
<dependency>
106112
<groupId>org.hamcrest</groupId>

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*-
2+
* #%L
3+
* XTerm Console Addon
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.xterm.integration;
21+
22+
import com.flowingcode.vaadin.addons.xterm.ITerminalOptions.CursorStyle;
23+
import com.flowingcode.vaadin.addons.xterm.XTerm;
24+
import com.vaadin.flow.component.ClientCallable;
25+
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
26+
import com.vaadin.flow.router.Route;
27+
28+
@SuppressWarnings("serial")
29+
@Route(value = IntegrationView.ROUTE)
30+
public class IntegrationView extends VerticalLayout implements IntegrationViewCallables {
31+
32+
public static final String ROUTE = "xterm/it";
33+
34+
private XTerm xterm;
35+
36+
private SampleClientTerminalAddon sampleClientTerminalAddon;
37+
38+
public IntegrationView() {
39+
setSizeFull();
40+
setPadding(false);
41+
getElement().getStyle().set("background", "black");
42+
43+
xterm = new XTerm();
44+
xterm.setPrompt("[user@xterm ~]$ ");
45+
46+
xterm.writeln("xterm add-on by Flowing Code S.A.\n\n");
47+
xterm.writePrompt();
48+
49+
xterm.setCursorBlink(true);
50+
xterm.setCursorStyle(CursorStyle.UNDERLINE);
51+
52+
xterm.setSizeFull();
53+
sampleClientTerminalAddon = new SampleClientTerminalAddon(xterm);
54+
55+
xterm.addLineListener(ev -> xterm.writePrompt());
56+
57+
xterm.focus();
58+
xterm.fit();
59+
add(xterm);
60+
}
61+
62+
@Override
63+
@ClientCallable
64+
public void setSampleClientTerminalAddonValue(String value) {
65+
sampleClientTerminalAddon.setValue(value);
66+
}
67+
68+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*-
2+
* #%L
3+
* XTerm Console Addon
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.xterm.integration;
21+
22+
public interface IntegrationViewCallables {
23+
24+
void setSampleClientTerminalAddonValue(String value);
25+
26+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*-
2+
* #%L
3+
* XTerm Console Addon
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.xterm.integration;
21+
22+
import com.flowingcode.vaadin.addons.xterm.ClientTerminalAddon;
23+
import com.flowingcode.vaadin.addons.xterm.XTermBase;
24+
25+
@SuppressWarnings("serial")
26+
public class SampleClientTerminalAddon extends ClientTerminalAddon {
27+
28+
public final static String NAME = "sample-terminal-addon";
29+
30+
public SampleClientTerminalAddon(XTermBase xterm) {
31+
super(xterm);
32+
33+
// see https://github.com/FlowingCode/XTermConsoleAddon/issues/98
34+
xterm.getElement().executeJs("""
35+
window.Vaadin.Flow.fcXtermConnector = window.Vaadin.Flow.fcXtermConnector || {};
36+
window.Vaadin.Flow.fcXtermConnector.load_sample = (name, node) => {
37+
const addon = {
38+
activate: () => {},
39+
dispose: () => {}
40+
};
41+
node.terminal.loadAddon(addon);
42+
node.addons[name]=addon;
43+
};
44+
Vaadin.Flow.fcXtermConnector.load_sample($0, this);""", NAME);
45+
}
46+
47+
public void setValue(String value) {
48+
executeJs("this.value=$0;", value);
49+
}
50+
51+
@Override
52+
public String getName() {
53+
return NAME;
54+
}
55+
56+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*-
2+
* #%L
3+
* XTerm Console Addon
4+
* %%
5+
* Copyright (C) 2020 - 2026 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.xterm.integration;
21+
22+
import static org.junit.Assert.assertEquals;
23+
import com.flowingcode.vaadin.testbench.rpc.HasRpcSupport;
24+
import org.junit.Test;
25+
26+
public class SampleClientTerminalAddonIT extends AbstractViewTest implements HasRpcSupport {
27+
28+
private static final String BAR = "BAR";
29+
IntegrationViewCallables $server = createCallableProxy(IntegrationViewCallables.class);
30+
31+
public SampleClientTerminalAddonIT() {
32+
super(IntegrationView.ROUTE);
33+
}
34+
35+
@Test
36+
public void testSelectionFeature1() throws InterruptedException {
37+
XTermElement term = $(XTermElement.class).first();
38+
$server.setSampleClientTerminalAddonValue(BAR);
39+
assertEquals(BAR, getSampleClientTerminalValue(term));
40+
}
41+
42+
private static String getSampleClientTerminalValue(XTermElement term) {
43+
return (String) term.executeScript("return this.addons[arguments[0]].value;",
44+
SampleClientTerminalAddon.NAME);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)