Skip to content

Commit

Permalink
refactor: merge test scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Mar 6, 2024
1 parent a5614b6 commit 175f60d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.omegat.gui.dialogs;
package org.omegat.gui;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.awt.event.KeyEvent;
import java.io.File;
Expand All @@ -12,13 +13,14 @@
import org.apache.commons.io.FileUtils;
import org.junit.Test;

import org.omegat.gui.dialogs.CreateGlossaryEntry;
import org.omegat.gui.glossary.GlossaryTextArea;
import org.omegat.gui.main.BaseMainWindowMenu;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.gui.main.TestCoreGUI;
import org.omegat.util.Preferences;

public class GlossaryEntryDialogTest extends TestCoreGUI {
public class GlossaryEntryTest extends TestCoreGUI {

private File tmpDir;

Expand All @@ -40,28 +42,40 @@ public void testOpenGlossaryEntryDialog() throws Exception {
Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_LENGTH, false);
Preferences.setPreference(Preferences.GLOSSARY_SORT_BY_SRC_LENGTH, false);
assertFalse(Preferences.isPreferenceDefault(Preferences.PROJECT_FILES_SHOW_ON_LOAD, true));
// 2. Open a sample project.
// 2. Operate Glossary preference from menu.
Preferences.setPreference(Preferences.GLOSSARY_STEMMING, true);
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertTrue(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).target()
.getModel().isSelected());
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).click();
// 3. toggle options > glossary menu
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertFalse(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).target()
.getModel().isSelected());
// 4. Open a sample project.
SwingUtilities.invokeAndWait(() -> ProjectUICommands.projectOpen(tmpDir));
// Enforce "Edit" menu enabled.
final JMenuItem menuItem = window.menuItem(BaseMainWindowMenu.EDIT_MENU).target();
SwingUtilities.invokeAndWait(() -> menuItem.setEnabled(true));
// 3. Click menu Edit > Create glossary menu items.
// 5. Click menu Edit > Create glossary menu items.
window.menuItem(BaseMainWindowMenu.EDIT_MENU).click();
window.menuItem(BaseMainWindowMenu.EDIT_CREATE_GLOSSARY_MENUITEM).click();
// 4. Check Create glossary dialog visible
// 6. Check Create glossary dialog visible
window.dialog(CreateGlossaryEntry.DIALOG_NAME).requireVisible();
// 5. Enter glossary keyword and translation in the field
// 7. Enter glossary keyword and translation in the field
window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.SOURCE_TEXT_FIELD)
.enterText("Apertium");
window.dialog(CreateGlossaryEntry.DIALOG_NAME).textBox(CreateGlossaryEntry.TARGET_TEXT_FIELD)
.enterText("Translation Engine");
// 6. Click a OK button
// 8. Click a OK button
window.dialog(CreateGlossaryEntry.DIALOG_NAME).button(CreateGlossaryEntry.OK_BUTTON).click();
// 7. Enforce refresh glossary pane
// 9. Enforce refresh glossary pane
GlossaryTextArea glossaryTextArea =
((GlossaryTextArea) (window.textBox(GlossaryTextArea.TEXTPANE_NAME).target()));
glossaryTextArea.refresh();
// 8. Wait showing a search result during some operation
// 10. Wait showing a search result during some operation
window.textBox(GlossaryTextArea.TEXTPANE_NAME).rightClick();
window.pressKey(KeyEvent.VK_ESCAPE);
// Check the glossary pane shown in the pane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
**************************************************************************/
package org.omegat.gui.main;
package org.omegat.gui;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.nio.file.Files;
Expand All @@ -34,7 +33,8 @@

import org.omegat.core.Core;
import org.omegat.gui.dialogs.NewProjectFileChooser;
import org.omegat.util.Preferences;
import org.omegat.gui.main.BaseMainWindowMenu;
import org.omegat.gui.main.TestCoreGUI;

public class ProjectMenuTest extends TestCoreGUI {

Expand All @@ -46,13 +46,13 @@ protected void onSetUp() throws Exception {
tempDir = Files.createTempDirectory("omegat").toFile();
}

@Test
public void testMainWindowTitle() {
window.requireTitle("OmegaT 6.1.0");
}

/**
* Test project menus.
*/
@Test
public void testNewProject() {
window.requireTitle("OmegaT 6.1.0");
// 2. click menu Project > new project
window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click();
window.menuItem(BaseMainWindowMenu.PROJECT_NEW_MENUITEM).click();
window.fileChooser(NewProjectFileChooser.DIALOG_NAME).requireEnabled();
Expand All @@ -65,28 +65,11 @@ public void testNewProject() {
window.dialog(ProjectPropertiesDialog.DIALOG_NAME).button(ProjectPropertiesDialog.OK_BUTTON_NAME).click();
assertTrue(Core.getProject().isProjectLoaded());
*/
}

@Test
public void testExit() {
// 3. select project > Exit menu.
window.menuItem(BaseMainWindowMenu.PROJECT_MENU).click();
window.menuItem(BaseMainWindowMenu.PROJECT_EXIT_MENUITEM).click();
window.requireNotVisible();
window.requireDisabled();
}

@Test
public void testGlossaryOption() {
Preferences.setPreference(Preferences.GLOSSARY_STEMMING, true);
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertTrue(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).target()
.getModel().isSelected());
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).click();
//
window.menuItem(BaseMainWindowMenu.OPTIONS_MENU).click();
window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_SUBMENU).click();
assertFalse(window.menuItem(BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM).target()
.getModel().isSelected());
}
}

0 comments on commit 175f60d

Please sign in to comment.