test/test_jamstack.rb in impression-0.5 vs test/test_jamstack.rb in impression-0.6
- old
+ new
@@ -106,11 +106,11 @@
head {
title 'AAA'
}
body {
article {
- h2 'BBB', id: 'bbb'
+ h2 'ZZZ', id: 'zzz'
}
}
}
}
assert_response a.render, :html, req
@@ -196,11 +196,11 @@
head {
title 'AAA'
}
body {
article {
- h2 'BBB', id: 'bbb'
+ h2 'ZZZ', id: 'zzz'
}
}
}
}
assert_response a.render, :html, req
@@ -209,36 +209,47 @@
def test_page_list
@jamstack = Impression::Jamstack.new(path: '/app', directory: JAMSTACK_PATH)
list = @jamstack.page_list('/')
assert_equal [
- { path: File.join(JAMSTACK_PATH, 'bar.html'), url: '/app/bar' },
- { path: File.join(JAMSTACK_PATH, 'index.md'), title: 'Hello', url: '/app/index' },
+ { kind: :file, path: File.join(JAMSTACK_PATH, 'bar.html'), ext: '.html', url: '/app/bar' },
+ { kind: :file, path: File.join(JAMSTACK_PATH, 'index.md'), ext: '.md', url: '/app',
+ title: 'Hello', foo: 'BarBar', markdown_content: '<h1>Index</h1>' },
], list
list = @jamstack.page_list('/articles')
+
assert_equal [
{
+ kind: :file,
path: File.join(JAMSTACK_PATH, 'articles/2008-06-14-manu.md'),
url: '/app/articles/2008-06-14-manu',
+ ext: '.md',
title: 'MMM',
layout: 'article',
+ markdown_content: "## BBB\n",
date: Date.new(2008, 06, 14)
},
{
+ kind: :file,
path: File.join(JAMSTACK_PATH, 'articles/2009-06-12-noatche.md'),
url: '/app/articles/2009-06-12-noatche',
+ ext: '.md',
title: 'NNN',
layout: 'article',
+ markdown_content: "## CCC\n",
date: Date.new(2009, 06, 12)
},
{
+ kind: :file,
path: File.join(JAMSTACK_PATH, 'articles/a.md'),
url: '/app/articles/a',
+ ext: '.md',
title: 'AAA',
- layout: 'article'
+ layout: 'article',
+ markdown_content: "## ZZZ\n"
},
], list
end
def test_template_resource_and_request
@@ -257,7 +268,44 @@
a 'AAA', href: '/articles/a'
}
}
}
assert_response foo.render, :html, req
+ end
+
+ def path_info(path)
+ @jamstack.send(:get_path_info, path)
+ end
+
+ def test_path_info
+ assert_equal({
+ kind: :file,
+ path: File.join(JAMSTACK_PATH, 'index.md'),
+ ext: '.md',
+ url: '/',
+ title: 'Hello',
+ foo: 'BarBar',
+ markdown_content: '<h1>Index</h1>'
+ }, path_info('/index'))
+
+ assert_equal({
+ kind: :file,
+ path: File.join(JAMSTACK_PATH, 'index.md'),
+ ext: '.md',
+ url: '/',
+ title: 'Hello',
+ foo: 'BarBar',
+ markdown_content: '<h1>Index</h1>'
+ }, path_info('/'))
+
+ assert_equal({
+ kind: :file,
+ path: File.join(JAMSTACK_PATH, 'assets/js/a.js'),
+ ext: '.js',
+ url: '/assets/js/a.js'
+ }, path_info('/assets/js/a.js'))
+
+ assert_equal({
+ kind: :not_found,
+ }, path_info('/js/b.js'))
end
end