Skip to content

Commit 6a5003d

Browse files
committed
Test link navigation intact and some beautifications
1 parent ab399ea commit 6a5003d

File tree

4 files changed

+89
-47
lines changed

4 files changed

+89
-47
lines changed

app/concepts/matestack/ui/core/app/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const componentDef = {
1313
}),
1414
mounted: function(){
1515
window.onpopstate = (event) => {
16-
if (isNavigatingToAnotherPage(window.location, event)) {
16+
if (isNavigatingToAnotherPage(document.location, event)) {
1717
this.$store.dispatch("navigateTo", {url: document.location.pathname, backwards: true} );
1818
};
1919
}

spec/usage/components/link_spec.rb

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def response
197197
}
198198
end
199199
end
200+
200201
visit "/example"
201202

202203
element = page.find("#my-div")
@@ -208,7 +209,7 @@ def response
208209
page.click_link("my-link")
209210

210211
# if the page reloaded we'd have different content here but as we don't want reloads
211-
# we want the sime
212+
# we want the same
212213
expect(page).to have_css("#my-div", text: before_content)
213214
expect(page.current_url).to end_with("#someanchor")
214215
end
@@ -252,11 +253,12 @@ def response
252253
}
253254
end
254255

255-
# u so hacky
256+
# Hacky/instable but easy way to set my custom App for this page
256257
def set_app_class
257258
@app_class = Apps::MyTestApp
258259
end
259260
end
261+
260262
visit "/example"
261263

262264
element = page.find("#my-div")
@@ -268,9 +270,49 @@ def set_app_class
268270
page.click_link("my-link")
269271

270272
# if the page reloaded we'd have different content here but as we don't want reloads
271-
# we want the sime
273+
# we want the same
272274
expect(page).to have_css("#my-div", text: before_content)
273275
expect(page.current_url).to end_with("#someanchor")
274276
end
277+
278+
it "just changing the search string will still reload the page" do
279+
class Apps::MyTestApp < Matestack::Ui::App
280+
def response
281+
components {
282+
page_content
283+
}
284+
end
285+
end
286+
287+
class ExamplePage < Matestack::Ui::Page
288+
def response
289+
components {
290+
link path: "?a=true", text: "go to anchor", id: "my-link"
291+
292+
br times: 200
293+
294+
div id: "my-div" do
295+
plain "#{DateTime.now.strftime('%Q')}"
296+
end
297+
}
298+
end
299+
300+
# Hacky/instable but easy way to set my custom App for this page
301+
def set_app_class
302+
@app_class = Apps::MyTestApp
303+
end
304+
end
305+
306+
visit "/example"
307+
308+
element = page.find("#my-div")
309+
before_content = element.text
310+
311+
page.click_link("my-link")
312+
313+
expect(page).to have_css("#my-div")
314+
expect(page).to have_no_css("#my-div", text: before_content)
315+
expect(page.current_url).to end_with("?a=true")
316+
end
275317
end
276318
end

vendor/assets/javascripts/matestack-ui-core.js

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/assets/javascripts/matestack-ui-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)