Skip to content

Commit 6b352e9

Browse files
committed
implemented feedback, moved logic out of app.js, fixed potential flaky test
1 parent 51b2798 commit 6b352e9

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from 'vue/dist/vue.esm'
22
import VRuntimeTemplate from "v-runtime-template"
33
import Vuex from 'vuex'
4+
import isNavigatingToAnotherPage from "./location"
45

56
const componentDef = {
67
props: ['appConfig', 'params'],
@@ -16,11 +17,11 @@ const componentDef = {
1617
mounted: function(){
1718
const self = this;
1819
window.onpopstate = (event) => {
19-
let needToNavigate = self.currentPathName !== document.location.pathname ||
20-
self.currentOrigin !== document.location.origin ||
21-
self.currentSearch !== document.location.search
22-
23-
if (needToNavigate){
20+
if (isNavigatingToAnotherPage({
21+
origin: self.currentOrigin,
22+
pathName: self.currentPathName,
23+
search: self.currentSearch
24+
}, document.location)){
2425
self.$store.dispatch("navigateTo", {url: document.location.pathname, backwards: true} );
2526
}
2627
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const isNavigatingToAnotherPage = function(currentLocation, targetLocation) {
2+
3+
// omits hash by design
4+
return currentLocation.pathName !== targetLocation.pathname ||
5+
currentLocation.origin !== targetLocation.origin ||
6+
currentLocation.search !== targetLocation.search
7+
}
8+
9+
export default isNavigatingToAnotherPage

spec/usage/components/transition_spec.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,13 @@ def page2
141141
expect(page).to have_content("This is Page 2")
142142
expect(page).to have_selector("body.not-reloaded")
143143

144-
# page.evaluate_script('window.history.back()')
145144
page.go_back
146145

147-
element = page.find("#my-div-on-page-1")
148-
refreshed_content_on_page_1 = element.text
149-
150146
expect(page).to have_content("My Example App Layout")
151147
expect(page).to have_content("This is Page 1")
152148
expect(page).not_to have_content("This is Page 2")
153149
expect(page).to have_selector("body.not-reloaded")
154-
155-
expect(first_content_on_page_1).not_to eq(refreshed_content_on_page_1)
150+
expect(page).to have_no_content(first_content_on_page_1)
156151
end
157152

158153
# supposed to work, but doesn't. Suspect Vue is the culprint here

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

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

vendor/assets/javascripts/dist/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)