-
Notifications
You must be signed in to change notification settings - Fork 2
/
pagine.spec.js
78 lines (63 loc) · 1.73 KB
/
pagine.spec.js
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
import Pagine from '../lib/pagine.js';
import { $ } from '../lib/dom';
function bootstrap() {
beforeEach(() => {
this.pagine = new Pagine({
view: '#view',
routes: [
{
path: '/home',
md: '## home page',
layout: '#main'
},
{
path: '/about',
md: '## about page',
layout: '#main'
}
]
});
document.body.innerHTML = `
<div id="view"></div>
<script type="text/html" id="main">
<%= content %>
</script>
`
});
}
describe('Pagine module', function() {
describe('router', function() {
bootstrap.call(this);
it('should create routes', () => {
expect(this.pagine.router._routes.length).toBe(2);
});
});
describe('markdown transformation', function() {
bootstrap.call(this);
it('should compile markdown to html', () => {
const md = this.pagine.compileMarkdown('# hello');
expect(md).toEqual('<h1>hello</h1>')
})
});
describe('view rendering', () => {
bootstrap.call(this);
it('should compile template into view', () => {
this.pagine.setContent('main', '# Readme');
var output = $('#view').first().innerHTML.trim()
console.log(output);
expect(output).toBe('<h1>Readme</h1>');
});
/*
* TODO: Fix this unit test to change URL location
*/
it('should change view content on route change', () => {
var output;
window.location.url = '#/home';
output = $('#view').first().innerHTML.trim()
expect(output).toBe('<h2>home page</h2>');
window.location.url = '#/about';
output = $('#view').first().innerHTML.trim()
expect(output).toBe('<h2>about page</h2>')
});
})
});