Skip to content

Commit fb60497

Browse files
author
Jakub Sobolewski
committed
feat: 🧪✅ Integrate storage code with the app
- Use new interface of saving inputs in the app. - Update the acceptance test so that each test case uses it's own storage, making them independent of each other.
1 parent d30de11 commit fb60497

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

app/main.R

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ box::use(
1111

1212
box::use(
1313
app / components,
14+
app / registry,
15+
app / storage,
16+
app / transaction,
1417
)
1518

1619
#' @export
@@ -55,29 +58,39 @@ ui <- function(id) {
5558
}
5659

5760
#' @export
58-
server <- function(id) {
61+
server <- function(
62+
id,
63+
.storage = storage$new(
64+
getOption("storage.path", "store.csv"),
65+
getOption("storage.schema", transaction$new())
66+
)) {
5967
moduleServer(id, function(input, output, session) {
60-
total_income <- reactiveVal(0)
61-
total_expenses <- reactiveVal(0)
68+
.registry <- registry$new(.storage)
69+
has_registry_updated <- reactiveVal(0)
6270

6371
observeEvent(input$record_income, {
64-
total_income(total_income() + input$income)
72+
.registry$record(transaction$new(input$income)) # nolint
73+
has_registry_updated(has_registry_updated() + 1)
6574
})
6675

6776
observeEvent(input$record_expense, {
68-
total_expenses(total_expenses() + input$expense)
77+
.registry$record(transaction$new(-input$expense)) # nolint
78+
has_registry_updated(has_registry_updated() + 1)
6979
})
7080

7181
output$total_income <- renderText({
72-
total_income()
82+
has_registry_updated()
83+
.registry$get_total_positive()
7384
})
7485

7586
output$total_expenses <- renderText({
76-
total_expenses()
87+
has_registry_updated()
88+
.registry$get_total_negative()
7789
})
7890

7991
output$net_balance <- renderText({
80-
total_income() - total_expenses()
92+
has_registry_updated()
93+
.registry$get_total()
8194
})
8295
})
8396
}

tests/acceptance/dsl.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
box::use(
2+
glue[glue],
23
R6[R6Class],
34
rhino,
45
selenider,
@@ -13,7 +14,13 @@ AppDriver <- R6Class(
1314
driver = NULL,
1415
initialize = function(app = rhino$app()) {
1516
with_dir("../../", {
16-
self$driver <- shinytest2$AppDriver$new(app)
17+
self$driver <- shinytest2$AppDriver$new(
18+
app,
19+
options = list(
20+
storage.path = glue("session_{floor(as.numeric(Sys.time()))}.csv"),
21+
storage.schema = list(amount = numeric())
22+
)
23+
)
1724
self$session <- selenider$selenider_session(
1825
driver = self$driver,
1926
local = FALSE

0 commit comments

Comments
 (0)