diff --git a/R/moduleNavbarWidget.R b/R/moduleNavbarWidget.R index a83e0e32..fe08e42b 100644 --- a/R/moduleNavbarWidget.R +++ b/R/moduleNavbarWidget.R @@ -140,7 +140,9 @@ navbarWidgetServer2 <- function( ) output$name <- shiny::renderText(rv$fullName) - output$affiliation <- shiny::renderText(paste(orgName, rv$role, sep = ", ")) + output$affiliation <- shiny::renderText( + paste(rv$orgName, rv$role, sep = ", ") + ) # User info in widget userInfo <- howWeDealWithPersonalData(session, callerPkg = caller) @@ -159,6 +161,11 @@ navbarWidgetServer2 <- function( # Select organization in widget (for container apps only) shiny::observeEvent(input$selectOrganization, { choices <- paste0(user$orgName, " (", user$org, ") - ", user$role) + lastchoice <- if (is.null(input$unit)) { + NA + } else { + choices[choices == input$unit] + } shinyalert::shinyalert( html = TRUE, @@ -177,7 +184,11 @@ navbarWidgetServer2 <- function( session$ns("unit"), "", choices, - selected = choices[1] + selected = if (is.na(lastchoice)) { + choices[1] + } else { + lastchoice + } ) )), type = "", imageUrl = "rap/logo.svg", diff --git a/tests/testthat/test-moduleNavbarWidget.R b/tests/testthat/test-moduleNavbarWidget.R index 01e84349..6010034f 100644 --- a/tests/testthat/test-moduleNavbarWidget.R +++ b/tests/testthat/test-moduleNavbarWidget.R @@ -61,16 +61,29 @@ with_envvar( orgName = registryName, caller = "rapbase" ), { - # expect_equal(output$name, "Tore Tester Container") + session$setInputs(unit = NULL) expect_equal(class(output$affiliation), "character") - # session$setInputs(userInfo = 1) - # session$setInputs(selectOrganization = 1, unit = 1) expect_equal(rv$name, "ttesterc") expect_equal(rv$fullName, "Tore Tester Container") expect_equal(rv$group, 80) expect_equal(rv$unit, 1) expect_equal(rv$org, 1) expect_equal(rv$role, "LU") + + session$setInputs(selectOrganization = 3, + unit = paste0("Ukjent", " (", "2", ") - ", "SC")) + expect_equal(rv$unit, 2) + expect_equal(rv$org, 2) + expect_equal(rv$role, "SC") + session$setInputs(unit = NULL) + expect_equal(rv$unit, 2) + expect_equal(rv$org, 2) + expect_equal(rv$role, "SC") + session$setInputs(selectOrganization = 4, + unit = NULL) + expect_equal(rv$unit, 2) + expect_equal(rv$org, 2) + expect_equal(rv$role, "SC") }) }) }