1
+ require 'spec_helper'
2
+
3
+
4
+ steps 'Test basic behavior' , :js => true do
5
+
6
+ before ( :each ) do # only executed once before all "it" blocks (see https://github.com/LRDesign/rspec-steps)
7
+ visit root_path ( ajaxify_on : true )
8
+ @layout_id = find ( 'body' ) [ 'data-id' ]
9
+ end
10
+
11
+ it "should display loader" do
12
+ click_on 'Page 1'
13
+ page . should have_css ( ".ajaxify_loader" )
14
+ end
15
+
16
+ it "should load page's content" do
17
+ should_have_content 'Page 1 Content'
18
+ push_state_path_should_be '/home/page1'
19
+ ensure_layout_not_reloaded
20
+ end
21
+
22
+ it "should redirect" do
23
+ click_on 'Page 3 (redirects to page 1)'
24
+ should_have_content 'Page 1 Content'
25
+ push_state_path_should_be '/home/page1'
26
+ ensure_layout_not_reloaded
27
+ end
28
+
29
+ it "should display flash" do
30
+ should_have_notice 'Redirected to Page 1'
31
+ end
32
+
33
+ it "should submit a form" do
34
+ click_on 'Page 2'
35
+ fill_in 'input1' , with : 'test'
36
+ check 'check_me'
37
+ push_state_path_should_be '/home/page2'
38
+ click_button 'Submit me'
39
+ should_have_notice 'Form submitted (test, , 1)'
40
+ ensure_layout_not_reloaded
41
+ end
42
+
43
+ it "should load previous content when clicking the browser back button" do
44
+ click_on 'Home'
45
+ wait_for_ajaxify_loaded
46
+ click_on 'Page 1'
47
+ wait_for_ajaxify_loaded
48
+ click_browser_back_button
49
+ should_have_content 'Home Content'
50
+ push_state_path_should_be '/'
51
+ ensure_layout_not_reloaded
52
+ end
53
+
54
+ it "should load next content when clicking the browser forward button" do
55
+ click_browser_forward_button
56
+ should_have_content 'Page 1 Content'
57
+ push_state_path_should_be '/home/page1'
58
+ ensure_layout_not_reloaded
59
+ end
60
+
61
+ it "should not repost form clicking the browser back button" do
62
+ click_on 'Page 2'
63
+ click_button 'Submit me'
64
+ wait_for_ajaxify_loaded
65
+ click_on 'Page 1'
66
+ wait_for_ajaxify_loaded
67
+ click_browser_back_button
68
+ wait_for_ajaxify_loaded
69
+ page . should_not have_css ( "#notice" , visible : true )
70
+ should_have_content /A Form/
71
+ push_state_path_should_be '/home/page2'
72
+ end
73
+
74
+ end
75
+
76
+
77
+ steps 'Test hash based url scheme for browsers without pushState' , :js => true do
78
+
79
+ before ( :each ) do # only executed once before all "it" blocks (see https://github.com/LRDesign/rspec-steps)
80
+ visit root_path ( ajaxify_on : true , push_state_enabled : false )
81
+ @layout_id = find ( 'body' ) [ 'data-id' ]
82
+ #sleep 2 # poltergeist needs this
83
+ hash_path_should_be '/?ajaxify_on=true&push_state_enabled=false'
84
+ end
85
+
86
+ it "should display loader" do
87
+ click_on 'Page 1'
88
+ page . should have_css ( ".ajaxify_loader" )
89
+ end
90
+
91
+ it "should load page's content" do
92
+ should_have_content 'Page 1 Content'
93
+ hash_path_should_be '/home/page1'
94
+ ensure_layout_not_reloaded
95
+ end
96
+
97
+ it "should redirect" do
98
+ click_on 'Page 3 (redirects to page 1)'
99
+ should_have_content 'Page 1 Content'
100
+ hash_path_should_be '/home/page1'
101
+ ensure_layout_not_reloaded
102
+ end
103
+
104
+ it "should display flash" do
105
+ should_have_notice 'Redirected to Page 1'
106
+ end
107
+
108
+ it "should submit a form" do
109
+ click_on 'Page 2'
110
+ fill_in 'input1' , with : 'test'
111
+ check 'check_me'
112
+ hash_path_should_be '/home/page2'
113
+ click_button 'Submit me'
114
+ should_have_notice 'Form submitted (test, , 1)'
115
+ ensure_layout_not_reloaded
116
+ end
117
+
118
+ it "should load previous content when clicking the browser back button" do
119
+ click_on 'Home'
120
+ wait_for_ajaxify_loaded
121
+ click_on 'Page 1'
122
+ wait_for_ajaxify_loaded
123
+ click_browser_back_button
124
+ should_have_content 'Home Content'
125
+ hash_path_should_be '/'
126
+ ensure_layout_not_reloaded
127
+ end
128
+
129
+ it "should load next content when clicking the browser forward button" do
130
+ click_browser_forward_button
131
+ should_have_content 'Page 1 Content'
132
+ hash_path_should_be '/home/page1'
133
+ ensure_layout_not_reloaded
134
+ end
135
+
136
+ it "should not repost form clicking the browser back button" do
137
+ click_on 'Page 2'
138
+ click_button 'Submit me'
139
+ wait_for_ajaxify_loaded
140
+ click_on 'Page 1'
141
+ wait_for_ajaxify_loaded
142
+ click_browser_back_button
143
+ wait_for_ajaxify_loaded
144
+ page . should_not have_css ( "#notice" , visible : true )
145
+ should_have_content /A Form/
146
+ hash_path_should_be '/home/page2'
147
+ end
148
+
149
+ end
150
+
151
+
152
+ describe 'Test convert urls' , :js => true do
153
+
154
+ it 'should convert a hash url to a proper one in a browser supporting pushState' do
155
+ visit root_path ( ajaxify_on : true , anchor : '/home/page1' )
156
+ should_have_content 'Page 1 Content'
157
+ push_state_path_should_be '/home/page1'
158
+ end
159
+
160
+ it 'should convert a proper url to a hash url in a browser not supporting pushState' do
161
+ visit '/home/page1?ajaxify_on=true&push_state_enabled=false'
162
+ should_have_content 'Page 1 Content'
163
+ hash_path_should_be '/home/page1?ajaxify_on=true&push_state_enabled=false'
164
+ end
165
+
166
+ end
0 commit comments