UNPKG

2.64 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.7.1
2var View, assert, makeReq, makeRes, path;
3
4assert = require("assert");
5
6path = require('path');
7
8makeReq = function(config) {
9 if (config == null) {
10 config = {};
11 }
12 return config;
13};
14
15makeRes = function() {
16 return {
17 locals: {}
18 };
19};
20
21View = (require('../index.js')).view;
22
23describe('View', function() {
24 describe('viewPaths()', function() {
25 it('configure', function(done) {
26 View.configure({
27 folders: ['a', 'b']
28 }, {
29 get: function() {
30 return function(name, cfg) {
31 return this.root = cfg.root, this.ext = cfg.ext, cfg;
32 };
33 },
34 set: function() {}
35 });
36 assert.deepEqual(['a', 'b'], View.viewPaths());
37 return done();
38 });
39 return it('addViewPath', function(done) {
40 View.configure({
41 folders: ['a', 'b']
42 });
43 View.addViewPath('1');
44 assert.deepEqual(['1', 'a', 'b'], View.viewPaths());
45 return done();
46 });
47 });
48 return describe('lookup()', function() {
49 it('default', function(done) {
50 var app_view, tv;
51 app_view = null;
52 View.configure({
53 folders: [path.join(__dirname, "view", "root"), path.join(__dirname, "view", "view2")]
54 }, {
55 get: function() {
56 return function(name, cfg) {
57 return this.root = cfg.root, this.ext = cfg.ext, cfg;
58 };
59 },
60 set: function(key, view) {
61 return app_view = view;
62 }
63 });
64 tv = new app_view('view2_view', {
65 root: path.join(__dirname, "view", "root")
66 });
67 assert.equal(path.join(__dirname, 'view', 'view2', 'view2_view.dust'), tv.lookup('view2_view.dust'));
68 assert.equal(path.join(__dirname, 'view', 'root', 'root_view.dust'), tv.lookup('root_view.dust'));
69 return done();
70 });
71 return it('multiple filename', function(done) {
72 var app_view, tv;
73 app_view = null;
74 View.configure({
75 folders: [path.join(__dirname, "view")]
76 }, {
77 get: function() {
78 return function(name, cfg) {
79 return this.root = cfg.root, this.ext = cfg.ext, cfg;
80 };
81 },
82 set: function(key, view) {
83 return app_view = view;
84 }
85 });
86 tv = new app_view("view1/page-article,view1/page--user--zh-cn,view1/page--user", {
87 root: path.join(__dirname, "view")
88 });
89 assert.equal(path.join(__dirname, 'view', 'view1', 'page--user--zh-cn.dust'), tv.lookup("view1/page-article,view1/page--user--zh-cn,view1/page--user.dust"));
90 return done();
91 });
92 });
93});
94
95//# sourceMappingURL=view_test.map