From d10003fa11decab41f6da7b2bb61e4e05037d744 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 27 Nov 2024 14:55:34 +0900 Subject: [PATCH] feat: Add acceptance test of Fuzzy matches pane Signed-off-by: Hiroshi Miura --- .../omegat/gui/main/DockableScrollPane.java | 8 +++ .../omegat/gui/matches/MatchesTextArea.java | 1 + .../data/project/omegat/last_entry.properties | 4 ++ .../data/project/omegat/project_save.tmx | 26 +++++++- .../omegat/gui/align/AlignerWindowTest.java | 2 + .../src/org/omegat/gui/main/TestCoreGUI.java | 20 +++++++ .../gui/matches/MatchesTextAreaTest.java | 60 +++++++++++++++++++ 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 test-acceptance/data/project/omegat/last_entry.properties create mode 100644 test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java diff --git a/src/org/omegat/gui/main/DockableScrollPane.java b/src/org/omegat/gui/main/DockableScrollPane.java index 95186032a6..36b64f2f58 100644 --- a/src/org/omegat/gui/main/DockableScrollPane.java +++ b/src/org/omegat/gui/main/DockableScrollPane.java @@ -63,6 +63,14 @@ public void setName(String name) { dockKey.setName(name); } + @Override + public String getName() { + if (dockKey == null) { + return null; + } + return dockKey.getName(); + } + /** Creates a new instance of DockableScrollBox */ public DockableScrollPane(String key, String name, Component view, boolean detouchable) { super(view); diff --git a/src/org/omegat/gui/matches/MatchesTextArea.java b/src/org/omegat/gui/matches/MatchesTextArea.java index a95e246941..3ef284bef8 100644 --- a/src/org/omegat/gui/matches/MatchesTextArea.java +++ b/src/org/omegat/gui/matches/MatchesTextArea.java @@ -133,6 +133,7 @@ public class MatchesTextArea extends EntryInfoThreadPane> imple /** Creates new form MatchGlossaryPane */ public MatchesTextArea(IMainWindow mw) { super(true); + setName("matches_pane"); String title = OStrings.getString("GUI_MATCHWINDOW_SUBWINDOWTITLE_Fuzzy_Matches"); scrollPane = new DockableScrollPane("MATCHES", title, this, true); diff --git a/test-acceptance/data/project/omegat/last_entry.properties b/test-acceptance/data/project/omegat/last_entry.properties new file mode 100644 index 0000000000..61a922f279 --- /dev/null +++ b/test-acceptance/data/project/omegat/last_entry.properties @@ -0,0 +1,4 @@ +#Wed Nov 27 12:53:42 JST 2024 +LAST_ENTRY_NUMBER=3 +LAST_ENTRY_SRC=Error {0}\: {1} +LAST_ENTRY_FILE=Bundle.properties diff --git a/test-acceptance/data/project/omegat/project_save.tmx b/test-acceptance/data/project/omegat/project_save.tmx index ae4a8b233b..caea9fcbcc 100644 --- a/test-acceptance/data/project/omegat/project_save.tmx +++ b/test-acceptance/data/project/omegat/project_save.tmx @@ -1,9 +1,17 @@ -
+
+ + + Apertium + + + Apertium + + Birds in Oregon @@ -12,6 +20,22 @@ Birds in Oregon + + + Error while reading MT results + + + Erreur lors de la lecture des résultats de TA + + + + + Error {0}: {1} + + + Error {0}: {1} + + diff --git a/test-acceptance/src/org/omegat/gui/align/AlignerWindowTest.java b/test-acceptance/src/org/omegat/gui/align/AlignerWindowTest.java index 98ac33f0c2..21006fc5bc 100644 --- a/test-acceptance/src/org/omegat/gui/align/AlignerWindowTest.java +++ b/test-acceptance/src/org/omegat/gui/align/AlignerWindowTest.java @@ -143,6 +143,8 @@ public void testAligner() throws Exception { // aligner.menuItem("align_menu_file").click(); aligner.menuItem("align_menu_close_item").click(); + // + closeProject(); } } diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java index 4d729a6501..049113e64b 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java @@ -61,6 +61,21 @@ public abstract class TestCoreGUI extends AssertJSwingJUnitTestCase { protected File tmpDir; + protected void closeProject() throws Exception { + CountDownLatch latch = new CountDownLatch(1); + Core.getProject().closeProject(); + CoreEvents.registerProjectChangeListener(event -> { + if (!Core.getProject().isProjectLoaded()) { + latch.countDown(); + } + }); + try { + latch.await(5, TimeUnit.SECONDS); + } catch (InterruptedException ignored) { + } + assertFalse("Project should not be loaded.", Core.getProject().isProjectLoaded()); + } + protected void openSampleProject(String projectPath) throws Exception { // 0. Prepare project folder tmpDir = Files.createTempDirectory("omegat-sample-project-").toFile(); @@ -88,6 +103,11 @@ protected void openSampleProject(String projectPath) throws Exception { assertTrue("Sample project should be loaded.", Core.getProject().isProjectLoaded()); } + @Override + protected void onTearDown() throws Exception { + window.cleanUp(); + } + @Override protected void onSetUp() throws Exception { Path tmp = Files.createTempDirectory("omegat"); diff --git a/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java b/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java new file mode 100644 index 0000000000..252a7db7d9 --- /dev/null +++ b/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java @@ -0,0 +1,60 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2024 Hiroshi Miura + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ + +package org.omegat.gui.matches; + +import java.util.Locale; +import java.util.regex.Pattern; + +import org.junit.Rule; +import org.junit.Test; + +import org.omegat.gui.main.TestCoreGUI; +import org.omegat.util.LocaleRule; +import org.omegat.util.OStrings; + +public class MatchesTextAreaTest extends TestCoreGUI { + + private static final String PROJECT_PATH = "test-acceptance/data/project/"; + + @Rule + public final LocaleRule localeRule = new LocaleRule(new Locale("en")); + + @Test + public void testFuzzyMatches() throws Exception { + // load project + openSampleProject(PROJECT_PATH); + robot().waitForIdle(); + // check a fuzzy match pane + window.scrollPane(OStrings.getString("GUI_MATCHWINDOW_SUBWINDOWTITLE_Fuzzy_Matches")).requireVisible(); + window.textBox("matches_pane").requireVisible(); + window.textBox("matches_pane").requireNotEditable(); + Pattern pattern = Pattern.compile("1. Error while reading MT results\\n" + + "Erreur lors de la lecture des résultats de TA\\n" + + "<\\d+/\\d+/\\d+%\\s*>"); + window.textBox("matches_pane").requireText(pattern); + closeProject(); + } +}