Skip to content

Commit 18e1720

Browse files
committed
Add initial plotly test
1 parent 6070b3b commit 18e1720

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

data/reports/plotly.rmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Plotly Example"
3+
output: html_document
4+
---
5+
6+
```{r testing, echo=FALSE, message=FALSE}
7+
library(plotly, warn.conflicts = FALSE)
8+
9+
fig <- plot_ly(x = ~rnorm(50), type = "box")
10+
fig <- fig %>% add_trace(x = ~rnorm(50, 1))
11+
fig
12+
```

src/org/labkey/test/TestFileUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static String getFileContents(Path path)
109109
{
110110
try
111111
{
112-
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
112+
return Files.readString(path);
113113
}
114114
catch (IOException fail)
115115
{
@@ -306,7 +306,7 @@ public static Set<File> getSampleDataDirs()
306306
if (sampledataDirsFile.exists())
307307
{
308308
String path = getFileContents(sampledataDirsFile);
309-
_sampledataDirs.addAll(Arrays.stream(path.split(";")).map(File::new).collect(Collectors.toList()));
309+
_sampledataDirs.addAll(Arrays.stream(path.split(";")).map(File::new).toList());
310310
}
311311
else
312312
{
@@ -317,7 +317,7 @@ public static Set<File> getSampleDataDirs()
317317
// We know where the modules live; no reason to insist that sampledata.dirs exists.
318318
Files.walkFileTree(modulesDir, Collections.emptySet(), 2, new SimpleFileVisitor<>(){
319319
@Override
320-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException
320+
public @NotNull FileVisitResult preVisitDirectory(@NotNull Path dir, @NotNull BasicFileAttributes attrs)
321321
{
322322
if (dir.equals(modulesDir))
323323
{

src/org/labkey/test/tests/AbstractKnitrReportTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.Assume;
1919
import org.junit.BeforeClass;
20+
import org.junit.Test;
2021
import org.labkey.remoteapi.CommandException;
2122
import org.labkey.test.BaseWebDriverTest;
2223
import org.labkey.test.Locator;
@@ -54,6 +55,8 @@ public abstract class AbstractKnitrReportTest extends BaseWebDriverTest
5455
protected static final Path rmdReport_no_scriptpad = TestFileUtils.getSampleData("reports/knitr_no_scriptpad.rmd").toPath();
5556
private static final Path rhtmlReport = scriptpadReports.resolve("script_rhtml.rhtml");
5657
private static final Path rhtmlReport_no_scriptpad = TestFileUtils.getSampleData("reports/knitr_no_scriptpad.rhtml").toPath();
58+
protected static final Path rmdReport_embedded_script = TestFileUtils.getSampleData("reports/plotly.rmd").toPath();
59+
5760
protected final RReportHelper _rReportHelper = new RReportHelper(this);
5861

5962
private static String readReport(final Path reportFile)
@@ -225,4 +228,18 @@ protected void moduleReportDependencies()
225228
_ext4Helper.waitForMaskToDisappear(3 * BaseWebDriverTest.WAIT_FOR_JAVASCRIPT);
226229
waitForElement(Locator.id("mtcars_table"));
227230
}
231+
232+
/**
233+
* Issue 53211: CSP reports when an R/Plotly graph is displayed in Reports web part, same thing wrapped in a wiki works fine with strict csp
234+
*/
235+
@Test
236+
public void reportEmbeddedScript()
237+
{
238+
Locator[] reportContains = {};
239+
240+
String[] reportNotContains = {};
241+
242+
createAndVerifyKnitrReport(rmdReport_embedded_script, RReportHelper.ReportOption.knitrMarkdown, reportContains,
243+
reportNotContains, true);
244+
}
228245
}

0 commit comments

Comments
 (0)