From 4367e45b73d9d34451ccf9271ab31f63565da485 Mon Sep 17 00:00:00 2001 From: emma-hq <78740801+emma-hq@users.noreply.github.com> Date: Mon, 24 Oct 2022 07:45:06 +0200 Subject: [PATCH] Const adding for content tests (#13271) * Constant replacing string SaveNode const created to replace string for saveNew action * Hardcoded string for content replaced for const * Const created for default alias * Refactoring dupe constants * Using constanthelper to refactor further * Dupe consts for strings amalgamated Cleaning up the few strings I have missed and duplicate constants with different name Co-authored-by: emma burstow --- .../DefaultConfig/Content/content.spec.ts | 128 ++++++++---------- 1 file changed, 60 insertions(+), 68 deletions(-) diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Content/content.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Content/content.spec.ts index c2b9be27aa..acd7dca7e3 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Content/content.spec.ts +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Content/content.spec.ts @@ -16,7 +16,18 @@ test.describe('Content tests', () => { await page.waitForTimeout(1000); await umbracoApi.login(); }); - + + const rootDocTypeName = "Test document type"; + const childDocTypeName = "Child test document type"; + const firstRootNodeName = "1) Home"; + const secondRootNodeName = "2) Home"; + const firstChildNodeName = "1) Child"; + const secondChildNodeName = "2) Child"; + const saveNode = "saveNew"; + const defaultContentAlias = "alias"; + const homeNodeName = "Home"; + const aliasText = "text"; + async function createSimpleMacro(name, umbracoApi: ApiHelpers){ const insertMacro = new PartialViewMacroBuilder() .withName(name) @@ -35,11 +46,6 @@ test.describe('Content tests', () => { } test('Copy content', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const childDocTypeName = "Child test document type"; - const firstRootNodeName = "1) Home"; - const childNodeName = "1) Child"; - const secondRootNodeName = "2) Home"; await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -59,10 +65,9 @@ test.describe('Content tests', () => { const createdRootDocType = await umbracoApi.documentTypes.save(rootDocType); - // TODO: Make some constants for actions. const rootContentNode = new ContentBuilder() .withContentTypeAlias(createdRootDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .addVariant() .withName(firstRootNodeName) .withSave(true) // We should probably just default to true... @@ -73,7 +78,7 @@ test.describe('Content tests', () => { const secondRootNode = new ContentBuilder() .withContentTypeAlias(createdRootDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .addVariant() .withName(secondRootNodeName) .withSave(true) @@ -84,10 +89,10 @@ test.describe('Content tests', () => { const childContentNode = new ContentBuilder() .withContentTypeAlias(createdChildDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .withParent(savedRootNode.id) .addVariant() - .withName(childNodeName) + .withName(firstChildNodeName) .withSave(true) .done() .build(); @@ -96,7 +101,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [firstRootNodeName, childNodeName]), {button: "right", force: true}) + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [firstRootNodeName, firstChildNodeName]), {button: "right", force: true}) await umbracoUi.clickElement(umbracoUi.getContextMenuAction(ConstantHelper.actions.copy)) await page.locator('.umb-pane [data-element="tree-item-' + secondRootNodeName + '"]').click(); await page.locator('.umb-dialog-footer > .btn-primary').click(); @@ -107,11 +112,6 @@ test.describe('Content tests', () => { }); test('Move content', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const childDocTypeName = "Child test document type"; - const firstRootNodeName = "1) Home"; - const childNodeName = "1) Child"; - const secondRootNodeName = "2) Home"; await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -133,7 +133,7 @@ test.describe('Content tests', () => { const rootContentNode = new ContentBuilder() .withContentTypeAlias(createdRootDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .addVariant() .withName(firstRootNodeName) .withSave(true) // We should probably just default to true... @@ -144,7 +144,7 @@ test.describe('Content tests', () => { const secondRootNode = new ContentBuilder() .withContentTypeAlias(createdRootDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .addVariant() .withName(secondRootNodeName) .withSave(true) @@ -155,10 +155,10 @@ test.describe('Content tests', () => { const childContentNode = new ContentBuilder() .withContentTypeAlias(createdChildDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .withParent(savedRootNode.id) .addVariant() - .withName(childNodeName) + .withName(firstChildNodeName) .withSave(true) .done() .build(); @@ -167,7 +167,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [firstRootNodeName, childNodeName]), { button: "right", force: true }); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [firstRootNodeName, firstChildNodeName]), { button: "right", force: true }); await umbracoUi.clickElement(umbracoUi.getContextMenuAction(ConstantHelper.actions.move)) await page.locator('.umb-pane [data-element="tree-item-' + secondRootNodeName + '"]').click() await page.locator('[key="actions_move"]').click(); @@ -179,11 +179,6 @@ test.describe('Content tests', () => { }); test('Sort content', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const childDocTypeName = "Child test document type"; - const rootNodeName = "1) Home"; - const firstChildNodeName = "1) Child"; - const secondChildNodeName = "2) Child"; await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -203,9 +198,9 @@ test.describe('Content tests', () => { const rootContentNode = new ContentBuilder() .withContentTypeAlias(createdRootDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .addVariant() - .withName(rootNodeName) + .withName(firstRootNodeName) .withSave(true) .done() .build(); @@ -214,7 +209,7 @@ test.describe('Content tests', () => { // Add an item under root node const firstChildContentNode = new ContentBuilder() .withContentTypeAlias(createdChildDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .withParent(createdRootContentNode.id) .addVariant() .withName(firstChildNodeName) @@ -226,7 +221,7 @@ test.describe('Content tests', () => { // Add a second item under root node const secondChildContentNode = new ContentBuilder() .withContentTypeAlias(createdChildDocType.alias) - .withAction("saveNew") + .withAction(saveNode) .withParent(createdRootContentNode.id) .addVariant() .withName(secondChildNodeName) @@ -236,7 +231,7 @@ test.describe('Content tests', () => { await umbracoApi.content.save(secondChildContentNode); await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [rootNodeName]), { button: "right", force: true }); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [firstRootNodeName]), { button: "right", force: true }); await umbracoUi.clickElement(umbracoUi.getContextMenuAction(ConstantHelper.actions.sort)); // Drag'n'drop second child to be the first one. await page.locator('.ui-sortable-handle >> text=' + secondChildNodeName).hover(); @@ -256,9 +251,8 @@ test.describe('Content tests', () => { }); test('Rollback content', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; + const initialNodeName = "Home node"; - const newNodeName = "Home"; await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -279,7 +273,7 @@ test.describe('Content tests', () => { await umbracoApi.content.save(rootContentNode); await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [initialNodeName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [initialNodeName])); const header = await page.locator('#headerName') // Sadly playwright doesn't have a clear method for inputs :( @@ -287,7 +281,7 @@ test.describe('Content tests', () => { await header.click({ clickCount: 3 }) await page.keyboard.press('Backspace'); - await umbracoUi.setEditorHeaderName(newNodeName); + await umbracoUi.setEditorHeaderName(homeNodeName); await umbracoUi.clickElement(umbracoUi.getButtonByLabelKey(ConstantHelper.buttons.saveAndPublish)); await umbracoUi.isSuccessNotificationVisible(); await page.locator('span:has-text("×")').click(); @@ -303,13 +297,12 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); await expect(page.locator('.umb-badge >> text=Save')).toBeVisible(); await expect(page.locator('.umb-badge >> text=RollBack')).toBeVisible(); - const node = await umbracoUi.getTreeItem("content", [initialNodeName]) + const node = await umbracoUi.getTreeItem(ConstantHelper.sections.content, [initialNodeName]) await expect(node).toBeVisible(); }); test('View audit trail', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const nodeName = "Home"; + const labelName = "Name"; await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -328,9 +321,9 @@ test.describe('Content tests', () => { const generatedRootDocType = await umbracoApi.documentTypes.save(rootDocType) const rootContentNode = new ContentBuilder() - .withContentTypeAlias(generatedRootDocType["alias"]) + .withContentTypeAlias(generatedRootDocType[defaultContentAlias]) .addVariant() - .withName(nodeName) + .withName(homeNodeName) .withSave(true) .done() .build(); @@ -341,7 +334,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); // Access node - await umbracoUi.clickElement(umbracoUi.getTreeItem('content', [nodeName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [homeNodeName])); // Navigate to Info app await page.locator(ConstantHelper.contentApps.info).click(); @@ -354,8 +347,7 @@ test.describe('Content tests', () => { }); test('Save draft', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const nodeName = "Home"; + const expected = "Unpublished"; await umbracoApi.content.deleteAllContent(); @@ -369,10 +361,10 @@ test.describe('Content tests', () => { const generatedRootDocType = await umbracoApi.documentTypes.save(rootDocType); const rootContentNode = new ContentBuilder() - .withContentTypeAlias(generatedRootDocType["alias"]) - .withAction("saveNew") + .withContentTypeAlias(generatedRootDocType[defaultContentAlias]) + .withAction(saveNode) .addVariant() - .withName(nodeName) + .withName(homeNodeName) .withSave(true) .done() .build(); @@ -383,7 +375,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); // Access node - await umbracoUi.clickElement(umbracoUi.getTreeItem('content', [nodeName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [homeNodeName])); // Assert await expect(page.locator('[data-element="node-info-status"]').locator('.umb-badge')).toContainText(expected); @@ -393,8 +385,8 @@ test.describe('Content tests', () => { }); test('Preview draft', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const nodeName = "Home"; + + await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(rootDocTypeName); @@ -407,10 +399,10 @@ test.describe('Content tests', () => { const generatedRootDocType = await umbracoApi.documentTypes.save(rootDocType); const rootContentNode = new ContentBuilder() - .withContentTypeAlias(generatedRootDocType["alias"]) - .withAction("saveNew") + .withContentTypeAlias(generatedRootDocType[defaultContentAlias]) + .withAction(saveNode) .addVariant() - .withName(nodeName) + .withName(homeNodeName) .withSave(true) .done() .build(); @@ -421,7 +413,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); // Access node - await umbracoUi.clickElement(umbracoUi.getTreeItem('content', [nodeName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [homeNodeName])); // Assert await expect(page.locator('[alias="preview"]')).toBeVisible(); @@ -433,8 +425,7 @@ test.describe('Content tests', () => { }); test('Publish draft', async ({ page, umbracoApi, umbracoUi }) => { - const rootDocTypeName = "Test document type"; - const nodeName = "Home"; + const expected = "Published"; await umbracoApi.content.deleteAllContent(); @@ -448,9 +439,9 @@ test.describe('Content tests', () => { const generatedRootDocType = await umbracoApi.documentTypes.save(rootDocType); const rootContentNode = new ContentBuilder() - .withContentTypeAlias(generatedRootDocType["alias"]) + .withContentTypeAlias(generatedRootDocType[defaultContentAlias]) .addVariant() - .withName(nodeName) + .withName(homeNodeName) .withSave(true) .done() .build(); @@ -461,7 +452,7 @@ test.describe('Content tests', () => { await umbracoUi.refreshContentTree(); // Access node - await umbracoUi.clickElement(umbracoUi.getTreeItem('content', [nodeName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [homeNodeName])); // Assert await expect(page.locator('[data-element="node-info-status"]').locator('.umb-badge')).toContainText(expected); @@ -476,6 +467,7 @@ test.describe('Content tests', () => { const pickedDocTypeName = 'Picked content document type'; const pickedDocTypeAlias = AliasHelper.toAlias(pickedDocTypeName); + await umbracoApi.content.deleteAllContent(); await umbracoApi.documentTypes.ensureNameNotExists(pickerDocTypeName); await umbracoApi.templates.ensureNameNotExists(pickerDocTypeName); @@ -488,21 +480,21 @@ test.describe('Content tests', () => { .withAllowAsRoot(true) .addGroup() .addTextBoxProperty() - .withAlias('text') + .withAlias(aliasText) .done() .done() .build(); const generatedType = await umbracoApi.documentTypes.save(pickedDocType) const pickedContentNode = new ContentBuilder() - .withContentTypeAlias(generatedType["alias"]) + .withContentTypeAlias(generatedType[defaultContentAlias]) .withAction("publishNew") .addVariant() .withName('Content to pick') .withSave(true) .withPublish(true) .addProperty() - .withAlias('text') + .withAlias(aliasText) .withValue('Acceptance test') .done() .withSave(true) @@ -590,7 +582,7 @@ test.describe('Content tests', () => { .withDefaultTemplate(alias) .addGroup() .addRichTextProperty() - .withAlias('text') + .withAlias(aliasText) .done() .done() .build(); @@ -598,8 +590,8 @@ test.describe('Content tests', () => { const generatedDocType = await umbracoApi.documentTypes.save(docType) // Might as wel initally create the content here, the less GUI work during the test the better const contentNode = new ContentBuilder() - .withContentTypeAlias(generatedDocType["alias"]) - .withAction('saveNew') + .withContentTypeAlias(generatedDocType[defaultContentAlias]) + .withAction(saveNode) .addVariant() .withName(viewMacroName) .withSave(true) @@ -624,7 +616,7 @@ test.describe('Content tests', () => { // Enter content await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [viewMacroName])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [viewMacroName])); // Insert macro await page.locator('[title="Insert macro"]').click(); @@ -685,7 +677,7 @@ test.describe('Content tests', () => { const generatedDocType = await umbracoApi.documentTypes.save(docType); const contentNode = new ContentBuilder() - .withContentTypeAlias(generatedDocType["alias"]) + .withContentTypeAlias(generatedDocType[defaultContentAlias]) .addVariant() .withName(name) .withSave(true) @@ -707,7 +699,7 @@ test.describe('Content tests', () => { // Act // Enter content await umbracoUi.refreshContentTree(); - await umbracoUi.clickElement(umbracoUi.getTreeItem("content", [name])); + await umbracoUi.clickElement(umbracoUi.getTreeItem(ConstantHelper.sections.content, [name])); // Click add await page.locator(':nth-child(2) > .preview-row > .preview-col > .preview-cell').click(); // Choose 1 column layout.