Fixes for componentized Pagedform
[tcl-tlc.git] / tests / form_default_handling.test
blobdc0e9fbb3ce464a01b928017b5a1c25826ae4378
1 # vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
3 if {[lsearch [namespace children] ::tcltest] == -1} {
4         package require tcltest 2.2.5
5         namespace import ::tcltest::*
8 package require TLC
10 test form_default_handling-1.1 {Check correct order of precedence with no default values, no _onchange} -body { #<<<
11         tlc::Form .f -name "form_default_handling-1.1" -schema {
12                 "Foo"           {foo radiogroup -choices {
13                         "option 1"      {option1}
14                         "option 2"      {option2}
15                         "option 3"      {option3}
16                 }}
17                 "Bar"           {bar checkbutton}
18                 "History"       {history entry}
19                 "Thing"         {thing entry}
20         }
21         .f set_data     [dict create \
22                         foo             "option2" \
23                         bar             0 \
24                         history "Updated" \
25                         thing   "Also updated" \
26         ]
27         set dat [.f get_data]
28         list [dict get $dat foo] [dict get $dat bar] [dict get $dat history] [dict get $dat thing]
29 } -cleanup {
30         if {[itcl::is object .f]} {delete object .f}
31 } -result [list option2 0 Updated "Also updated"]
32 #>>>
33 test form_default_handling-1.2 {Check correct order of precedence with default values, no _onchange} -body { #<<<
34         tlc::Form .f -name "form default_handling-1.2" -schema {
35                 "Foo"           {foo radiogroup -choices {
36                         "option 1"      {option1}
37                         "option 2"      {option2}
38                         "option 3"      {option3}
39                 }}
40                 "Bar"           {bar checkbutton}
41                 "History"       {history entry}
42                 "Thing"         {thing entry}
44                 _defaults {
45                         foo             "option1"
46                         bar             1
47                         history "Foo"
48                 }
49         }
50         .f set_data     [dict create \
51                         foo             "option2" \
52                         bar             0 \
53                         history "Updated" \
54                         thing   "Also updated" \
55         ]
56         set dat [.f get_data]
57         list [dict get $dat foo] [dict get $dat bar] [dict get $dat history] [dict get $dat thing]
58 } -cleanup {
59         if {[itcl::is object .f]} {delete object .f}
60 } -result [list option2 0 Updated "Also updated"]
61 #>>>
63 ::tcltest::cleanupTests
64 return