forked from gollum/gollum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pages_view.rb
78 lines (68 loc) · 3.69 KB
/
test_pages_view.rb
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
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
require File.expand_path '../../lib/gollum/views/pages', __FILE__
class FakeSane
def clean(data)
data
end
end
class FakeWiki
def sanitizer
FakeSane.new
end
end
FakePageResult = Struct.new(:path) do
def name
File.basename(path, File.extname(path)).gsub("-", " ")
end
def escaped_url_path
CGI.escape(path).gsub(/\..+$/, "").gsub("%2F", "/")
end
def format
true
end
end
FakeFileResult = Struct.new(:path) do
def name
File.basename(path).gsub("-", " ")
end
def escaped_url_path
result = path.sub(/\/[^\/]+$/, '/')
CGI.escape(result).gsub("%2F", "/")
end
end
context "Precious::Views::Pages" do
setup do
@page = Precious::Views::Pages.new
@page.instance_variable_set("@wiki", FakeWiki.new)
end
test "breadcrumb" do
@page.instance_variable_set("@path", "Mordor/Eye-Of-Sauron/Saruman")
@page.instance_variable_set("@base_url", "")
assert_equal '<a href="/pages/">Home</a> / <a href="/pages/Mordor/">Mordor</a> / <a href="/pages/Mordor/Eye-Of-Sauron/">Eye-Of-Sauron</a> / Saruman', @page.breadcrumb
end
test "breadcrumb with no path" do
assert_equal 'Home', @page.breadcrumb
end
test "folders first" do
@page.instance_variable_set("@base_url", "")
results = [FakePageResult.new("Gondor/Bromir.md"), FakePageResult.new("Hobbit.md"), FakePageResult.new("Home.md"), FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakePageResult.new("Mordor/todo.md"), FakePageResult.new("Rivendell/Elrond.md"), FakePageResult.new("My-Precious.md"), FakePageResult.new("Zamin.md"), FakePageResult.new("Samwise-Gamgee.md"), FakePageResult.new("roast-mutton.md"), FakePageResult.new("Bilbo-Baggins.md")]
@page.instance_variable_set("@results", results)
assert_equal %{<li><a href="/pages/Gondor/" class="folder">Gondor</a></li>\n<li><a href="/pages/Mordor/" class="folder">Mordor</a></li>\n<li><a href="/pages/Rivendell/" class="folder">Rivendell</a></li>\n<li><a href="/Bilbo-Baggins" class="file">Bilbo Baggins</a></li>\n<li><a href="/Hobbit" class="file">Hobbit</a></li>\n<li><a href="/Home" class="file">Home</a></li>\n<li><a href="/My-Precious" class="file">My Precious</a></li>\n<li><a href="/roast-mutton" class="file">roast mutton</a></li>\n<li><a href="/Samwise-Gamgee" class="file">Samwise Gamgee</a></li>\n<li><a href="/Zamin" class="file">Zamin</a></li>}, @page.files_folders
end
test "files_folders from subdir" do
@page.instance_variable_set("@path", "Mordor")
@page.instance_variable_set("@base_url", "")
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakeFileResult.new("Mordor/.gitkeep")]
@page.instance_variable_set("@results", results)
assert_equal %{<li><a href="/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/Mordor/Eye-Of-Sauron" class="file">Eye Of Sauron</a></li>}, @page.files_folders
end
test "base url" do
# based on test "files_folders"
@page.instance_variable_set("@path", "Mordor")
@page.instance_variable_set("@base_url", "/wiki")
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakePageResult.new("Mordor/.gitkeep")]
@page.instance_variable_set("@results", results)
assert_equal %{<li><a href="/wiki/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/wiki/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/wiki/Mordor/Eye-Of-Sauron" class="file">Eye Of Sauron</a></li>}, @page.files_folders
end
end