|
1 | 1 | require('./helper');
|
2 | 2 | var URLStore = require('../modules/stores/URLStore');
|
3 | 3 |
|
4 |
| -describe('when a new path is pushed to the URL', function () { |
5 |
| - beforeEach(function () { |
6 |
| - URLStore.push('/a/b/c'); |
| 4 | +describe('URLStore', function() { |
| 5 | + |
| 6 | + beforeEach(function() { |
| 7 | + URLStore.setup("hash"); |
7 | 8 | });
|
8 | 9 |
|
9 |
| - afterEach(function () { |
| 10 | + afterEach(function() { |
10 | 11 | URLStore.teardown();
|
11 | 12 | });
|
12 | 13 |
|
13 |
| - it('has the correct path', function () { |
14 |
| - expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
15 |
| - }); |
16 |
| -}); |
| 14 | + describe('when a new path is pushed to the URL', function() { |
| 15 | + beforeEach(function() { |
| 16 | + URLStore.push('/a/b/c'); |
| 17 | + }); |
17 | 18 |
|
18 |
| -describe('when a new path is used to replace the URL', function () { |
19 |
| - beforeEach(function () { |
20 |
| - URLStore.replace('/a/b/c'); |
| 19 | + it('has the correct path', function() { |
| 20 | + expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 21 | + }); |
21 | 22 | });
|
22 | 23 |
|
23 |
| - afterEach(function () { |
24 |
| - URLStore.teardown(); |
25 |
| - }); |
| 24 | + describe('when a new path is used to replace the URL', function() { |
| 25 | + beforeEach(function() { |
| 26 | + URLStore.replace('/a/b/c'); |
| 27 | + }); |
26 | 28 |
|
27 |
| - it('has the correct path', function () { |
28 |
| - expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 29 | + it('has the correct path', function() { |
| 30 | + expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 31 | + }); |
29 | 32 | });
|
30 |
| -}); |
31 | 33 |
|
32 |
| -describe('when going back in history', function () { |
33 |
| - afterEach(function () { |
34 |
| - URLStore.teardown(); |
| 34 | + describe('when going back in history', function() { |
| 35 | + it('has the correct path', function() { |
| 36 | + URLStore.push('/a/b/c'); |
| 37 | + expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 38 | + |
| 39 | + URLStore.push('/d/e/f'); |
| 40 | + expect(URLStore.getCurrentPath()).toEqual('/d/e/f'); |
| 41 | + |
| 42 | + URLStore.back(); |
| 43 | + expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 44 | + }); |
35 | 45 | });
|
36 | 46 |
|
37 |
| - it('has the correct path', function () { |
38 |
| - URLStore.push('/a/b/c'); |
39 |
| - expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 47 | + describe('when navigating back to the root', function() { |
| 48 | + beforeEach(function() { |
| 49 | + URLStore.teardown(); |
40 | 50 |
|
41 |
| - URLStore.push('/d/e/f'); |
42 |
| - expect(URLStore.getCurrentPath()).toEqual('/d/e/f'); |
| 51 | + // simulating that the browser opens a page with #/dashboard |
| 52 | + window.location.hash = '/dashboard'; |
| 53 | + URLStore.setup('hash'); |
| 54 | + }); |
43 | 55 |
|
44 |
| - URLStore.back(); |
45 |
| - expect(URLStore.getCurrentPath()).toEqual('/a/b/c'); |
| 56 | + it('should have the correct path', function() { |
| 57 | + URLStore.push('/'); |
| 58 | + expect(window.location.hash).toEqual('#/'); |
| 59 | + }); |
46 | 60 | });
|
47 | 61 |
|
48 |
| - it('should not go back before recorded history', function () { |
49 |
| - var error = false; |
50 |
| - try { |
51 |
| - URLStore.back(); |
52 |
| - } catch (e) { |
53 |
| - error = true; |
54 |
| - } |
| 62 | + describe('when using history location handler', function() { |
| 63 | + itShouldManagePathsForLocation('history'); |
| 64 | + }); |
55 | 65 |
|
56 |
| - expect(error).toEqual(true); |
| 66 | + describe('when using memory location handler', function() { |
| 67 | + itShouldManagePathsForLocation('memory'); |
57 | 68 | });
|
58 |
| -}); |
59 | 69 |
|
60 |
| -describe('when navigating back to the root', function() { |
61 |
| - beforeEach(function () { |
62 |
| - // not all tests are constructing and tearing down the URLStore. |
63 |
| - // Let's set it up correctly once and then tear it down to ensure that all |
64 |
| - // variables in the URLStore module are reset. |
65 |
| - URLStore.setup('hash'); |
66 |
| - URLStore.teardown(); |
| 70 | + function itShouldManagePathsForLocation(location) { |
| 71 | + var origPath; |
67 | 72 |
|
68 |
| - // simulating that the browser opens a page with #/dashboard |
69 |
| - window.location.hash = '/dashboard'; |
70 |
| - URLStore.setup('hash'); |
71 |
| - }); |
| 73 | + beforeEach(function() { |
| 74 | + URLStore.teardown(); |
| 75 | + URLStore.setup(location); |
| 76 | + origPath = URLStore.getCurrentPath(); |
| 77 | + }); |
72 | 78 |
|
73 |
| - afterEach(function () { |
74 |
| - URLStore.teardown(); |
75 |
| - }); |
| 79 | + afterEach(function() { |
| 80 | + URLStore.push(origPath); |
| 81 | + expect(URLStore.getCurrentPath()).toEqual(origPath); |
| 82 | + }); |
| 83 | + |
| 84 | + it('should manage the path correctly', function() { |
| 85 | + URLStore.push('/test'); |
| 86 | + expect(URLStore.getCurrentPath()).toEqual('/test'); |
| 87 | + |
| 88 | + URLStore.push('/test/123'); |
| 89 | + expect(URLStore.getCurrentPath()).toEqual('/test/123'); |
| 90 | + |
| 91 | + URLStore.replace('/test/replaced'); |
| 92 | + expect(URLStore.getCurrentPath()).toEqual('/test/replaced'); |
| 93 | + |
| 94 | + URLStore.back(); |
| 95 | + expect(URLStore.getCurrentPath()).toEqual('/test'); |
| 96 | + |
| 97 | + }); |
| 98 | + } |
76 | 99 |
|
77 |
| - it('should have the correct path', function () { |
78 |
| - URLStore.push('/'); |
79 |
| - expect(window.location.hash).toEqual('#/'); |
80 |
| - }); |
81 | 100 | });
|
| 101 | + |
0 commit comments