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
This commit is contained in:
@@ -77,12 +77,11 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
|
|||||||
|
|
||||||
const isShownKey = layoutSelectors.isShownKeyFromUrlHashArray(hashArray)
|
const isShownKey = layoutSelectors.isShownKeyFromUrlHashArray(hashArray)
|
||||||
|
|
||||||
const [type, tagId, maybeOperationId] = isShownKey
|
const [type, tagId = "", maybeOperationId = ""] = isShownKey
|
||||||
|
|
||||||
if(type === "operations") {
|
if(type === "operations") {
|
||||||
// we're going to show an operation, so we need to expand the tag as well
|
// we're going to show an operation, so we need to expand the tag as well
|
||||||
const tagIsShownKey = layoutSelectors.isShownKeyFromUrlHashArray([tagId])
|
const tagIsShownKey = layoutSelectors.isShownKeyFromUrlHashArray([tagId])
|
||||||
layoutActions.show(tagIsShownKey)
|
|
||||||
|
|
||||||
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
||||||
// TODO: remove this in v4.0, it is deprecated
|
// TODO: remove this in v4.0, it is deprecated
|
||||||
@@ -90,9 +89,9 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
|
|||||||
console.warn("Warning: escaping deep link whitespace with `_` will be unsupported in v4.0, use `%20` instead.")
|
console.warn("Warning: escaping deep link whitespace with `_` will be unsupported in v4.0, use `%20` instead.")
|
||||||
layoutActions.show(tagIsShownKey.map(val => val.replace(/_/g, " ")), true)
|
layoutActions.show(tagIsShownKey.map(val => val.replace(/_/g, " ")), true)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
layoutActions.show(isShownKey, true)
|
layoutActions.show(tagIsShownKey, true)
|
||||||
|
}
|
||||||
|
|
||||||
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
||||||
// TODO: remove this in v4.0, it is deprecated
|
// TODO: remove this in v4.0, it is deprecated
|
||||||
@@ -101,6 +100,8 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
|
|||||||
layoutActions.show(isShownKey.map(val => val.replace(/_/g, " ")), true)
|
layoutActions.show(isShownKey.map(val => val.replace(/_/g, " ")), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layoutActions.show(isShownKey, true)
|
||||||
|
|
||||||
// Scroll to the newly expanded entity
|
// Scroll to the newly expanded entity
|
||||||
layoutActions.scrollTo(isShownKey)
|
layoutActions.scrollTo(isShownKey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,13 @@ describe("Deep linking feature", () => {
|
|||||||
|
|
||||||
describe("Operation with whitespace in tag+id", () => {
|
describe("Operation with whitespace in tag+id", () => {
|
||||||
const elementToGet = ".opblock-post"
|
const elementToGet = ".opblock-post"
|
||||||
|
const correctFragment = "#/my%20Tag/my%20Operation"
|
||||||
|
|
||||||
BaseDeeplinkTestFactory({
|
BaseDeeplinkTestFactory({
|
||||||
baseUrl: swagger2BaseUrl,
|
baseUrl: swagger2BaseUrl,
|
||||||
elementToGet,
|
elementToGet,
|
||||||
correctElementId: "operations-my_Tag-my_Operation",
|
correctElementId: "operations-my_Tag-my_Operation",
|
||||||
correctFragment: "#/my%20Tag/my%20Operation",
|
correctFragment,
|
||||||
correctHref: "#/my%20Tag/my%20Operation"
|
correctHref: "#/my%20Tag/my%20Operation"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -31,6 +32,13 @@ describe("Deep linking feature", () => {
|
|||||||
.get(`${elementToGet}.is-open`)
|
.get(`${elementToGet}.is-open`)
|
||||||
.should("exist")
|
.should("exist")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
|
||||||
|
cy.visit(`${swagger2BaseUrl}${legacyFragment}`)
|
||||||
|
.reload()
|
||||||
|
.window()
|
||||||
|
.should("have.deep.property", "location.hash", correctFragment)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Operation with underscores in tag+id", () => {
|
describe("Operation with underscores in tag+id", () => {
|
||||||
@@ -91,14 +99,13 @@ describe("Deep linking feature", () => {
|
|||||||
|
|
||||||
describe("Operation with whitespace in tag+id", () => {
|
describe("Operation with whitespace in tag+id", () => {
|
||||||
const elementToGet = ".opblock-post"
|
const elementToGet = ".opblock-post"
|
||||||
const correctElementId = "operations-my_Tag-my_Operation"
|
|
||||||
const correctFragment = "#/my%20Tag/my%20Operation"
|
const correctFragment = "#/my%20Tag/my%20Operation"
|
||||||
|
|
||||||
BaseDeeplinkTestFactory({
|
BaseDeeplinkTestFactory({
|
||||||
baseUrl: openAPI3BaseUrl,
|
baseUrl: openAPI3BaseUrl,
|
||||||
elementToGet: ".opblock-post",
|
elementToGet: ".opblock-post",
|
||||||
correctElementId: "operations-my_Tag-my_Operation",
|
correctElementId: "operations-my_Tag-my_Operation",
|
||||||
correctFragment: "#/my%20Tag/my%20Operation",
|
correctFragment,
|
||||||
correctHref: "#/my%20Tag/my%20Operation"
|
correctHref: "#/my%20Tag/my%20Operation"
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -110,6 +117,14 @@ describe("Deep linking feature", () => {
|
|||||||
.get(`${elementToGet}.is-open`)
|
.get(`${elementToGet}.is-open`)
|
||||||
.should("exist")
|
.should("exist")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
it.skip("should rewrite to the correct fragment when provided the legacy fragment", () => {
|
||||||
|
cy.visit(`${openAPI3BaseUrl}${legacyFragment}`)
|
||||||
|
.reload()
|
||||||
|
.window()
|
||||||
|
.should("have.deep.property", "location.hash", correctFragment)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Operation with underscores in tag+id", () => {
|
describe("Operation with underscores in tag+id", () => {
|
||||||
@@ -187,4 +202,12 @@ function BaseDeeplinkTestFactory({ baseUrl, elementToGet, correctElementId, corr
|
|||||||
.get(`${elementToGet}.is-open`)
|
.get(`${elementToGet}.is-open`)
|
||||||
.should("exist")
|
.should("exist")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should retain the correct fragment when reloaded", () => {
|
||||||
|
cy.visit(`${baseUrl}${correctFragment}`)
|
||||||
|
.reload()
|
||||||
|
.should("exist")
|
||||||
|
.window()
|
||||||
|
.should("have.deep.property", "location.hash", correctFragment)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user