Skip to content

Commit 3df9fad

Browse files
authored
improve: deeplinking behavior (#4960)
* add passing tests for fragment rewriting * add failing fragment retention tests * fire legacy `show` actions before standard ones * skip failing tests * remove extra line
1 parent 505d056 commit 3df9fad

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/core/plugins/deep-linking/layout.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,22 +77,21 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
7777

7878
const isShownKey = layoutSelectors.isShownKeyFromUrlHashArray(hashArray)
7979

80-
const [type, tagId, maybeOperationId] = isShownKey
80+
const [type, tagId = "", maybeOperationId = ""] = isShownKey
8181

8282
if(type === "operations") {
8383
// we're going to show an operation, so we need to expand the tag as well
8484
const tagIsShownKey = layoutSelectors.isShownKeyFromUrlHashArray([tagId])
85-
layoutActions.show(tagIsShownKey)
8685

8786
// If an `_` is present, trigger the legacy escaping behavior to be safe
8887
// TODO: remove this in v4.0, it is deprecated
8988
if(tagId.indexOf("_") > -1) {
9089
console.warn("Warning: escaping deep link whitespace with `_` will be unsupported in v4.0, use `%20` instead.")
9190
layoutActions.show(tagIsShownKey.map(val => val.replace(/_/g, " ")), true)
9291
}
93-
}
9492

95-
layoutActions.show(isShownKey, true)
93+
layoutActions.show(tagIsShownKey, true)
94+
}
9695

9796
// If an `_` is present, trigger the legacy escaping behavior to be safe
9897
// TODO: remove this in v4.0, it is deprecated
@@ -101,6 +100,8 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
101100
layoutActions.show(isShownKey.map(val => val.replace(/_/g, " ")), true)
102101
}
103102

103+
layoutActions.show(isShownKey, true)
104+
104105
// Scroll to the newly expanded entity
105106
layoutActions.scrollTo(isShownKey)
106107
}

test/e2e-cypress/tests/deep-linking.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ describe("Deep linking feature", () => {
1414

1515
describe("Operation with whitespace in tag+id", () => {
1616
const elementToGet = ".opblock-post"
17+
const correctFragment = "#/my%20Tag/my%20Operation"
1718

1819
BaseDeeplinkTestFactory({
1920
baseUrl: swagger2BaseUrl,
2021
elementToGet,
2122
correctElementId: "operations-my_Tag-my_Operation",
22-
correctFragment: "#/my%20Tag/my%20Operation",
23+
correctFragment,
2324
correctHref: "#/my%20Tag/my%20Operation"
2425
})
2526

@@ -31,6 +32,13 @@ describe("Deep linking feature", () => {
3132
.get(`${elementToGet}.is-open`)
3233
.should("exist")
3334
})
35+
36+
it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
37+
cy.visit(`${swagger2BaseUrl}${legacyFragment}`)
38+
.reload()
39+
.window()
40+
.should("have.deep.property", "location.hash", correctFragment)
41+
})
3442
})
3543

3644
describe("Operation with underscores in tag+id", () => {
@@ -91,14 +99,13 @@ describe("Deep linking feature", () => {
9199

92100
describe("Operation with whitespace in tag+id", () => {
93101
const elementToGet = ".opblock-post"
94-
const correctElementId = "operations-my_Tag-my_Operation"
95102
const correctFragment = "#/my%20Tag/my%20Operation"
96103

97104
BaseDeeplinkTestFactory({
98105
baseUrl: openAPI3BaseUrl,
99106
elementToGet: ".opblock-post",
100107
correctElementId: "operations-my_Tag-my_Operation",
101-
correctFragment: "#/my%20Tag/my%20Operation",
108+
correctFragment,
102109
correctHref: "#/my%20Tag/my%20Operation"
103110
})
104111

@@ -110,6 +117,14 @@ describe("Deep linking feature", () => {
110117
.get(`${elementToGet}.is-open`)
111118
.should("exist")
112119
})
120+
121+
122+
it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
123+
cy.visit(`${openAPI3BaseUrl}${legacyFragment}`)
124+
.reload()
125+
.window()
126+
.should("have.deep.property", "location.hash", correctFragment)
127+
})
113128
})
114129

115130
describe("Operation with underscores in tag+id", () => {
@@ -187,4 +202,12 @@ function BaseDeeplinkTestFactory({ baseUrl, elementToGet, correctElementId, corr
187202
.get(`${elementToGet}.is-open`)
188203
.should("exist")
189204
})
205+
206+
it("should retain the correct fragment when reloaded", () => {
207+
cy.visit(`${baseUrl}${correctFragment}`)
208+
.reload()
209+
.should("exist")
210+
.window()
211+
.should("have.deep.property", "location.hash", correctFragment)
212+
})
190213
}

0 commit comments

Comments
 (0)