Skip to content

Commit

Permalink
Adds tests for current.path and current.source
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethormandy committed Jan 17, 2014
1 parent aab820d commit 2826c38
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,15 @@ exports.getCurrent = function(sourcePath){

// this could be a tad smarter
var namespace = sourcePath.split(".")[0].split("/")

var base = '';
namespace.slice(0, namespace.length - 1) ? namespace.slice(0, namespace.length - 1).forEach(function() { base += '../' }) : ''
return {
source: namespace[namespace.length -1],
path: namespace
path: namespace,
base: base
}
}


/**
*
* Source Type
Expand Down
97 changes: 97 additions & 0 deletions test/current.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
var should = require('should')
var polymer = require('../')

describe("current", function(){

describe("base", function(){
var root = __dirname + "/fixtures/current/base"
var poly = polymer.root(root)

it("should use a relative path in the root", function(done){
poly.render("index.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>Matthew Carter</h1>")
body.should.include("<link href=\"main.css\" rel=\"stylesheet\" type=\"text/css\">")
done()
})
})

it("should use a relative path when nested", function(done){
poly.render("georgia/verdana/helvetica/index.ejs", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>Matthew Carter</h1>")
body.should.include("<link href=\"../../../main.css\" rel=\"stylesheet\" type=\"text/css\">")
done()
})
})

})

describe("path", function(){
var root = __dirname + "/fixtures/current/path"
var poly = polymer.root(root)

it("should provide current path", function(done){
poly.render("index.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<h1>index</h1>")
done()
})
})

it("should provide current path in to an index page in a subdirectory", function(done){
poly.render("one/two/index.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<li><a href=\"#\">one</a>")
body.should.include("<li><a href=\"#\">two</a>")
body.should.include("<li><a href=\"#\">index</a>")
done()
})
})


it("should provide current path to a non-index page in a subdirectory", function(done){
poly.render("one/two/three/about.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<li><a href=\"#\">one</a>")
body.should.include("<li><a href=\"#\">two</a>")
body.should.include("<li><a href=\"#\">three</a>")
body.should.include("<li><a href=\"#\">about</a>")
body.should.not.include("index")
done()
})
})

it("should provide a portion of the current path", function(done){
poly.render("contact/index.ejs", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<title>contact</title>")
done()
})
})


})

describe("source", function(){
var root = __dirname + "/fixtures/current/source"
var poly = polymer.root(root)

it("should provide the current source", function(done){
poly.render("about.jade", function(error, body){
should.not.exist(error)
should.exist(body)
body.should.include("<a href=\"about\" class=\"active\">About</a>")
done()
})
})

})

})
8 changes: 8 additions & 0 deletions test/fixtures/current/path/contact/index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<title><%= current.path[0] %></title>
</head>
<body>
</body>
</html>
6 changes: 6 additions & 0 deletions test/fixtures/current/path/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
doctype
html
head
title Home
body
h1= current.path
9 changes: 9 additions & 0 deletions test/fixtures/current/path/one/two/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
doctype
html
head
title Two
body
h1 Where am I?
ul
each item in current.path
li: a(href="#")= item
9 changes: 9 additions & 0 deletions test/fixtures/current/path/one/two/three/about.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
doctype
html
head
title About
body
h1 Where am I?
ul
each item in current.path
li: a(href="#")= item
8 changes: 8 additions & 0 deletions test/fixtures/current/source/about.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doctype
html
head
title About
body
nav
a(href="/") Home
a(href="about" class="#{ current.source == 'about' ? 'active' : 'inactive' }") About

0 comments on commit 2826c38

Please sign in to comment.