Add tests for file_view.
This commit is contained in:
@@ -10,7 +10,7 @@ module Gollum
|
||||
end
|
||||
|
||||
def enclose_tree string
|
||||
%Q(<ol class="tree">\n) + string + %Q(\n</ol>)
|
||||
%Q(<ol class="tree">\n) + string + %Q(</ol>)
|
||||
end
|
||||
|
||||
def new_page page
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
<ol class="tree">
|
||||
<li class="file"><a href="0">0</a></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,8 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="0">0</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -0,0 +1,8 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>.</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="folder0">folder0</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -0,0 +1,12 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="0">0</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder1</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="1">1</a></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,13 @@
|
||||
<ol class="tree">
|
||||
<li class="file"><a href="root">root</a></li>
|
||||
<li>
|
||||
<label>folder0</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="0">0</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder1</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="1">1</a></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,18 @@
|
||||
<ol class="tree">
|
||||
<li>
|
||||
<label>folder0/folder1/folder2</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="0">0</a></li>
|
||||
<li>
|
||||
<label>folder3</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="1">1</a></li>
|
||||
</ol>
|
||||
</li>
|
||||
</ol>
|
||||
</li>
|
||||
<li>
|
||||
<label>folder4</label> <input type="checkbox" checked />
|
||||
<ol>
|
||||
<li class="file"><a href="2">2</a></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,107 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
require File.expand_path '../../lib/gollum/file_view', __FILE__
|
||||
|
||||
class FakePage
|
||||
def initialize filepath
|
||||
@filepath = filepath
|
||||
end
|
||||
|
||||
def path
|
||||
return @filepath
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def name
|
||||
self.class.canonicalize_filename @filepath
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def self.strip_filename filename
|
||||
::File.basename( filename, ::File.extname( filename ))
|
||||
end
|
||||
|
||||
# From page.rb
|
||||
def self.canonicalize_filename filename
|
||||
strip_filename(filename).gsub('-', ' ')
|
||||
end
|
||||
end
|
||||
|
||||
class FakePages
|
||||
def initialize filepath_array
|
||||
@array = filepath_array.map { | filepath | FakePage.new filepath }
|
||||
end
|
||||
|
||||
def size
|
||||
@array.size
|
||||
end
|
||||
|
||||
def [] index
|
||||
@array[ index ]
|
||||
end
|
||||
end
|
||||
|
||||
def view pages
|
||||
Gollum::FileView.new( pages ).render_files
|
||||
end
|
||||
|
||||
@@test_path = File.expand_path( '../file_view/' , __FILE__ ) + '/'
|
||||
|
||||
def read file
|
||||
File.read @@test_path + file + '.txt'
|
||||
end
|
||||
|
||||
# For creating expected files.
|
||||
def write file, content
|
||||
File.open(@@test_path + file + '.txt', 'w') do | f |
|
||||
f.write content
|
||||
end
|
||||
end
|
||||
|
||||
# Test Notes
|
||||
# root files must be before any folders.
|
||||
# Home.md => file at root folder
|
||||
# docs/sanitization.md => file within folder
|
||||
context 'file_view' do
|
||||
test 'one file' do
|
||||
pages = FakePages.new [ '0.md' ]
|
||||
expected = read '1_file'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
test 'one folder' do
|
||||
pages = FakePages.new [ 'folder0/' ]
|
||||
expected = read '1_folder'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
test 'one file with one folder' do
|
||||
pages = FakePages.new [ 'folder0/0.md' ]
|
||||
expected = read '1_file_1_folder'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
test 'two files with two folders' do
|
||||
pages = FakePages.new [ 'folder0/0.md', 'folder1/1.md' ]
|
||||
expected = read '2_files_2_folders'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
test 'two files with two folders and one root file' do
|
||||
pages = FakePages.new [ 'root.md', 'folder0/0.md', 'folder1/1.md' ]
|
||||
expected = read '2_files_2_folders_1_root'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
|
||||
test 'nested folders' do
|
||||
pages = FakePages.new [ 'folder0/folder1/folder2/0.md', 'folder0/folder1/folder3/1.md', 'folder4/2.md' ]
|
||||
expected = read 'nested_folders'
|
||||
actual = view pages
|
||||
assert_equal expected, actual
|
||||
end
|
||||
end # context
|
||||
Reference in New Issue
Block a user