tests/testthat/test2_prune_closed.R

context("testing prune_closed")
# In the shiny GUI we have 3 trees:
# complete_tree, pruned_tree and input_tree
# to let states survive opening and closing we have to copy them to comlete_tree
# scenario:
# 1 open a node -> 2 check|select child -> 3 close node -> 4 reopen node -> is child still selected<-checked ?
# same must be true if we operate not on child but on the node which is opened and closed

# @2, but at least before we close the node in @3, we have to sync complete_tree <-- input$tree

load("testdata/tr")
tr1<-prune_closed(tr)
expect_null(  attr(tr1, "stopened") )

# variant of tr with two nodes open
tro=tr   # make a variant of tr with one node open
attr(tro[[1]], "stopened")<-T
attr(tro[[c(1,1)]], "stopened")<-F

# testing if nodes are expanded
tr2<-prune_closed(tro)
expect_equal (names(tr2[[1]]), names(tr[[1]]) )
expect_equal(names(tr2[[c(1,1)]]), "...")

#open one child node and retest
attr(tro[[c(1,1)]], "stopened")<-T
tr3<-prune_closed(tro)
expect_equal (names(tr3[[1]]), names(tr[[1]]) )
expect_equal (names(tr3[[c(1,1)]]), names(tr[[c(1,1)]]) )
expect_equal(names(tr3[[c(1,1,1)]]), "...")

# testing if open node in input_tree is expands node in tree
tr2<-prune_closed(tr, tro)
expect_true(  attr(tr2[[1]], "stopened")  )
expect_true(  attr(tr2[[c(1,1)]], "stopened")    )
expect_null(  attr(tr2[[c(1,1,1)]], "stopened")   )

# testing if selected and checked state are copied from second tree to first
attr(tro[[c(1,1)]], "stselected")<-T
attr(tro[[c(1,1)]], "stchecked")<-T
tr2<-prune_closed(tr, tro)
expect_true( attr(tr2[[1]], "stopened") )
expect_true( attr(tr2[[c(1,1)]], "stselected") )
expect_true( attr(tr2[[c(1,1)]], "stchecked") )



# if we close a checked node, it not gets unchecked
attr(tro[[c(1,1)]], "stopened")<-T
tr2<-prune_closed(tr, tro)
expect_true( attr(tr2[[c(1,1)]], "stopened") )
expect_true( attr(tr2[[c(1,1)]], "stselected") )
expect_true( attr(tr2[[c(1,1)]], "stchecked") )

attr(tro[[c(1,1)]], "stopened")<-F
tr2<-prune_closed(tr, tro)
expect_false( attr(tr2[[c(1,1)]], "stopened") )
expect_true( attr(tr2[[c(1,1)]], "stselected") )
expect_true( attr(tr2[[c(1,1)]], "stchecked") )

# if we open a node with a checked child node, using a pruned input_tree....
attr(tr[[c(1,1,1)]],"stchecked")<-T
# first prune tro with closed node 1,1
tro<-prune_closed(tro)
#then open node 1,1
attr(tro[[c(1)]], "stopened")<-T # why this?
attr(tro[[c(1,1)]], "stopened")<-T
# now try to expand, 
tr2<-prune_closed(tr, tro)
expect_true(attr(tr[[c(1,1,1)]],"stchecked"))  #T
expect_null(attr(tro[[c(1,1,1)]],"stchecked")) #null
expect_true(attr(tr2[[c(1,1,1)]],"stchecked")) #T
tdanker/ephys2 documentation built on Aug. 11, 2019, 12:12 p.m.