-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaced-templates-tests.js
77 lines (63 loc) · 3.23 KB
/
namespaced-templates-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Tinytest.add("namespaced templating basic pre-scanner", function (test) {
var res
// basic template renaming
res = html_scanner.preScan('<template name="foo"></template>', 'foo_tpl')
test.equal(res, '<template name="foo_foo"></template>')
})
Tinytest.add("namespaced templating nested path pre-scanner", function (test) {
var res
// nested path template renaming
res = html_scanner.preScan('<template name="foo"></template>', 'foo_bar_tpl')
test.equal(res, '<template name="foo_bar_foo"></template>')
})
Tinytest.add("namespaced templating no path pre-scanner", function (test) {
var res
// no path template renaming
res = html_scanner.preScan('<template name="foo"></template>', 'tpl')
test.equal(res, '<template name="foo"></template>')
})
Tinytest.add("namespaced templating testing ${{>template}} replacement pre-scanner", function (test) {
var res
// replace ${{>
res = html_scanner.preScan('<template name="foo">{{>other}}${{>our}}</template>', 'foo_tpl')
test.equal(res, '<template name="foo_foo">{{>other}}{{> Template.dynamic ___goto "our" "***noargs***"}}</template>')
res = html_scanner.preScan('<template name="foo">{{>other}}${{>our item1="thing" }}</template>', 'foo_tpl')
test.equal(res, '<template name="foo_foo">{{>other}}{{> Template.dynamic ___goto "our" item1="thing" }}</template>')
// 2 templates in the same file
res = html_scanner.preScan('<template name="foo">{{>other}}${{>our item1="thing" }}</template>' +
'<template name="next">${{>bar}}</template>', 'foo_tpl')
test.equal(res, '<template name="foo_foo">{{>other}}{{> Template.dynamic ___goto "our" item1="thing" }}</template>' +
'<template name="foo_next">{{> Template.dynamic ___goto "bar" "***noargs***"}}</template>')
})
Tinytest.add("namespaced template with <body> tag pre-scanner", function(test) {
var res
res = html_scanner.preScan("<head>\n"+
"<title>Namespaced Templates Example</title>\n" +
"</head>\n" +
"\n" +
"<body>\n" +
"<h1>Welcome to Meteor!</h1>\n" +
"\n" +
"<h2>Please select a template path</h2>\n" +
"<input type=\"radio\" name=\"template\" id=\"first\" value=\"first:second\"><label for=\"first\">first:second</label>\n" +
"<input type=\"radio\" name=\"template\" id=\"second\" value=\"second:first\"><label for=\"second\">second:first</label>\n" +
"${{> hello}}\n" +
"</body>", 'example', true)
test.equal(res, "<head>\n"+
"<title>Namespaced Templates Example</title>\n" +
"</head>\n" +
"\n" +
"<body>\n" +
"<h1>Welcome to Meteor!</h1>\n" +
"\n" +
"<h2>Please select a template path</h2>\n" +
"<input type=\"radio\" name=\"template\" id=\"first\" value=\"first:second\"><label for=\"first\">first:second</label>\n" +
"<input type=\"radio\" name=\"template\" id=\"second\" value=\"second:first\"><label for=\"second\">second:first</label>\n" +
"{{> Template.dynamic ___goto \"hello\" \"***noargs***\"}}\n" +
"</body>")
})
Tinytest.add("whitespace at end of template tag", function(test) {
var res
res = html_scanner.preScan("<template name=\"test\">${{> subthing }}</template>", 'foo')
test.equal(res, "<template name=\"test\">{{> Template.dynamic ___goto \"subthing\" \"***noargs***\"}}</template>")
})