diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 13e05fede..3833cb0b1 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -751,8 +751,8 @@ private void changeLocale() { } private void setupHandlers() { - ripButton.addActionListener(new RipButtonHandler()); - ripTextfield.addActionListener(new RipButtonHandler()); + ripButton.addActionListener(new RipButtonHandler(this)); + ripTextfield.addActionListener(new RipButtonHandler(this)); ripTextfield.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { @@ -1390,10 +1390,25 @@ private boolean canRip(String urlString) { } } - class RipButtonHandler implements ActionListener { + + public static JTextField getRipTextfield() { + return ripTextfield; + } + + public static DefaultListModel getQueueListModel() { + return queueListModel; + } + static class RipButtonHandler implements ActionListener { + + private MainWindow mainWindow; + + public RipButtonHandler(MainWindow mainWindow) { + this.mainWindow = mainWindow; + } public void actionPerformed(ActionEvent event) { String url = ripTextfield.getText(); - if (!queueListModel.contains(url) && !url.equals("")) { + boolean url_not_empty = !url.equals(""); + if (!queueListModel.contains(url) && url_not_empty) { // Check if we're ripping a range of urls if (url.contains("{")) { // Make sure the user hasn't forgotten the closing } @@ -1403,22 +1418,25 @@ public void actionPerformed(ActionEvent event) { int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]); for (int i = rangeStart; i < rangeEnd + 1; i++) { String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i)); - if (canRip(realURL)) { - queueListModel.add(queueListModel.size(), realURL); + if (mainWindow.canRip(realURL)) { + queueListModel.addElement(realURL); ripTextfield.setText(""); } else { - displayAndLogError("Can't find ripper for " + realURL, Color.RED); + mainWindow.displayAndLogError("Can't find ripper for " + realURL, Color.RED); } } } } else { - queueListModel.add(queueListModel.size(), ripTextfield.getText()); + queueListModel.addElement(url); ripTextfield.setText(""); } - } else { - if (!isRipping) { - ripNextAlbum(); - } + } else if (url_not_empty) { + mainWindow.displayAndLogError("This URL is already in queue: " + url, Color.RED); + mainWindow.statusWithColor("This URL is already in queue: " + url, Color.ORANGE); + ripTextfield.setText(""); + } + else if(!mainWindow.isRipping){ + mainWindow.ripNextAlbum(); } } } diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/ChanRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/ChanRipperTest.java index ed023d474..b8860e3b8 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/ChanRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/ChanRipperTest.java @@ -23,32 +23,18 @@ public class ChanRipperTest extends RippersTest { @Test @Tag("flaky") - public void testChanURLPasses() throws IOException, URISyntaxException { + public void testChanURLPasses() throws IOException, URISyntaxException { List passURLs = new ArrayList<>(); // URLs that should work passURLs.add(new URI("http://desuchan.net/v/res/7034.html").toURL()); passURLs.add(new URI("https://boards.4chan.org/hr/thread/3015701").toURL()); - passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL()); +// passURLs.add(new URI("https://boards.420chan.org/420/res/232066.php").toURL()); - Dead link passURLs.add(new URI("http://7chan.org/gif/res/25873.html").toURL()); passURLs.add(new URI("https://rbt.asia/g/thread/70643087/").toURL()); //must work with TLDs with len of 4 for (URL url : passURLs) { ChanRipper ripper = new ChanRipper(url); // Use CompletableFuture to run setup() asynchronously - CompletableFuture setupFuture = CompletableFuture.runAsync(() -> { - try { - ripper.setup(); - } catch (IOException | URISyntaxException e) { - throw new RuntimeException(e); - } - }); - - try { - // Wait for up to 5 seconds for setup() to complete - setupFuture.get(5, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | - TimeoutException e) { - e.printStackTrace(); // Handle exceptions as needed - } + ripper.setup(); assert (ripper.canRip(url)); Assertions.assertNotNull(ripper.getWorkingDir(), "Ripper for " + url + " did not have a valid working directory."); deleteDir(ripper.getWorkingDir()); diff --git a/src/test/java/com/rarchives/ripme/ui/RipButtonHandlerTest.java b/src/test/java/com/rarchives/ripme/ui/RipButtonHandlerTest.java new file mode 100644 index 000000000..9c8f9640a --- /dev/null +++ b/src/test/java/com/rarchives/ripme/ui/RipButtonHandlerTest.java @@ -0,0 +1,37 @@ +package com.rarchives.ripme.ui; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.io.IOException; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; + +public class RipButtonHandlerTest { + + + @Test + @Tag("flaky") + public void duplicateUrlTestCase() throws IOException { + // Simulating the MainWindow in our test + MainWindow testMainWindow = new MainWindow(); + SwingUtilities.invokeLater(testMainWindow); + + MainWindow.RipButtonHandler rbHandler = new MainWindow.RipButtonHandler(testMainWindow); + // Creating a RipButtonHandler instance - Changing fake text to cause github to rebuild 1. + + // Add some URL to the model (assuming there's a method for adding URLs) + testMainWindow.getRipTextfield().setText("http://example.com"); + rbHandler.actionPerformed(null); + testMainWindow.getRipTextfield().setText("http://example.com"); + rbHandler.actionPerformed(null); + + // Assuming your MainWindow or RipButtonHandler sets some flag or state + // indicating that a duplicate URL was encountered + assertEquals(testMainWindow.getRipTextfield().getText(), ""); + } + +} \ No newline at end of file diff --git a/src/test/java/com/rarchives/ripme/ui/UIContextMenuTests.java b/src/test/java/com/rarchives/ripme/ui/UIContextMenuTests.java index 32dcdd9bf..c09cb7947 100644 --- a/src/test/java/com/rarchives/ripme/ui/UIContextMenuTests.java +++ b/src/test/java/com/rarchives/ripme/ui/UIContextMenuTests.java @@ -57,6 +57,7 @@ void tearDown() { } @Test + @Tag("flaky") void testCut() { // Simulate a cut event simulateCutEvent(); @@ -64,6 +65,7 @@ void testCut() { } @Test + @Tag("flaky") void testCopy() { // Simulate a copy event simulateCopyEvent(); @@ -71,6 +73,7 @@ void testCopy() { } @Test + @Tag("flaky") void testPaste() { // Simulate a paste event simulatePasteEvent(); @@ -78,6 +81,7 @@ void testPaste() { } @Test + @Tag("flaky") void testSelectAll() { // Simulate a select all event simulateSelectAllEvent(); @@ -85,6 +89,7 @@ void testSelectAll() { } @Test + @Tag("flaky") void testUndo() { // Simulate an undo event simulateUndoEvent();