Files
swagger-ui/test/e2e-cypress/tests/deep-linking.js
James ZHANG 1791759de5 improve(deeplink): support utf16 tags and IDs (via #4921)
* ref #3958, support utf16 fragments on the deeplink plugin
* put -> head for UTF16 operation
this is a temporary fix, eventually we will run out
of methods and need to use a new targeting strategy
* drop obsolete %20 decoder
* add full test suite for UTF16 operation
* use encodeURIComponent when setting hash
* drop obsolete test cases
2018-10-18 16:55:30 -05:00

397 lines
13 KiB
JavaScript

describe("Deep linking feature", () => {
describe("in Swagger 2", () => {
const baseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.swagger.yaml"
beforeEach(() => {
cy.visit(baseUrl)
})
describe("regular Operation", () => {
const elementToGet = ".opblock-get"
const correctElementId = "operations-myTag-myOperation"
const correctFragment = "#/myTag/myOperation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with whitespace in tag+id", () => {
const elementToGet = ".opblock-post"
const correctElementId = "operations-my_Tag-my_Operation"
const correctFragment = "#/my%20Tag/my%20Operation"
const legacyFragment = "#/my_Tag/my_Operation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
it("should expand the operation when reloaded and provided the legacy fragment", () => {
cy.visit(`${baseUrl}${legacyFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with underscores in tag+id", () => {
const elementToGet = ".opblock-patch"
const correctElementId = "operations-underscore_Tag-underscore_Operation"
const correctFragment = "#/underscore_Tag/underscore_Operation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with UTF-16 characters", () => {
const elementToGet = ".opblock-head"
const correctElementId = "operations-шеллы-пошел"
const correctFragment = "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB"
const correctHref = "#/шеллы/пошел"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctHref)
.click()
.should("have.attr", "href", correctHref) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with no operationId", () => {
const elementToGet = ".opblock-put"
const correctElementId = "operations-tagTwo-put_noOperationId"
const correctFragment = "#/tagTwo/put_noOperationId"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("regular Operation with `docExpansion: none` enabled", function() {
it("should expand a tag", () => {
cy.visit(`${baseUrl}&docExpansion=none#/myTag`)
.get(`.opblock-tag-section.is-open`)
.should("have.length", 1)
})
it("should expand an operation", () => {
cy.visit(`${baseUrl}&docExpansion=none#/myTag/myOperation`)
.get(`.opblock.is-open`)
.should("have.length", 1)
})
})
})
describe("in OpenAPI 3", () => {
const baseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.openapi.yaml"
beforeEach(() => {
cy.visit(baseUrl)
})
describe("regular Operation", () => {
const elementToGet = ".opblock-get"
const correctElementId = "operations-myTag-myOperation"
const correctFragment = "#/myTag/myOperation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with whitespace in tag+id", () => {
const elementToGet = ".opblock-post"
const correctElementId = "operations-my_Tag-my_Operation"
const correctFragment = "#/my%20Tag/my%20Operation"
const legacyFragment = "#/my_Tag/my_Operation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
it("should expand the operation when reloaded and provided the legacy fragment", () => {
cy.visit(`${baseUrl}${legacyFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with underscores in tag+id", () => {
const elementToGet = ".opblock-patch"
const correctElementId = "operations-underscore_Tag-underscore_Operation"
const correctFragment = "#/underscore_Tag/underscore_Operation"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with UTF-16 characters", () => {
const elementToGet = ".opblock-head"
const correctElementId = "operations-шеллы-пошел"
const correctFragment = "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB"
const correctHref = "#/шеллы/пошел"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctHref)
.click()
.should("have.attr", "href", correctHref) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("Operation with no operationId", () => {
const elementToGet = ".opblock-put"
const correctElementId = "operations-tagTwo-put_noOperationId"
const correctFragment = "#/tagTwo/put_noOperationId"
it("should generate a correct element ID", () => {
cy.get(elementToGet)
.should("have.id", correctElementId)
})
it("should add the correct element fragment to the URL when expanded", () => {
cy.get(elementToGet)
.click()
.window()
.should("have.deep.property", "location.hash", correctFragment)
})
it("should provide an anchor link that has the correct fragment as href", () => {
cy.get(elementToGet)
.find("a")
.should("have.attr", "href", correctFragment)
.click()
.should("have.attr", "href", correctFragment) // should be valid after expanding
})
it("should expand the operation when reloaded", () => {
cy.visit(`${baseUrl}${correctFragment}`)
.reload()
.get(`${elementToGet}.is-open`)
.should("exist")
})
})
describe("regular Operation with `docExpansion: none` enabled", function () {
it("should expand a tag", () => {
cy.visit(`${baseUrl}&docExpansion=none#/myTag`)
.get(`.opblock-tag-section.is-open`)
.should("have.length", 1)
})
it("should expand an operation", () => {
cy.visit(`${baseUrl}&docExpansion=none#/myTag/myOperation`)
.get(`.opblock.is-open`)
.should("have.length", 1)
})
})
})
})