UNPKG

2.82 kBJavaScriptView Raw
1var assert = require('assert'),
2 sinon = require('sinon'),
3 prerender = require('../index'),
4 util = require('../lib/util')
5
6describe('Prerender', function() {
7
8 describe('#util', function() {
9
10 var sandbox;
11
12 beforeEach(function() {
13 sandbox = sinon.createSandbox();
14 });
15
16 afterEach(function() {
17 sandbox.restore();
18 });
19
20 it('should remove the / from the beginning of the URL if present', function() {
21
22 var url = util.getUrl('/http://www.example.com/');
23
24 assert.equal(url, 'http://www.example.com/');
25
26 });
27
28 it('should return the correct URL for #! URLs without query strings', function() {
29
30 var url = util.getUrl('http://www.example.com/?_escaped_fragment_=/user/1');
31
32 assert.equal(url, 'http://www.example.com/#!/user/1');
33
34 });
35
36 it('should return the correct URL for #! URLs with query strings', function() {
37
38 var url = util.getUrl('http://www.example.com/?_escaped_fragment_=/user/1&param1=yes&param2=no');
39
40 assert.equal(url, 'http://www.example.com/?param1=yes&param2=no#!/user/1');
41
42 });
43
44 it('should return the correct URL for #! URLs if query string is before hash', function() {
45
46 var url = util.getUrl('http://www.example.com/?param1=yes&param2=no&_escaped_fragment_=/user/1');
47
48 assert.equal(url, 'http://www.example.com/?param1=yes&param2=no#!/user/1');
49
50 });
51
52 it('should return the correct URL for #! URLs that are encoded with another ?', function() {
53
54 var url = util.getUrl('http://www.example.com/?_escaped_fragment_=%2Fuser%2F1%3Fparam1%3Dyes%26param2%3Dno');
55
56 assert.equal(url, 'http://www.example.com/?param1=yes&param2=no#!/user/1');
57
58 });
59
60 it('should return the correct URL for html5 push state URLs', function() {
61
62 var url = util.getUrl('http://www.example.com/user/1?_escaped_fragment_=');
63
64 assert.equal(url, 'http://www.example.com/user/1');
65
66 });
67
68 it('should return the correct URL for html5 push state URLs with query strings', function() {
69
70 var url = util.getUrl('http://www.example.com/user/1?param1=yes&param2=no&_escaped_fragment_=');
71
72 assert.equal(url, 'http://www.example.com/user/1?param1=yes&param2=no');
73
74 });
75
76 it('should fix incorrect html5 URL that Bing accesses', function() {
77
78 var url = util.getUrl('http://www.example.com/?&_escaped_fragment_=');
79
80 assert.equal(url, 'http://www.example.com/');
81
82 });
83
84
85 it('should encode # correctly in URLs that do not use the #!', function() {
86
87 var url = util.getUrl('http://www.example.com/productNumber=123%23456?_escaped_fragment_=');
88
89 assert.equal(url, 'http://www.example.com/productNumber=123%23456');
90
91 });
92
93 it('should not encode non-english characters', function() {
94
95 var url = util.getUrl('http://www.example.com/كاليفورنيا?_escaped_fragment_=');
96
97 assert.equal(url, 'http://www.example.com/كاليفورنيا');
98 });
99 });
100});
\No newline at end of file