Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teach test to expect mailto: links #2237

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading