layouts.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. var should = require('should')
  2. var polymer = require('../')
  3. describe("layout", function(){
  4. describe("none", function(){
  5. var root = __dirname + "/fixtures/layouts/none"
  6. var poly = polymer.root(root)
  7. it("should render with no layout", function(done){
  8. poly.render("index.jade", function(errors, body){
  9. should.not.exist(errors)
  10. should.exist(body)
  11. body.should.eql("<h2>Home Page</h2>")
  12. done()
  13. })
  14. })
  15. it("should render with no layout too", function(done){
  16. poly.render("false/layout-false.jade", function(errors, body){
  17. should.not.exist(errors)
  18. should.exist(body)
  19. body.should.eql("<h2>Layout Explicitly Set to False</h2>")
  20. done()
  21. })
  22. })
  23. })
  24. describe("base", function(){
  25. var root = __dirname + "/fixtures/layouts/base"
  26. var poly = polymer.root(root)
  27. it("should render with layout in base", function(done){
  28. poly.render("index.jade", function(errors, body){
  29. should.not.exist(errors)
  30. should.exist(body)
  31. body.should.include("<h1>Layout in Base</h1>")
  32. body.should.include("<h2>Home Page</h2>")
  33. done()
  34. })
  35. })
  36. it("should render with no layout if asked to", function(done){
  37. poly.render("info.json.jade", function(errors, body){
  38. should.not.exist(errors)
  39. should.exist(body)
  40. var obj = JSON.parse(body)
  41. obj.should.have.property("source", "info.json")
  42. done()
  43. })
  44. })
  45. })
  46. describe("deep", function(){
  47. var root = __dirname + "/fixtures/layouts/deep"
  48. var poly = polymer.root(root)
  49. it("should render with layout in deep", function(done){
  50. poly.render("nested/something.jade", function(errors, body){
  51. should.not.exist(errors)
  52. should.exist(body)
  53. body.should.include("<h1>Nested Layout</h1>")
  54. body.should.include("<h2>Something</h2>")
  55. done()
  56. })
  57. })
  58. it("should render with cascading layout", function(done){
  59. poly.render("nested/deeply/heyo.jade", function(errors, body){
  60. should.not.exist(errors)
  61. should.exist(body)
  62. body.should.include("<h1>Nested Layout</h1>")
  63. body.should.include("<h2>Heyo</h2>")
  64. done()
  65. })
  66. })
  67. it("should render with relative explicit layout", function(done){
  68. poly.render("nested/deeply/relative.jade", function(errors, body){
  69. should.not.exist(errors)
  70. should.exist(body)
  71. body.should.include("<h1>Another Layout</h1>")
  72. body.should.include("<h2>Relative</h2>")
  73. done()
  74. })
  75. })
  76. it("should render with relative explicit layout 2", function(done){
  77. poly.render("nested/deeply/relative2.jade", function(errors, body){
  78. should.not.exist(errors)
  79. should.exist(body)
  80. body.should.include("<h1>Layout in Base</h1>")
  81. body.should.include("<h2>Relative 2</h2>")
  82. done()
  83. })
  84. })
  85. it("should render with no layout if asked to", function(done){
  86. poly.render("nested/deeply/relative2.jade", { layout: false }, function(errors, body){
  87. should.not.exist(errors)
  88. should.exist(body)
  89. body.should.not.include("<h1>Layout in Base</h1>")
  90. body.should.include("<h2>Relative 2</h2>")
  91. done()
  92. })
  93. })
  94. })
  95. })