Skip to content

Commit c667ee9

Browse files
committed
Initial working spec(s)
1 parent 8cd6fc1 commit c667ee9

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ group :development, :test do
2626
gem 'puma'
2727
gem 'simplecov', require: false, group: :test
2828
gem 'byebug'
29-
# gem 'pry-byebug'
29+
gem 'pry-byebug'
3030
gem 'webmock'
3131
gem 'webdrivers', '~> 4.1'
3232
end

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ GEM
8080
cells (>= 4.1.6, < 5.0.0)
8181
childprocess (0.9.0)
8282
ffi (~> 1.0, >= 1.0.11)
83+
coderay (1.1.2)
8384
concurrent-ruby (1.1.5)
8485
crack (0.4.3)
8586
safe_yaml (~> 1.0.0)
@@ -125,6 +126,12 @@ GEM
125126
nokogiri (1.10.5)
126127
mini_portile2 (~> 2.4.0)
127128
pipetree (0.1.1)
129+
pry (0.12.2)
130+
coderay (~> 1.1.0)
131+
method_source (~> 0.9.0)
132+
pry-byebug (3.8.0)
133+
byebug (~> 11.0)
134+
pry (~> 0.10)
128135
public_suffix (3.0.3)
129136
puma (4.3.1)
130137
nio4r (~> 2.0)
@@ -253,6 +260,7 @@ DEPENDENCIES
253260
cells-rails
254261
generator_spec
255262
matestack-ui-core!
263+
pry-byebug
256264
puma
257265
rspec-rails (~> 3.8)
258266
selenium-webdriver

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
Dir[File.join File.dirname(__FILE__), 'support', '**', '*.rb'].each { |f| require f }
3838

39+
require 'pry'
40+
3941
RSpec.configure do |config|
4042
# config.include Capybara::DSL
4143
# rspec-expectations config goes here. You can use an alternate

spec/usage/components/link_spec.rb

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,102 @@ def response
179179
expect(stripped(static_output)).to ( include(stripped(expected_static_output)) )
180180
end
181181

182+
it "behaves correctly with anchor links (no reload, retain anchor)" do
183+
class ExamplePage < Matestack::Ui::Page
184+
def response
185+
components {
186+
link path: "#someanchor", text: "go to anchor", id: "my-link"
187+
188+
br times: 200
189+
190+
div id: "someanchor" do
191+
plain "hello!"
192+
end
193+
194+
div id: "my-div" do
195+
plain "#{DateTime.now.strftime('%Q')}"
196+
end
197+
}
198+
end
199+
end
200+
visit "/example"
201+
202+
element = page.find("#my-div")
203+
before_content = element.text
204+
205+
# don't you rerender on me!
206+
expect(ExamplePage).not_to receive(:new)
207+
208+
page.click_link("my-link")
209+
210+
# if the page reloaded we'd have different content here but as we don't want reloads
211+
# we want the sime
212+
expect(page).to have_css("#my-div", text: before_content)
213+
expect(page.current_url).to end_with("#someanchor")
214+
end
215+
216+
describe "with an App" do
217+
218+
after :each do
219+
class ExamplePage < Matestack::Ui::Page
220+
# as the test suites work with redefining classes and this
221+
# hack here was used to set a specific app easily,
222+
# we need to "restore" previous state
223+
def set_app_class
224+
super
225+
end
226+
end
227+
end
228+
229+
it "behaves correctly with anchor links (no reload, retain anchor) even inside an app" do
230+
class Apps::MyTestApp < Matestack::Ui::App
231+
def response
232+
components {
233+
page_content
234+
}
235+
end
236+
end
237+
238+
class ExamplePage < Matestack::Ui::Page
239+
def response
240+
components {
241+
link path: "#someanchor", text: "go to anchor", id: "my-link"
242+
243+
br times: 200
244+
245+
div id: "someanchor" do
246+
plain "hello!"
247+
end
248+
249+
div id: "my-div" do
250+
plain "#{DateTime.now.strftime('%Q')}"
251+
end
252+
}
253+
end
254+
255+
# u so hacky
256+
def set_app_class
257+
@app_class = Apps::MyTestApp
258+
end
259+
end
260+
visit "/example"
261+
262+
element = page.find("#my-div")
263+
before_content = element.text
264+
265+
puts before_content
266+
267+
# don't you rerender on me!
268+
expect(ExamplePage).not_to receive(:new)
269+
270+
page.click_link("my-link")
271+
272+
# binding.pry
273+
274+
# if the page reloaded we'd have different content here but as we don't want reloads
275+
# we want the sime
276+
expect(page).to have_css("#my-div", text: before_content)
277+
expect(page.current_url).to end_with("#someanchor")
278+
end
279+
end
182280
end

0 commit comments

Comments
 (0)