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

Add initial tests for the support_panel function #5

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
939c514
Add basic check on valid email address for support panel
cjrace Nov 8, 2023
a620798
Add a couple of extra test case emails
cjrace Nov 8, 2023
466284c
Add my information as an author
cjrace Nov 8, 2023
dec68cd
add instructions on setup and running of tests to readme
cjrace Jan 30, 2024
b16fa16
fix typo
cjrace Jan 30, 2024
a4b7390
reduce line length plus styler::style_pkg()
cjrace Jan 30, 2024
f573459
Switching in cookie module code developed within the template
rmbielby Feb 12, 2024
2766a15
Documentation update with cookie module
rmbielby Feb 12, 2024
e2b5686
Clarifying some namespace issues
rmbielby Feb 12, 2024
ab2f6c6
Revert "Clarifying some namespace issues"
rmbielby Feb 12, 2024
21d5b6d
Updated cookie documentation
rmbielby Feb 12, 2024
70172f4
Adding cookie header script
rmbielby Feb 12, 2024
f70c63f
Adding cookie header script to docs
rmbielby Feb 12, 2024
1650f74
Renaming cookie script function
rmbielby Feb 12, 2024
4c30abe
Added cookie js script
rmbielby Feb 12, 2024
ea4b53d
Updated cookie script to point to remote consent script
rmbielby Feb 12, 2024
1cdc9f7
Making the references to dfe_cookie_script consistent
rmbielby Feb 12, 2024
2050c47
Rolling back to the local cookie-consent.js
rmbielby Feb 12, 2024
2b7c422
Removing some print() statements
rmbielby Feb 12, 2024
02c068d
Commenting in cookies.R
rmbielby Feb 12, 2024
b402b7b
Reverting to gov style button inputs.
rmbielby Feb 13, 2024
ed99f80
Updated styling of the cookies link in the banner
rmbielby Feb 13, 2024
fb05a29
Adjusting how the cookies link button is rendered
rmbielby Feb 13, 2024
d5f529d
Switched cookie link to actionLink instead of a button
rmbielby Feb 13, 2024
93c7741
Updating support and feedback id
rmbielby Feb 13, 2024
3ee22bb
Adjusing namespacing for updateTabsetPanel
rmbielby Feb 13, 2024
5dc3f9a
Updated cookie server function to pull in parent session
rmbielby Feb 13, 2024
a0fdc5c
Updated cookie module server to return cookie status text
rmbielby Feb 13, 2024
47bab1b
Updated references for input in cookie module
rmbielby Feb 13, 2024
d123654
Adjusting cookie status logic
rmbielby Feb 13, 2024
02eca50
Adding in the brackets for the reactives!
rmbielby Feb 13, 2024
2085897
Expanded description of how to use the cookie banner
rmbielby Feb 13, 2024
1c65605
Testing out defining parent package for functions to stop lintr compl…
rmbielby Feb 13, 2024
34f610c
Testing out defining parent package for functions to stop lintr compl…
rmbielby Feb 13, 2024
458a96f
Adding in the google analytics key!
rmbielby Feb 13, 2024
b3bbce4
A few styling changes to the cookie code based on lintr
rmbielby Feb 13, 2024
b3bcde1
Code styling clean up
rmbielby Feb 13, 2024
e2583f6
Updated readme with instructions on using the cookie functionality
rmbielby Feb 13, 2024
af0301a
Updating title hierarchy in readme
rmbielby Feb 13, 2024
0be14f9
Adding links to template examples
rmbielby Feb 13, 2024
d9c2016
Adding link to template global.R example
rmbielby Feb 13, 2024
4dbbace
Added shinytest2 tests and changed the language on the remove consent…
rmbielby Feb 13, 2024
35aa82e
Updated links to example dashboard code to the dfeshiny test dashboard
rmbielby Feb 13, 2024
12c1d5a
Updated links to example ui code to the dfeshiny test ui.R
rmbielby Feb 13, 2024
c9d790b
Little bit of code styling
rmbielby Feb 13, 2024
255c058
Adding shinytest2 and diffviewer to suggests
rmbielby Feb 13, 2024
8efeaea
Missed some commas in the description file
rmbielby Feb 13, 2024
255407e
Added NEWS.md with overview of updates intended for v0.2.0.
rmbielby Feb 15, 2024
50edb7f
Merge branch 'main' into cookie-module
rmbielby Feb 15, 2024
7de0416
Expanded NEWS.md to include testing improvements
rmbielby Feb 15, 2024
a3dc1c3
Merge branch 'cookie-module' of https://github.com/dfe-analytical-ser…
rmbielby Feb 15, 2024
75ac192
change support_panel() to need a dfe email address
cjrace Feb 15, 2024
4325565
add r cmd check action
cjrace Feb 15, 2024
0ff91fa
Merge branch 'main' into add-initial-tests
cjrace Feb 15, 2024
51ec204
add code coverage tests
cjrace Feb 15, 2024
4b615f3
Merge branch 'add-initial-tests' of https://github.com/dfe-analytical…
cjrace Feb 15, 2024
bb29969
style code
cjrace Feb 15, 2024
159aded
explicitly state packages for functinos to make devtools::check() pass
cjrace Feb 15, 2024
c58e7ba
update license, add .md and to buildignore
cjrace Feb 15, 2024
b3ae9d9
add validation to repo URL
cjrace Feb 15, 2024
2b2aa35
add return values and examples to existing functions
cjrace Feb 15, 2024
3bcf2c1
merge in cookie branch and resolve conflicts
cjrace Feb 15, 2024
859beed
update documentation
cjrace Feb 15, 2024
bec0f1a
remove duplication in repo name
cjrace Feb 15, 2024
9e161b3
quick commit to try to force the file updates in github to update
cjrace Feb 15, 2024
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
^dfeshiny\.Rproj$
^\.Rproj\.user$
^\.github$
^codecov\.yml$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Package: dfeshiny
Title: DfE R-Shiny Standards
Version: 0.1.1
Authors@R:
Authors@R: c(
person("Rich", "Bielby", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9070-9969"))
comment = c(ORCID = "0000-0001-9070-9969")),
person("Cameron", "Race", , "[email protected]", role = c("aut"))
)
Description: R package containing preferred methods for creating official DfE R-Shiny dashboards.
License: `use_gpl3_license()`
Encoding: UTF-8
Expand All @@ -13,3 +15,6 @@ Imports:
styler
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
127 changes: 76 additions & 51 deletions R/standard_panels.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @description
#' Create the standard DfE R-Shiny support and feedback dashboard panel.
#'
#' @param team_email Your team e-mail address as a string
#' @param team_email Your team e-mail address as a string, this must be a education.gov.uk email
Fixed Show fixed Hide fixed
#' @param repo_name The repository name as listed on GitHub
#' @param ees_publication Whether the parent publication is hosted on Explore Education Statistics
#' @param publication_name The parent publication name
Expand All @@ -26,80 +26,105 @@
publication_stub = "",
alt_href = NULL,
form_url = NULL) {
tabPanel(

# Check that the team_email is a valid email
is_valid_dfe_email <- function(email) {
grepl(
"\\<[A-Z0-9._%+-][email protected]\\>",
as.character(email),
ignore.case = TRUE
)
}

if (is_valid_dfe_email(team_email) == FALSE) {
stop(
"You have entered an invalid email in the team_email argument.
Fixed Show fixed Hide fixed
Please enter a @education.gov.uk email.")
}


shiny::tabPanel(
"Support and feedback",
gov_main_layout(
gov_row(
column(
shinyGovstyle::gov_main_layout(
shinyGovstyle::gov_row(
shiny::column(
width = 12,
h1("Support and feedback"),
h2("Give us feedback"),
shiny::tags$h1("Support and feedback"),
shiny::tags$h2("Give us feedback"),
if (!is.null(form_url)) {
p(
"This dashboard is a new service that we are developing. If you have any feedback or suggestions for improvements, please submit them using our ",
a(href = form_url, "feedback form", .noWS = c("after"))
shiny::tags$p(
"This dashboard is a new service that we are developing.
If you have any feedback or suggestions for improvements,
please submit them using our ",
shiny::tags$a(href = form_url, "feedback form", .noWS = c("after"))
Fixed Show fixed Hide fixed
)
} else {
p("This dashboard is a new service that we are developing.")
shiny::tags$p("This dashboard is a new service that we are developing.")
Fixed Show fixed Hide fixed
},
p(
shiny::tags$p(
paste0(
ifelse(
!is.null(form_url),
"Alternatively, i",
"I"
),
"f you spot any errors or bugs while using this dashboard, please screenshot and email them to "
"f you spot any errors or bugs while using this dashboard,
please screenshot and email them to "
),
tags$a(href = paste0("mailto:", team_email), team_email, .noWS = c("after")), "."
shiny::tags$a(
href = paste0("mailto:", team_email),
Fixed Show fixed Hide fixed
team_email,
.noWS = c("after")),
"."
),
h2("Find more information on the data"),
if (ees_publication) {
p(
"The parent statistical release of this dashboard, along with methodological information, is available at the following link: ",
tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub),
ifelse(!is.null(publication_name), publication_name, "Explore Education Statistics"),
.noWS = c("after")
),
". The statistical release provides additional ",
tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub, "/data guidance"),
"data guidance",
.noWS = c("after")
),
" and ",
tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub,'#explore-data-and-files'),
"tools to access and interogate the underling data",
.noWS = c("after")
),
shiny::tags$h2("Find more information on the data"),
if (ees_publication) {
shiny::tags$p(
"The parent statistical release of this dashboard,
along with methodological information, is available at the following link: ",
Fixed Show fixed Hide fixed
shiny::tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub),
Fixed Show fixed Hide fixed
ifelse(!is.null(publication_name), publication_name, "Explore Education Statistics"),
Fixed Show fixed Hide fixed
.noWS = c("after")
),
". The statistical release provides additional ",
shiny::tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub, "/data guidance"),
Fixed Show fixed Hide fixed
"data guidance",
.noWS = c("after")
),
" and ",
shiny::tags$a(
href = paste0("https://explore-education-statistics.service.gov.uk/find-statistics/", publication_stub, "#explore-data-and-files"),
Fixed Show fixed Hide fixed
"tools to access and interogate the underling data",
.noWS = c("after")
),
" contained in this dashboard."
)
} else {
p(
"The parent statistical release of this dashboard, along with methodological information, is available at the following link: ",
a(
)
} else {
shiny::tags$p(
"The parent statistical release of this dashboard, along with methodological information, is available at the following link: ",
Fixed Show fixed Hide fixed
shiny::tags$a(
href = alt_href,
publication_name,
.noWS = c("after")
)
)
},
h2("Contact us"),
p(
)
},
shiny::tags$h2("Contact us"),
shiny::tags$p(
"If you have questions about the dashboard or data within it, please contact us at ",
a(href = paste0("mailto:", team_email), team_email, .noWS = c("after"))
shiny::tags$a(href = paste0("mailto:", team_email), team_email, .noWS = c("after"))
Fixed Show fixed Hide fixed
),
h2("See the source code"),
p(
shiny::tags$h2("See the source code"),
shiny::tags$p(
"The source code for this dashboard is available in our ",
a(href = paste0("https://github.com/dfe-analytical-services/", repo_name), "GitHub repository", .noWS = c("after")),
shiny::tags$a(href = paste0("https://github.com/dfe-analytical-services/", repo_name), "GitHub repository", .noWS = c("after")),
Fixed Show fixed Hide fixed
"."
),
h2("Use of cookies"),
textOutput("cookie_status"),
actionButton("remove", "Reset cookie consent"),
shiny::tags$h2("Use of cookies"),
shiny::textOutput("cookie_status"),
shiny::actionButton("remove", "Reset cookie consent"),
)
)
)
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
<!-- badges: start -->
[![R-CMD-check](https://github.com/dfe-analytical-services/dfeshiny/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dfe-analytical-services/dfeshiny/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/dfe-analytical-services/dfeshiny/branch/main/graph/badge.svg)](https://app.codecov.io/gh/dfe-analytical-services/dfeshiny?branch=main)

<!-- badges: end -->

# dfeshiny
R package containing preferred methods for creating official DfE R-Shiny dashboards

# Contributing

Try and make use of the [usethis](https://usethis.r-lib.org/) package wherever possible.
Try and make use of the `usethis` package wherever relevant: [https://usethis.r-lib.org/](https://usethis.r-lib.org/)

When you initially clone the package, the first thing you'll need to do is install `devtools`:

`install.packages("devtools")`

Then to load in the package in its current form:

`devtools::load_all()`

## Run the unit tests

Once the package is loaded in you can run the tests locally in a couple of ways:

`Ctrl-Shft-T`

or via the function that triggers

`devtools::test()`

## Adding a package/dependency

Expand All @@ -17,6 +41,7 @@ This will create a new script within the package R/ folder.

This will create a new script within the package R/ folder.


## Updating the package version

Once changes have been completed, reviewed and are ready for use in the wild, you
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(dfeshiny)

test_check("dfeshiny")
18 changes: 18 additions & 0 deletions tests/testthat/test-support-panel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("email needs to follow standard pattern", {
# Test that a @education.gov.uk passes
expect_no_error(support_panel(team_email = "[email protected]"))
expect_no_error(support_panel(team_email = "[email protected]"))

# Testing that it will fail if it follows the [email protected] pattern
expect_error(support_panel(team_email = "[email protected]"))
expect_error(support_panel(team_email = "[email protected]"))

# Testing that it will fail if there is no final dot and section
expect_error(support_panel(team_email = "thisshoulfail@something"))

# Test Wales will fail
expect_error(support_panel(team_email = "[email protected]"))

# Test that it fails if there is no @ symbol
expect_error(support_panel(team_email = "team.team"))
})
Loading