tests/app-ui-navigation.R

library(shiny)
library(iSTATS)

app_file <- function(name) {
  path <- system.file("app", name, package = "iSTATS")
  stopifnot(nzchar(path))
  path
}

main_ui <- paste(readLines(app_file("ui.R"), warn = FALSE), collapse = "\n")
alignment_ui <- paste(readLines(app_file("alignment_ui.R"), warn = FALSE),
                      collapse = "\n")
alignment_server <- paste(readLines(app_file("Pretreatment_server.R"), warn = FALSE),
                          collapse = "\n")
pretreatment_ui <- paste(readLines(app_file("Pretreatment_ui.R"), warn = FALSE),
                         collapse = "\n")

alignment_inputs <- c("icoshift_mode", "icoshift_auto_align",
                      "icoshift_detect", "icoshift_align")

stopifnot(
  grepl('tabPanel("Alignment"', main_ui, fixed = TRUE),
  regexpr('tabPanel("Alignment"', main_ui, fixed = TRUE) <
    regexpr('navbarMenu("Select"', main_ui, fixed = TRUE),
  grepl("source('alignment_ui.R'", main_ui, fixed = TRUE),
  # Both panels are server-rendered images sharing one view on the server;
  # no Plotly output or browser-side synchronization remains.
  !grepl("plotly", alignment_ui, fixed = TRUE),
  !grepl("plotly", alignment_server, fixed = TRUE),
  !grepl("alignment_view_change", alignment_server, fixed = TRUE),
  grepl("input$alignment_unaligned_brush", alignment_server, fixed = TRUE),
  grepl("input$alignment_aligned_brush", alignment_server, fixed = TRUE),
  grepl("bindCache(renderPlot(", alignment_server, fixed = TRUE),
  grepl("input$alignment_region_drag", alignment_server, fixed = TRUE),
  grepl("input$alignment_region_remove", alignment_server, fixed = TRUE),
  all(vapply(alignment_inputs, grepl, logical(1), x = alignment_ui,
             fixed = TRUE)),
  !any(vapply(alignment_inputs, grepl, logical(1), x = pretreatment_ui,
              fixed = TRUE))
)

rendered_ui <- local({
  previous_directory <- setwd(dirname(app_file("ui.R")))
  on.exit(setwd(previous_directory))
  ui <- source("ui.R", local = new.env(parent = globalenv()))[[1L]]
  as.character(ui)
})

stopifnot(
  grepl('data-value="Alignment"', rendered_ui, fixed = TRUE),
  grepl('id="icoshift_align"', rendered_ui, fixed = TRUE),
  grepl('id="icoshift_auto_align"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_unaligned_plot"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_aligned_plot"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_reset_view"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_zoom_out"', rendered_ui, fixed = TRUE),
  grepl('name="alignment_mouse_mode"', rendered_ui, fixed = TRUE),
  grepl('value="regions"', rendered_ui, fixed = TRUE),
  grepl('src="alignment_regions.js"', rendered_ui, fixed = TRUE),
  file.exists(app_file("www/alignment_regions.js")),
  grepl('id="alignment_pan_left"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_pan_right"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_unaligned_hover_label"', rendered_ui, fixed = TRUE),
  grepl('id="alignment_aligned_hover_label"', rendered_ui, fixed = TRUE),
  grepl('data-brush-id="alignment_unaligned_brush"', rendered_ui, fixed = TRUE),
  grepl('data-brush-id="alignment_aligned_brush"', rendered_ui, fixed = TRUE),
  grepl('data-hover-id="alignment_unaligned_hover"', rendered_ui, fixed = TRUE),
  grepl('data-click-id="alignment_aligned_click"', rendered_ui, fixed = TRUE),
  grepl('data-dblclick-id="alignment_aligned_dblclick"', rendered_ui, fixed = TRUE),
  grepl('data-brush-id="plot_multi_brush"', rendered_ui, fixed = TRUE),
  grepl('data-hover-id="plot_multi_hover"', rendered_ui, fixed = TRUE),
  !grepl("plotly", rendered_ui, fixed = TRUE),
  grepl('name="alignment_layout"', rendered_ui, fixed = TRUE),
  grepl('value="balanced"', rendered_ui, fixed = TRUE),
  grepl('value="unaligned"', rendered_ui, fixed = TRUE),
  grepl('value="aligned"', rendered_ui, fixed = TRUE)
)

# Frente 16: a explicacao e sob demanda, mas nunca so no hover. Cada botao de
# icone carrega title/aria-label alem do bsTooltip, e os textos longos ficam no
# popover do botao "?", que abre por clique.
alignment_icon_buttons <- c("alignment_pan_left", "alignment_zoom_out",
                            "alignment_pan_right", "alignment_reset_view")
stopifnot(
  grepl('id="alignment_help"', rendered_ui, fixed = TRUE),
  grepl("'popover'", rendered_ui, fixed = TRUE),
  grepl("'trigger': 'click'", rendered_ui, fixed = TRUE),
  all(vapply(alignment_icon_buttons, function(id) {
    button <- regmatches(rendered_ui,
                         regexpr(sprintf('(?s)<button id="%s".*?</button>', id),
                                 rendered_ui, perl = TRUE))
    length(button) == 1L &&
      grepl("title=", button, fixed = TRUE) &&
      grepl("aria-label=", button, fixed = TRUE) &&
      grepl("<img src=", button, fixed = TRUE) &&
      grepl(sprintf("shinyBS.addTooltip('%s', 'tooltip'", id), rendered_ui,
            fixed = TRUE)
  }, logical(1))),
  # Os icones sao os que as outras abas ja usam; nenhum asset novo foi criado.
  all(file.exists(app_file(file.path(
    "www", c("s_left.png", "cont.png", "s_right.png", "rsh.png"))))),
  # As tabelas atras de abas precisam continuar renderizadas.
  grepl('outputOptions(output, "icoshift_detection_table", suspendWhenHidden = FALSE)',
        alignment_server, fixed = TRUE),
  grepl('outputOptions(output, "icoshift_applied_regions_table", suspendWhenHidden = FALSE)',
        alignment_server, fixed = TRUE)
)

cat("PASS Alignment precedes Select; Alignment and Plot Spectra use server-rendered plots\n")
cat("PASS alignment toolbar: icon buttons keep title/aria-label plus tooltip, help opens a click popover\n")

Try the iSTATS package in your browser

Any scripts or data that you put into this service are public.

iSTATS documentation built on Nov. 6, 2026, 1:07 a.m.