From cd596b444ee953927cb6889509ac2fd3d51282e5 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Thu, 4 Nov 2021 16:54:25 +0100 Subject: [PATCH] v9: Implemented new routing tests (#11571) * Implemented new routing tests * Update package-lock.json * Cleanup * Updated routing to cleanup before and after tests Co-authored-by: Nikolaj Geisle Co-authored-by: Elitsa Marinovska --- .../cypress/integration/Content/routing.ts | 369 ++++++++++++++++++ .../package-lock.json | 6 +- .../Umbraco.Tests.AcceptanceTest/package.json | 2 +- 3 files changed, 373 insertions(+), 4 deletions(-) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Content/routing.ts diff --git a/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Content/routing.ts b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Content/routing.ts new file mode 100644 index 0000000000..4165624caa --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Content/routing.ts @@ -0,0 +1,369 @@ +/// +import { + DocumentTypeBuilder, + ContentBuilder +} from 'umbraco-cypress-testhelpers'; + +context('Routing', () => { + + let swedishLanguageId = 0; + const swedishCulture = "sv"; + const danishCulture = "da" + const nodeName = "Root"; + const childNodeName = "Child"; + const grandChildNodeName = "Grandchild"; + const rootDocTypeName = "Test document type"; + + function refreshContentTree() { + // Refresh to update the tree + cy.get('li .umb-tree-root:contains("Content")').should("be.visible").rightclick(); + cy.umbracoContextMenuAction("action-refreshNode").click(); + // We have to wait in case the execution is slow, otherwise we'll try and click the item before it appears in the UI + cy.get('.umb-tree-item__inner').should('exist', {timeout: 10000}); + } + + function saveNewLanguages() { + // Save Danish + const url = "/umbraco/backoffice/umbracoapi/language/SaveLanguage"; + const danishRequestBody = { + culture: danishCulture + } + + cy.umbracoApiRequest(url, "POST", danishRequestBody); + + // Save Swedish + const swedishRequestBody = { + culture: swedishCulture + } + cy.umbracoApiRequest(url, "POST", swedishRequestBody).then((responseBody) => { + swedishLanguageId = responseBody["id"]; + }); + } + + function configureDomain(id, name, lang) { + //Save domain for child node + const url = "/umbraco/backoffice/umbracoapi/content/PostSaveLanguageAndDomains" + const body = { + nodeId : id, + domains : [ + { + name : name, + lang : lang + }], + language : 0 + } + cy.umbracoApiRequest(url, 'POST', body); + } + + beforeEach(() => { + cy.umbracoLogin(Cypress.env('username'), Cypress.env('password')); + cy.umbracoEnsureLanguageNotExists(danishCulture); + cy.umbracoEnsureLanguageNotExists(swedishCulture); + }); + + afterEach(() => { + cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName); + cy.umbracoEnsureLanguageNotExists(danishCulture); + cy.umbracoEnsureLanguageNotExists(swedishCulture); + }) + + it('Root node published in language A, Child node published in language A', () => { + + const rootDocType = new DocumentTypeBuilder() + .withName(rootDocTypeName) + .withAllowAsRoot(true) + .withAllowCultureVariation(true) + .build(); + + cy.deleteAllContent(); + cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName); + + saveNewLanguages(); + + cy.saveDocumentType(rootDocType).then((generatedRootDocType) => { + const rootContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("publishNew") + .addVariant() + .withCulture('en-US') + .withName(nodeName) + .withSave(true) + .withPublish(true) + .done() + .build(); + + cy.saveContent(rootContentNode).then((generatedRootContent) => { + const childContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedRootContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(childNodeName) + .withSave(true) + .done() + .build(); + + cy.saveContent(childContentNode); + }); + }); + + // Refresh to update the tree + refreshContentTree(); + + cy.umbracoTreeItem("content", [nodeName, childNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + // Pop-up with what cultures you want to publish shows, click it + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Assert + cy.get('.alert-success').should('exist'); + }); + + + it('Root node published in language A, Child node published in language B', () => { + + const rootDocType = new DocumentTypeBuilder() + .withName(rootDocTypeName) + .withAllowAsRoot(true) + .withAllowCultureVariation(true) + .build(); + + cy.deleteAllContent(); + cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName); + + saveNewLanguages(); + + cy.saveDocumentType(rootDocType).then((generatedRootDocType) => { + const rootContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("publishNew") + .addVariant() + .withCulture('en-US') + .withName(nodeName) + .withSave(true) + .withPublish(true) + .done() + .build(); + + cy.saveContent(rootContentNode).then((generatedRootContent) => { + const childContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedRootContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(childNodeName) + .withSave(true) + .done() + .addVariant() + .withCulture(swedishCulture) + .withName("Bärn") + .withSave(true) + .done() + .build(); + + cy.saveContent(childContentNode); + }); + }); + + // Refresh to update the tree + refreshContentTree(); + + cy.umbracoTreeItem("content", [nodeName, childNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + // Pop-up with what cultures you want to publish shows, click it + cy.get('.umb-list').contains("Swedish").click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Assert + cy.get('.alert-success').should('have.length', 2); + cy.get('.alert-warning').should('exist'); + }); + + it('Root node published in language A, Child node published in language A + B, Grandchild published in A + B', () => { + + const rootDocType = new DocumentTypeBuilder() + .withName(rootDocTypeName) + .withAllowAsRoot(true) + .withAllowCultureVariation(true) + .build(); + + cy.deleteAllContent(); + cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName); + + saveNewLanguages(); + + cy.saveDocumentType(rootDocType).then((generatedRootDocType) => { + const rootContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("publishNew") + .addVariant() + .withCulture('en-US') + .withName(nodeName) + .withSave(true) + .withPublish(true) + .done() + .build(); + + cy.saveContent(rootContentNode).then((generatedRootContent) => { + + configureDomain(generatedRootContent["id"], "/en", 1); + const childContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedRootContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(childNodeName) + .withSave(true) + .done() + .addVariant() + .withCulture(swedishCulture) + .withName("Barn") + .withSave(true) + .done() + .build(); + + cy.saveContent(childContentNode).then((generatedChildContent) => { + + configureDomain(generatedChildContent["id"], "/sv", swedishLanguageId); + const grandChildContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedChildContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(grandChildNodeName) + .withSave(true) + .done() + .addVariant() + .withCulture(swedishCulture) + .withName("Barnbarn") + .withSave(true) + .done() + .build(); + + cy.saveContent(grandChildContentNode); + }); + }); + }); + + // Refresh to update the tree + refreshContentTree(); + + // Publish Child + cy.umbracoTreeItem("content", [nodeName, childNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + //Pop-up with what cultures you want to publish shows, click it + cy.get('.umb-list').contains("Swedish").click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Publish Grandchild + cy.umbracoTreeItem("content", [nodeName, childNodeName, grandChildNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + // Pop-up with what cultures you want to publish shows, click it + cy.get('.umb-list').contains("Swedish").click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Assert + cy.get('.alert-success').should('have.length', 2); + cy.get('.alert-warning').should('not.exist'); + }); + + it('Root node published in language A, Child node published in language A + B, Grandchild published in A + B + C', () => { + + const rootDocType = new DocumentTypeBuilder() + .withName(rootDocTypeName) + .withAllowAsRoot(true) + .withAllowCultureVariation(true) + .build(); + + cy.deleteAllContent(); + cy.umbracoEnsureDocumentTypeNameNotExists(rootDocTypeName); + + saveNewLanguages(); + + cy.saveDocumentType(rootDocType).then((generatedRootDocType) => { + const rootContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("publishNew") + .addVariant() + .withCulture('en-US') + .withName(nodeName) + .withSave(true) + .withPublish(true) + .done() + .build(); + + cy.saveContent(rootContentNode).then((generatedRootContent) => { + + configureDomain(generatedRootContent["id"], "/en", 1); + const childContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedRootContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(childNodeName) + .withSave(true) + .done() + .addVariant() + .withCulture(swedishCulture) + .withName("Barn") + .withSave(true) + .done() + .build(); + + cy.saveContent(childContentNode).then((generatedChildContent) => { + + configureDomain(generatedChildContent["id"], "/sv", swedishLanguageId); + const grandChildContentNode = new ContentBuilder() + .withContentTypeAlias(generatedRootDocType["alias"]) + .withAction("saveNew") + .withParent(generatedChildContent["id"]) + .addVariant() + .withCulture('en-US') + .withName(grandChildNodeName) + .withSave(true) + .done() + .addVariant() + .withCulture(swedishCulture) + .withName("Barnbarn") + .withSave(true) + .done() + .addVariant() + .withCulture(danishCulture) + .withName("Barnebarn") + .withSave(true) + .done() + .build(); + + cy.saveContent(grandChildContentNode); + }); + }); + }); + + // Refresh to update the tree + refreshContentTree(); + + // Publish Child + cy.umbracoTreeItem("content", [nodeName, childNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + // Pop-up with what cultures you want to publish shows, click it + cy.get('.umb-list').contains("Swedish").click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Publish Grandchild + cy.umbracoTreeItem("content", [nodeName, childNodeName, grandChildNodeName]).click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click(); + // Pop-up with what cultures you want to publish shows, click it + cy.get('.umb-list').contains("Swedish").click(); + cy.get('.umb-list').contains("Danish").click(); + cy.umbracoButtonByLabelKey('buttons_saveAndPublish').last().click(); + + // Assert + cy.get('.alert-success').should('exist'); + cy.get('.alert-warning').should('exist'); + }); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/package-lock.json b/tests/Umbraco.Tests.AcceptanceTest/package-lock.json index 6b605bfbb9..2019dfacd8 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/package-lock.json +++ b/tests/Umbraco.Tests.AcceptanceTest/package-lock.json @@ -1622,9 +1622,9 @@ "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==" }, "umbraco-cypress-testhelpers": { - "version": "1.0.0-beta-60", - "resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-60.tgz", - "integrity": "sha512-VEe6r7G9nBwtATxAZPFOY4utCpsmKV8oK5FbPV4TrEyMH08hmAYmEq+w84Bq1Q85khG01ivyMCR/8sYUEHTWIg==", + "version": "1.0.0-beta-61", + "resolved": "https://registry.npmjs.org/umbraco-cypress-testhelpers/-/umbraco-cypress-testhelpers-1.0.0-beta-61.tgz", + "integrity": "sha512-WhOQ5foSWUdO3Vb3vGu6VAEWhncY13QGL323hPTMeVR3dqQd2uUExp7ppOBKYYgWHwjCvJbo0OMGGZMJyfoAPA==", "dev": true, "requires": { "camelize": "^1.0.0", diff --git a/tests/Umbraco.Tests.AcceptanceTest/package.json b/tests/Umbraco.Tests.AcceptanceTest/package.json index 3b9b2864e1..cb7253f273 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/package.json +++ b/tests/Umbraco.Tests.AcceptanceTest/package.json @@ -13,7 +13,7 @@ "del": "^6.0.0", "ncp": "^2.0.0", "prompt": "^1.2.0", - "umbraco-cypress-testhelpers": "^1.0.0-beta-60" + "umbraco-cypress-testhelpers": "^1.0.0-beta-61" }, "dependencies": { "typescript": "^3.9.2"