From f7f2d83b7182a4e0a31d0c197fbfc57db099f4db Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 12 Feb 2020 14:23:50 -0500 Subject: [PATCH 1/2] :rotating_light: add unit tests --- tests/testthat/test-index.R | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/testthat/test-index.R diff --git a/tests/testthat/test-index.R b/tests/testthat/test-index.R new file mode 100644 index 00000000..f52dca4c --- /dev/null +++ b/tests/testthat/test-index.R @@ -0,0 +1,51 @@ +context("customindex") + +test_that("Omitting required template keys produces warnings", { + string <- + " + + + {%meta_tags%} + Testing Again + {%favicon%} + {%css_tags%} + + + {%app_entry%} + + + " + + app <- Dash$new() + + expect_error( + app$index_string(gsub("\\{\\%config\\%\\}|\\{\\%scripts\\%\\}|\\{\\%app_entry\\%\\}", "", string)), + "Did you forget to include app_entry, config, scripts in your index string?" + ) + + expect_error( + app$index_string(gsub("\\{\\%scripts\\%\\}", "", string)), + "Did you forget to include scripts in your index string?" + ) + + expect_error( + app$index_string(gsub("\\{\\%app_entry\\%\\}", "", string)), + "Did you forget to include app_entry in your index string?" + ) + + expect_error( + app$index_string(gsub("\\{\\%config\\%\\}", "", string)), + "Did you forget to include config in your index string?" + ) +}) + +test_that("Customizing title using `name` produces a warning", { + + expect_error( + Dash$new(name="Testing"), + "The supplied application title, 'Testing', should be set using the title() method, or passed via index_string() or interpolate_index(); it has been ignored, and 'dash' will be used instead." + ) +}) From 70693532cef37c296d752660712dcc1fb5aacc5a Mon Sep 17 00:00:00 2001 From: Ryan Patrick Kyle Date: Wed, 12 Feb 2020 19:28:15 -0500 Subject: [PATCH 2/2] fix test failure --- tests/testthat/test-index.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-index.R b/tests/testthat/test-index.R index f52dca4c..4a5ccd47 100644 --- a/tests/testthat/test-index.R +++ b/tests/testthat/test-index.R @@ -44,8 +44,9 @@ test_that("Omitting required template keys produces warnings", { test_that("Customizing title using `name` produces a warning", { - expect_error( + expect_warning( Dash$new(name="Testing"), - "The supplied application title, 'Testing', should be set using the title() method, or passed via index_string() or interpolate_index(); it has been ignored, and 'dash' will be used instead." + "The supplied application title, 'Testing', should be set using the title() method, or passed via index_string() or interpolate_index(); it has been ignored, and 'dash' will be used instead.", + fixed=TRUE ) })