Skip to content

Commit

Permalink
Teach test to expect mailto: links (#2237)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-adam authored Jan 19, 2025
1 parent 1312843 commit f1bc366
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/org/labkey/test/tests/announcements/ModeratorReviewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* User: tgaluhn
* Date: 4/30/2018
*/
@Category({Daily.class})
@BaseWebDriverTest.ClassTimeout(minutes = 5)
public class ModeratorReviewTest extends BaseWebDriverTest
Expand Down Expand Up @@ -163,14 +161,16 @@ private String addResponse(String user, String title, boolean expectAutoApproved
.setBody(response)
.submit();

boolean responseAdded = isTextPresent(response);
// commonmark-java auto-linking turns all email addresses into mailto: links
String formattedResponse = replaceEmailAddressesWithMailToLinks(response);
boolean responseAdded = isTextPresent(formattedResponse);
if (expectAutoApproved && !responseAdded)
{
checker().fatal().error(String.format("Expected response '%s' was not present on the thread page.", response));
checker().fatal().error(String.format("Expected response '%s' was not present on the thread page.", formattedResponse));
}
else if (!expectAutoApproved && responseAdded)
{
checker().fatal().error(String.format("Response '%s' was present on the thread page. It should not be", response));
checker().fatal().error(String.format("Response '%s' was present on the thread page. It should not be", formattedResponse));
}
stopImpersonating();

Expand All @@ -179,6 +179,16 @@ else if (!expectAutoApproved && responseAdded)
return expectAutoApproved ? responseTitle : title; // New title if the response was posted successfully
}

private String replaceEmailAddressesWithMailToLinks(String s)
{
// A very primitive regex, but it's good enough to match our test email addresses
Matcher matcher = Pattern.compile("[0-9A-Za-z+_.-]+@[0-9A-Za-z.-]+").matcher(s);
return matcher.replaceAll(match -> {
String email = match.group();
return "<a href=\"mailto:" + email + "\">" + email + "</a>";
});
}

@Test
public void testAll()
{
Expand Down

0 comments on commit f1bc366

Please sign in to comment.