Debian Codegraph @

dojox/dtl/tests/context.js

raw symbols SCIP
1 dojo.provide("dojox.dtl.tests.context");
2
3 dojo.require("dojox.dtl");
4 dojo.require("dojox.dtl.Context");
5
6 doh.register("dojox.dtl.context",
7 [
8 function test_context_creation(t){
9 var context = new dojox.dtl.Context({ foo: "foo", bar: "bar" });
10 t.is("foo", context.foo);
11 t.is("bar", context.bar);
12 },
13 function test_context_push(t){
14 var context = new dojox.dtl.Context({ foo: "foo", bar: "bar" });
15 context = context.push();
16 var found = false;
17 for(var key in context){
18 if(key == "foo" || key == "bar"){
19 found = true;
20 }
21 }
22 t.t(found);
23 },
24 function test_context_getter(t){
25 var context = new dojox.dtl.Context({foo: "foo", bar: "bar", get: function(key){ return key + "TEST"; }});
26 var tpl = new dojox.dtl.Template("{{ foo }}-{{ bar }}");
27 t.is("fooTEST-barTEST", tpl.render(context));
28 },
29 function test_context_pop(t){
30 var context = new dojox.dtl.Context({ foo: "foo", bar: "bar" });
31 context = context.push();
32 t.f(context.hasOwnProperty("foo"));
33 t.f(context.hasOwnProperty("bar"));
34 context = context.pop();
35 t.is("foo", context.foo);
36 t.is("bar", context.bar);
37 },
38 function test_context_overpop(t){
39 var context = new dojox.dtl.Context();
40 try{
41 context = context.pop();
42 t.t(false);
43 }catch(e){
44 t.is("pop() called on empty Context", e.message);
45 }
46 },
47 function test_context_filter(t){
48 var context = new dojox.dtl.Context({ foo: "one", bar: "two", baz: "three" });
49 var filtered = context.filter("foo", "bar");
50 t.is(filtered.foo, "one");
51 t.is(filtered.bar, "two");
52 t.f(filtered.baz);
53
54 filtered = context.filter({ bar: true, baz: true });
55 t.f(filtered.foo);
56 t.is(filtered.bar, "two");
57 t.is(filtered.baz, "three");
58
59 filtered = context.filter(new dojox.dtl.Context({ foo: true, baz: true }));
60 t.is(filtered.foo, "one");
61 t.f(filtered.bar);
62 t.is(filtered.baz, "three");
63 },
64 function test_context_extend(t){
65 var context = new dojox.dtl.Context({ foo: "one" });
66 var extended = context.extend({ bar: "two", baz: "three" });
67 t.is(extended.foo, "one");
68 t.is(extended.bar, "two");
69 t.is(extended.baz, "three");
70
71 extended = context.extend({ barr: "two", bazz: "three" });
72 t.is(extended.foo, "one");
73 t.f(extended.bar);
74 t.f(extended.baz);
75 t.is(extended.barr, "two");
76 t.is(extended.bazz, "three");
77
78 t.f(context.bar)
79 t.f(context.baz);
80 t.f(context.barr);
81 t.f(context.bazz);
82 }
83 ]
84 );