forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatInputTextViewerTests.java
More file actions
102 lines (83 loc) · 2.93 KB
/
Copy pathChatInputTextViewerTests.java
File metadata and controls
102 lines (83 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.chat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import com.microsoft.copilot.eclipse.ui.chat.services.ChatServiceManager;
import com.microsoft.copilot.eclipse.ui.utils.SwtUtils;
@ExtendWith(MockitoExtension.class)
class ChatInputTextViewerTests {
@Mock
private ChatServiceManager mockChatServiceManager;
private Display display;
private Shell shell;
private Composite parent;
private ChatInputTextViewer chatInputTextViewer;
@BeforeEach
void setUp() {
// Set up SWT components
SwtUtils.invokeOnDisplayThread(() -> {
display = Display.getDefault();
shell = new Shell(display);
parent = new Composite(shell, SWT.NONE);
// Create the viewer
chatInputTextViewer = new ChatInputTextViewer(parent, mockChatServiceManager);
});
}
@AfterEach
void tearDown() {
SwtUtils.invokeOnDisplayThread(() -> {
if (shell != null && !shell.isDisposed()) {
shell.dispose();
}
});
}
@Test
void testConentCanBeKeptAfterRefresh() {
SwtUtils.invokeOnDisplayThread(() -> {
chatInputTextViewer.setContent("Test message");
chatInputTextViewer.refresh();
assertEquals("Test message", chatInputTextViewer.getContent());
});
}
@Test
void testUndoFunctionality() {
SwtUtils.invokeOnDisplayThread(() -> {
// Set initial content
chatInputTextViewer.setContent("Initial text");
assertEquals("Initial text", chatInputTextViewer.getContent());
// Modify the content
chatInputTextViewer.setContent("Modified text");
assertEquals("Modified text", chatInputTextViewer.getContent());
// Perform undo
chatInputTextViewer.getUndoManager().undo();
assertEquals("Initial text", chatInputTextViewer.getContent());
});
}
@Test
void testRedoFunctionality() {
SwtUtils.invokeOnDisplayThread(() -> {
// Set initial content
chatInputTextViewer.setContent("Initial text");
assertEquals("Initial text", chatInputTextViewer.getContent());
// Modify the content
chatInputTextViewer.setContent("Modified text");
assertEquals("Modified text", chatInputTextViewer.getContent());
// Perform undo
chatInputTextViewer.getUndoManager().undo();
assertEquals("Initial text", chatInputTextViewer.getContent());
// Perform redo
chatInputTextViewer.getUndoManager().redo();
assertEquals("Modified text", chatInputTextViewer.getContent());
});
}
}