forked from prerender/prerender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-spec.js
100 lines (55 loc) · 2.75 KB
/
index-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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var assert = require('assert'),
sinon = require('sinon'),
prerender = require('../index'),
util = require('../lib/util')
describe('Prerender', function() {
describe('#util', function() {
var sandbox;
beforeEach(function() {
sandbox = sinon.createSandbox();
});
afterEach(function() {
sandbox.restore();
});
it('should remove the / from the beginning of the URL if present', function() {
var url = util.getUrl('/http://www.example.com/');
assert.equal(url, 'http://www.example.com/');
});
it('should return the correct URL for #! URLs without query strings', function() {
var url = util.getUrl('http://www.example.com/?_escaped_fragment_=/user/1');
assert.equal(url, 'http://www.example.com/#!/user/1');
});
it('should return the correct URL for #! URLs with query strings', function() {
var url = util.getUrl('http://www.example.com/?_escaped_fragment_=/user/1¶m1=yes¶m2=no');
assert.equal(url, 'http://www.example.com/?param1=yes¶m2=no#!/user/1');
});
it('should return the correct URL for #! URLs if query string is before hash', function() {
var url = util.getUrl('http://www.example.com/?param1=yes¶m2=no&_escaped_fragment_=/user/1');
assert.equal(url, 'http://www.example.com/?param1=yes¶m2=no#!/user/1');
});
it('should return the correct URL for #! URLs that are encoded with another ?', function() {
var url = util.getUrl('http://www.example.com/?_escaped_fragment_=%2Fuser%2F1%3Fparam1%3Dyes%26param2%3Dno');
assert.equal(url, 'http://www.example.com/?param1=yes¶m2=no#!/user/1');
});
it('should return the correct URL for html5 push state URLs', function() {
var url = util.getUrl('http://www.example.com/user/1?_escaped_fragment_=');
assert.equal(url, 'http://www.example.com/user/1');
});
it('should return the correct URL for html5 push state URLs with query strings', function() {
var url = util.getUrl('http://www.example.com/user/1?param1=yes¶m2=no&_escaped_fragment_=');
assert.equal(url, 'http://www.example.com/user/1?param1=yes¶m2=no');
});
it('should fix incorrect html5 URL that Bing accesses', function() {
var url = util.getUrl('http://www.example.com/?&_escaped_fragment_=');
assert.equal(url, 'http://www.example.com/');
});
it('should encode # correctly in URLs that do not use the #!', function() {
var url = util.getUrl('http://www.example.com/productNumber=123%23456?_escaped_fragment_=');
assert.equal(url, 'http://www.example.com/productNumber=123%23456');
});
it('should not encode non-english characters', function() {
var url = util.getUrl('http://www.example.com/كاليفورنيا?_escaped_fragment_=');
assert.equal(url, 'http://www.example.com/كاليفورنيا');
});
});
});