tests/testthat/test_promex_feature_plot.R

context("test: promex_feature_plot")

test_that("Testing promex feature plot", {

  # Download required test files------------------------------------------------

  MS1FT <- readRDS(system.file("testdata", "MS1FT.RDS", package = "pspecterlib"))

  # Test promex feature plot----------------------------------------------------

  # MS1FT must be an appropriate object
  expect_error(
    promex_feature_plot(data.frame(test = 1)),
    "MS1FT must be a ms1ft object generated by get_ms1ft."
  )

  # Protein must be a character
  expect_error(
    promex_feature_plot(MS1FT, Proteins = c(1,2)),
    "Proteins must be a vector of characters."
  )

  # Interactive must be a true or false
  expect_error(
    promex_feature_plot(MS1FT, Interactive = "FALSE"),
    "Interactive needs to be a single logical: a TRUE or FALSE."
  )

  # Make a promex feature plot--------------------------------------------------

  # Make a static plot subsetted by the protein
  plot1 <- promex_feature_plot(MS1FT, Proteins = "SO_0239", Interactive = NA)
  expect_true(inherits(plot1, "ggplot"))

  # Protein must exist in the MS1FT
  suppressMessages(
    plot2 <- promex_feature_plot(
      MS1FT = MS1FT,
      Proteins = c("test", "testagain"),
      Interactive = TRUE
    )
  )
  expect_true(inherits(plot2, "plotly"))

  # Run a MS1FT with no proteins
  suppressMessages(
    plot3 <- promex_feature_plot(
      MS1FT = MS1FT[,c(1:5)],
      Interactive = FALSE
    )
  )
  expect_true(inherits(plot3, "ggplot"))

})
EMSL-Computing/pspecterlib documentation built on Jan. 28, 2024, 8:13 p.m.