-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.coffee
93 lines (87 loc) · 3.46 KB
/
gulpfile.coffee
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# copyright © 201{4,5,6} Jess Austin <jess.austin@gmail.com>, MIT license
gulp = require 'gulp'
matter = require 'jade-var-matter'
through = require 'through2'
test = require 'tape'
{connect, data, filter, jade, stream} = (require 'gulp-load-plugins')()
start = ->
nav = require './gulp-nav' # convenient during development to wait until now
gulp.src 'test/**/*.jade'
.pipe data ({ contents }) ->
matter String contents
.pipe nav orders: ['order', 'ord']
gulp.task 'build', ->
start()
.pipe jade pretty: true
.pipe gulp.dest 'test/dist'
gulp.task 'default', ['build'], ->
connect.server root: 'test/dist'
gulp.task 'test', ->
runTest 'Buffer', start()
runTest 'Stream', start().pipe stream()
runTest = (label, src) ->
src.pipe filter '*/latin/b.jade'
.pipe through.obj ({ nav }) ->
titleMsg = 'Nav should have this title.'
hrefMsg = 'Nav should have this href.'
activeMsg = 'Nav should be active.'
notActiveMsg = 'Nav shouldn\'t be active.'
activeDescendant = 'Nav should have an active descendant.'
noActiveDescendants = 'Nav shouldn\'t have an active descendant.'
test "Self-#{label}", (assert) ->
assert.is nav.title, 'B', titleMsg
assert.is nav.href, 'b.html', hrefMsg
assert.ok nav.active, activeMsg
assert.notOk nav.hasActiveDescendant, noActiveDescendants
assert.end()
test "Parent-#{label}", (assert) ->
assert.is nav.parent.title, 'Latin', titleMsg
assert.is nav.parent.href, '.', hrefMsg
assert.notOk nav.parent.active, notActiveMsg
assert.is nav.root.href, nav.parent.root.href, hrefMsg
assert.ok nav.parent.hasActiveDescendant, activeDescendant
assert.end()
test "Grandparent-#{label}", (assert) ->
assert.is nav.parent.parent.title, 'Home', titleMsg
assert.is nav.parent.parent.href, '..', hrefMsg
assert.notOk nav.parent.parent.active, notActiveMsg
assert.is nav.root.href, nav.parent.parent.root.href, hrefMsg
assert.ok nav.parent.parent.hasActiveDescendant, activeDescendant
assert.end()
test "Siblings-#{label}", (assert) ->
for item, i in [
title: 'A'
href: 'letter-a.html'
active: no
,
title: 'B'
href: 'b.html'
active: yes
,
title: 'C'
href: 'c.html'
active: no
]
current = nav.siblings[i]
assert.is current.title, item.title, titleMsg
assert.is current.href, item.href, hrefMsg
assert.is current.active, item.active,
if item.active then activeMsg else notActiveMsg
assert.is nav.root.href, current.root.href, hrefMsg
assert.notOk current.hasActiveDescendant, noActiveDescendants
assert.end()
test "Children-#{label}", (assert) ->
assert.notOk nav.children.length, 'Nav should have no children.'
assert.end()
test "Root-#{label}", (assert) ->
assert.is nav.root.title, 'Home', titleMsg
assert.is nav.root.href, '..', hrefMsg
assert.is nav.root.href, nav.root.root.href, hrefMsg
assert.ok nav.root.hasActiveDescendant, activeDescendant
assert.notOk nav.root.active, notActiveMsg
assert.end()
test "No-Index", (assert) ->
assert.plan 1
for uncle in nav.parent.siblings
if uncle.title is 'Greek'
assert.notOk uncle.href?, "Nav without index shouldn't have href"