diff --git a/test/e2e-cypress/tests/deep-linking.js b/test/e2e-cypress/tests/deep-linking.js index 58f3c2527a1..cbafe6d8588 100644 --- a/test/e2e-cypress/tests/deep-linking.js +++ b/test/e2e-cypress/tests/deep-linking.js @@ -1,79 +1,32 @@ 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) - }) + const swagger2BaseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.swagger.yaml" - it("should expand the operation when reloaded", () => { - cy.visit(`${baseUrl}${correctFragment}`) - .reload() - .get(`${elementToGet}.is-open`) - .should("exist") + describe("regular Operation", () => { + BaseDeeplinkTestFactory({ + baseUrl: swagger2BaseUrl, + elementToGet: ".opblock-get", + correctElementId: "operations-myTag-myOperation", + correctFragment: "#/myTag/myOperation", + correctHref: "#/myTag/myOperation" }) }) 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) + + BaseDeeplinkTestFactory({ + baseUrl: swagger2BaseUrl, + elementToGet, + correctElementId: "operations-my_Tag-my_Operation", + correctFragment: "#/my%20Tag/my%20Operation", + correctHref: "#/my%20Tag/my%20Operation" }) - 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") - }) + const legacyFragment = "#/my_Tag/my_Operation" it("should expand the operation when reloaded and provided the legacy fragment", () => { - cy.visit(`${baseUrl}${legacyFragment}`) + cy.visit(`${swagger2BaseUrl}${legacyFragment}`) .reload() .get(`${elementToGet}.is-open`) .should("exist") @@ -81,157 +34,58 @@ describe("Deep linking feature", () => { }) 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") + BaseDeeplinkTestFactory({ + baseUrl: swagger2BaseUrl, + elementToGet: ".opblock-patch", + correctElementId: "operations-underscore_Tag-underscore_Operation", + correctFragment: "#/underscore_Tag/underscore_Operation", + correctHref: "#/underscore_Tag/underscore_Operation" }) }) 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") + BaseDeeplinkTestFactory({ + baseUrl: swagger2BaseUrl, + elementToGet: ".opblock-head", + correctElementId: "operations-шеллы-пошел", + correctFragment: "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB", + correctHref: "#/шеллы/пошел" }) }) 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") + BaseDeeplinkTestFactory({ + baseUrl: swagger2BaseUrl, + elementToGet: ".opblock-put", + correctElementId: "operations-tagTwo-put_noOperationId", + correctFragment: "#/tagTwo/put_noOperationId", + correctHref: "#/tagTwo/put_noOperationId" }) }) describe("regular Operation with `docExpansion: none` enabled", function() { it("should expand a tag", () => { - cy.visit(`${baseUrl}&docExpansion=none#/myTag`) + cy.visit(`${swagger2BaseUrl}&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`) + cy.visit(`${swagger2BaseUrl}&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) - }) + const openAPI3BaseUrl = "/?deepLinking=true&url=/documents/features/deep-linking.openapi.yaml" - it("should expand the operation when reloaded", () => { - cy.visit(`${baseUrl}${correctFragment}`) - .reload() - .get(`${elementToGet}.is-open`) - .should("exist") + describe("regular Operation", () => { + BaseDeeplinkTestFactory({ + baseUrl: openAPI3BaseUrl, + elementToGet: ".opblock-get", + correctElementId: "operations-myTag-myOperation", + correctFragment: "#/myTag/myOperation", + correctHref: "#/myTag/myOperation" }) }) @@ -239,38 +93,19 @@ describe("Deep linking feature", () => { const elementToGet = ".opblock-post" const correctElementId = "operations-my_Tag-my_Operation" const correctFragment = "#/my%20Tag/my%20Operation" + + BaseDeeplinkTestFactory({ + baseUrl: openAPI3BaseUrl, + elementToGet: ".opblock-post", + correctElementId: "operations-my_Tag-my_Operation", + correctFragment: "#/my%20Tag/my%20Operation", + correctHref: "#/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}`) + cy.visit(`${openAPI3BaseUrl}${legacyFragment}`) .reload() .get(`${elementToGet}.is-open`) .should("exist") @@ -278,119 +113,78 @@ describe("Deep linking feature", () => { }) 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") + BaseDeeplinkTestFactory({ + baseUrl: openAPI3BaseUrl, + elementToGet: ".opblock-patch", + correctElementId: "operations-underscore_Tag-underscore_Operation", + correctFragment: "#/underscore_Tag/underscore_Operation", + correctHref: "#/underscore_Tag/underscore_Operation" }) }) 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") + BaseDeeplinkTestFactory({ + baseUrl: openAPI3BaseUrl, + elementToGet: ".opblock-head", + correctElementId: "operations-шеллы-пошел", + correctFragment: "#/%D1%88%D0%B5%D0%BB%D0%BB%D1%8B/%D0%BF%D0%BE%D1%88%D0%B5%D0%BB", + correctHref: "#/шеллы/пошел" }) }) 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") + BaseDeeplinkTestFactory({ + baseUrl: openAPI3BaseUrl, + elementToGet: ".opblock-put", + correctElementId: "operations-tagTwo-put_noOperationId", + correctFragment: "#/tagTwo/put_noOperationId", + correctHref: "#/tagTwo/put_noOperationId" }) }) describe("regular Operation with `docExpansion: none` enabled", function () { it("should expand a tag", () => { - cy.visit(`${baseUrl}&docExpansion=none#/myTag`) + cy.visit(`${openAPI3BaseUrl}&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`) + cy.visit(`${openAPI3BaseUrl}&docExpansion=none#/myTag/myOperation`) .get(`.opblock.is-open`) .should("have.length", 1) }) }) }) }) + +function BaseDeeplinkTestFactory({ baseUrl, elementToGet, correctElementId, correctFragment, correctHref }) { + it("should generate a correct element ID", () => { + cy.visit(baseUrl) + .get(elementToGet) + .should("have.id", correctElementId) + }) + + it("should add the correct element fragment to the URL when expanded", () => { + cy.visit(baseUrl) + .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.visit(baseUrl) + .get(elementToGet) + .find("a") + .should("have.attr", "href", correctHref) + .click() + .window() + .should("have.deep.property", "location.hash", correctFragment) + }) + + it("should expand the operation when reloaded", () => { + cy.visit(`${baseUrl}${correctFragment}`) + .get(`${elementToGet}.is-open`) + .should("exist") + }) +} \ No newline at end of file