From cff1dd52199a95a2dab6ddbccbc77bf4f98135c8 Mon Sep 17 00:00:00 2001 From: Andreas Zerbst <73799582+andr317c@users.noreply.github.com> Date: Thu, 23 May 2024 12:00:01 +0200 Subject: [PATCH] V14 QA Added document type acceptance test (#16211) * Added tests * Added the rest of the tests * Few changes to failing test * Added tests for folders * More cleanup * Updates * Fixed tests * More documentType fixes * Fixed test * Cleaned up * Cleaned * Bumped version of testHelpers * Added @smoke in the define to test all our tests * Updated version * Added smoke tags * Remove reload * Added clean * Updates from comments, not done * Added smoke tag * Uncommented test.describe * Bumped version * Added semicolon * Split documentType tests into more files * Bumped version * Removed test describe and fixed indentation --- .../DocumentType/DocumentType.spec.ts | 150 ++++++ .../DocumentTypeDesignTab.spec.ts | 431 ++++++++++++++++++ .../DocumentType/DocumentTypeFolder.spec.ts | 128 ++++++ .../DocumentTypeSettingsTab.spec.ts | 84 ++++ .../DocumentTypeStructureTab.spec.ts | 97 ++++ .../DocumentTypeTemplatesTab.spec.ts | 78 ++++ 6 files changed, 968 insertions(+) create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentType.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeDesignTab.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeFolder.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeSettingsTab.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeStructureTab.spec.ts create mode 100644 tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeTemplatesTab.spec.ts diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentType.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentType.spec.ts new file mode 100644 index 0000000000..e12749b1cd --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentType.spec.ts @@ -0,0 +1,150 @@ +import {AliasHelper, ConstantHelper, test} from '@umbraco/playwright-testhelpers'; +import {expect} from '@playwright/test'; + +const documentTypeName = 'TestDocumentType'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); +}); + +test('can create a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.clickActionsMenuAtRoot(); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateDocumentTypeButton(); + await umbracoUi.documentType.enterDocumentTypeName(documentTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + await umbracoUi.documentType.reloadTree('Document Types'); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentTypeName); +}); + +test('can create a document type with a template', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoApi.template.ensureNameNotExists(documentTypeName); + + // Act + await umbracoUi.documentType.clickActionsMenuAtRoot(); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateDocumentTypeWithTemplateButton(); + await umbracoUi.documentType.enterDocumentTypeName(documentTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + // Checks if both the success notification for document Types and teh template are visible + await umbracoUi.documentType.doesSuccessNotificationsHaveCount(2); + // Checks if the documentType contains the template + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + const templateData = await umbracoApi.template.getByName(documentTypeName); + expect(documentTypeData.allowedTemplates[0].id).toEqual(templateData.id); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + + // Clean + await umbracoApi.template.ensureNameNotExists(documentTypeName); +}); + +test('can create a element type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.clickActionsMenuAtRoot(); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateElementTypeButton(); + await umbracoUi.documentType.enterDocumentTypeName(documentTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + // Checks if the isElement is true + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.isElement).toBeTruthy(); +}); + +test('can rename a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const wrongName = 'NotADocumentTypeName'; + await umbracoApi.documentType.ensureNameNotExists(wrongName); + await umbracoApi.documentType.createDefaultDocumentType(wrongName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(wrongName); + await umbracoUi.documentType.enterDocumentTypeName(documentTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + await umbracoUi.documentType.isDocumentTreeItemVisible(wrongName, false); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentTypeName); +}); + +test('can update the alias for a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const oldAlias = AliasHelper.toAlias(documentTypeName); + const newAlias = 'newDocumentTypeAlias'; + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + const documentTypeDataOld = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeDataOld.alias).toBe(oldAlias); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.enterAliasName(newAlias); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentTypeName, true); + const documentTypeDataNew = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeDataNew.alias).toBe(newAlias); +}); + +test('can add an icon for a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const bugIcon = 'icon-bug'; + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.updateIcon(bugIcon); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.icon).toBe(bugIcon); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentTypeName, true); +}); + +test('can delete a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + + // Act + await umbracoUi.documentType.clickRootFolderCaretButton(); + await umbracoUi.documentType.clickActionsMenuForDocumentType(documentTypeName); + await umbracoUi.documentType.clickDeleteExactButton(); + await umbracoUi.documentType.clickConfirmToDeleteButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeFalsy(); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeDesignTab.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeDesignTab.spec.ts new file mode 100644 index 0000000000..9254db4605 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeDesignTab.spec.ts @@ -0,0 +1,431 @@ +import {ConstantHelper, test} from "@umbraco/playwright-testhelpers"; +import {expect} from "@playwright/test"; + +const documentTypeName = 'TestDocumentType'; +const dataTypeName = 'Approved Color'; +const groupName = 'TestGroup'; +const tabName = 'TestTab'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); +}); + +test('can add a property to a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickAddGroupButton(); + await umbracoUi.documentType.addPropertyEditor(dataTypeName); + await umbracoUi.documentType.enterGroupName(groupName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + const dataType = await umbracoApi.dataType.getByName(dataTypeName); + // Checks if the correct property was added to the document type + expect(documentTypeData.properties[0].dataType.id).toBe(dataType.id); +}); + +test('can update a property in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const newDataTypeName = 'Image Media Picker'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.updatePropertyEditor(newDataTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + const dataType = await umbracoApi.dataType.getByName(newDataTypeName); + // Checks if the correct property was added to the document type + expect(documentTypeData.properties[0].dataType.id).toBe(dataType.id); +}); + +test('can update group name in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const newGroupName = 'UpdatedGroupName'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.enterGroupName(newGroupName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.containers[0].name).toBe(newGroupName); +}); + +test('can delete a group in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id, groupName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.deleteGroup(groupName, true); + await umbracoUi.documentType.clickConfirmToDeleteButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.containers.length).toBe(0); + expect(documentTypeData.properties.length).toBe(0); +}); + +// TODO: Currently I am getting an error If I delete a tab that contains children. The children are not cleaned up when deleting the tab. +test.skip('can delete a tab in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditorInTab(documentTypeName, dataTypeName, dataTypeData.id, tabName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickRemoveTabWithName(tabName); + await umbracoUi.documentType.clickConfirmToDeleteButton(); + await umbracoUi.documentType.clickSaveButton(); + + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); +}); + +test('can delete a property editor in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id, groupName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.deletePropertyEditorWithName(dataTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties.length).toBe(0); +}); + +test('can create a document type with a property in a tab', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickAddTabButton(); + await umbracoUi.documentType.enterTabName(tabName); + await umbracoUi.documentType.clickAddGroupButton(); + await umbracoUi.documentType.addPropertyEditor(dataTypeName, 1); + await umbracoUi.documentType.enterGroupName(groupName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(await umbracoApi.documentType.doesTabContainCorrectPropertyEditorInGroup(documentTypeName, dataTypeName, documentTypeData.properties[0].dataType.id, tabName, groupName)).toBeTruthy(); +}); + +test('can create a document type with multiple groups', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const secondDataTypeName = 'Image Media Picker'; + const secondGroupName = 'TesterGroup'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id, groupName); + const secondDataType = await umbracoApi.dataType.getByName(secondDataTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickAddGroupButton(); + await umbracoUi.documentType.enterGroupName(secondGroupName, 1); + await umbracoUi.documentType.addPropertyEditor(secondDataTypeName, 1); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + expect(await umbracoApi.documentType.doesGroupContainCorrectPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id, groupName)).toBeTruthy(); + expect(await umbracoApi.documentType.doesGroupContainCorrectPropertyEditor(documentTypeName, secondDataTypeName, secondDataType.id, secondGroupName)).toBeTruthy(); +}); + +test('can create a document type with multiple tabs', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const secondDataTypeName = 'Image Media Picker'; + const secondGroupName = 'TesterGroup'; + const secondTabName = 'SecondTab'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditorInTab(documentTypeName, dataTypeName, dataTypeData.id, tabName, groupName); + const secondDataType = await umbracoApi.dataType.getByName(secondDataTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickAddTabButton(); + await umbracoUi.documentType.enterTabName(secondTabName); + await umbracoUi.documentType.clickAddGroupButton(); + await umbracoUi.documentType.enterGroupName(secondGroupName); + await umbracoUi.documentType.addPropertyEditor(secondDataTypeName, 1); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesNameExist(documentTypeName)).toBeTruthy(); + expect(await umbracoApi.documentType.doesTabContainCorrectPropertyEditorInGroup(documentTypeName, dataTypeName, dataTypeData.id, tabName, groupName)).toBeTruthy(); + expect(await umbracoApi.documentType.doesTabContainCorrectPropertyEditorInGroup(documentTypeName, secondDataTypeName, secondDataType.id, secondTabName, secondGroupName)).toBeTruthy(); +}); + +test('can create a document type with a composition', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const compositionDocumentTypeName = 'CompositionDocumentType'; + await umbracoApi.documentType.ensureNameNotExists(compositionDocumentTypeName); + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const compositionDocumentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(compositionDocumentTypeName, dataTypeName, dataTypeData.id, groupName); + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickCompositionsButton(); + await umbracoUi.documentType.clickButtonWithName(compositionDocumentTypeName); + await umbracoUi.documentType.clickSubmitButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(umbracoUi.documentType.doesGroupHaveValue(groupName)).toBeTruthy(); + // Checks if the composition in the document type is correct + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.compositions[0].documentType.id).toBe(compositionDocumentTypeId); + + // Clean + await umbracoApi.documentType.ensureNameNotExists(compositionDocumentTypeName); +}); + +test('can remove a composition form a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const compositionDocumentTypeName = 'CompositionDocumentType'; + await umbracoApi.documentType.ensureNameNotExists(compositionDocumentTypeName); + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const compositionDocumentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(compositionDocumentTypeName, dataTypeName, dataTypeData.id, groupName); + await umbracoApi.documentType.createDocumentTypeWithAComposition(documentTypeName, compositionDocumentTypeId); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickCompositionsButton(); + await umbracoUi.documentType.clickButtonWithName(compositionDocumentTypeName); + await umbracoUi.documentType.clickSubmitButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoUi.documentType.doesGroupHaveValue(groupName)).toBeFalsy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.compositions).toEqual([]); + + // Clean + await umbracoApi.documentType.ensureNameNotExists(compositionDocumentTypeName); +}); + +test('can reorder groups in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const secondGroupName = 'SecondGroup'; + await umbracoApi.documentType.createDocumentTypeWithTwoGroups(documentTypeName, dataTypeName, dataTypeData.id, groupName, secondGroupName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.goToDocumentType(documentTypeName); + + // Act + await umbracoUi.documentType.clickReorderButton(); + const groupValues = await umbracoUi.documentType.reorderTwoGroups(); + const firstGroupValue = groupValues.firstGroupValue; + const secondGroupValue = groupValues.secondGroupValue; + await umbracoUi.documentType.clickIAmDoneReorderingButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + // Since we swapped sorting order, the firstGroupValue should have sortOrder 1 and the secondGroupValue should have sortOrder 0 + expect(await umbracoApi.documentType.doesDocumentTypeGroupNameContainCorrectSortOrder(documentTypeName, secondGroupValue, 0)).toBeTruthy(); + expect(await umbracoApi.documentType.doesDocumentTypeGroupNameContainCorrectSortOrder(documentTypeName, firstGroupValue, 1)).toBeTruthy(); +}); + +// TODO: Unskip when it works. Sometimes the properties are not dragged correctly. +test.skip('can reorder properties in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const dataTypeNameTwo = "Second Color Picker"; + await umbracoApi.documentType.createDocumentTypeWithTwoPropertyEditors(documentTypeName, dataTypeName, dataTypeData.id, dataTypeNameTwo, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickReorderButton(); + // Drag and Drop + await umbracoUi.waitForTimeout(5000); + const dragFromLocator = umbracoUi.documentType.getTextLocatorWithName(dataTypeNameTwo); + const dragToLocator = umbracoUi.documentType.getTextLocatorWithName(dataTypeName); + await umbracoUi.documentType.dragAndDrop(dragFromLocator, dragToLocator, 0, 0, 5); + await umbracoUi.documentType.clickIAmDoneReorderingButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].name).toBe(dataTypeNameTwo); + expect(documentTypeData.properties[1].name).toBe(dataTypeName); +}); + +// TODO: Unskip when the frontend does not give the secondTab -1 as the sortOrder +test.skip('can reorder tabs in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const secondTabName = 'SecondTab'; + await umbracoApi.documentType.createDocumentTypeWithTwoTabs(documentTypeName, dataTypeName, dataTypeData.id, tabName, secondTabName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.goToDocumentType(documentTypeName); + + // Act + const dragToLocator = umbracoUi.documentType.getTabLocatorWithName(tabName); + const dragFromLocator = umbracoUi.documentType.getTabLocatorWithName(secondTabName); + await umbracoUi.documentType.clickReorderButton(); + await umbracoUi.documentType.dragAndDrop(dragFromLocator, dragToLocator, 0, 0, 10); + await umbracoUi.documentType.clickIAmDoneReorderingButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + expect(await umbracoApi.documentType.doesDocumentTypeTabNameContainCorrectSortOrder(documentTypeName, secondTabName, 0)).toBeTruthy(); + expect(await umbracoApi.documentType.doesDocumentTypeTabNameContainCorrectSortOrder(documentTypeName, tabName, 1)).toBeTruthy(); +}); + +test('can add a description to a property in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const descriptionText = 'This is a property'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickEditorSettingsButton(); + await umbracoUi.documentType.enterPropertyEditorDescription(descriptionText); + await umbracoUi.documentType.clickUpdateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + await expect(umbracoUi.documentType.enterDescriptionTxt).toBeVisible(); + expect(umbracoUi.documentType.doesDescriptionHaveValue(descriptionText)).toBeTruthy(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].description).toBe(descriptionText); +}); + +test('can set is mandatory for a property in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickEditorSettingsButton(); + await umbracoUi.documentType.clickMandatorySlider(); + await umbracoUi.documentType.clickUpdateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].validation.mandatory).toBeTruthy(); +}); + +test('can enable validation for a property in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + const regex = '^[a-zA-Z0-9]*$'; + const regexMessage = 'Only letters and numbers are allowed'; + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickEditorSettingsButton(); + await umbracoUi.documentType.selectValidationOption(''); + await umbracoUi.documentType.enterRegEx(regex); + await umbracoUi.documentType.enterRegExMessage(regexMessage); + await umbracoUi.documentType.clickUpdateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].validation.regEx).toBe(regex); + expect(documentTypeData.properties[0].validation.regExMessage).toBe(regexMessage); +}); + +test('can allow vary by culture for a property in a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id, groupName, true); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickEditorSettingsButton(); + await umbracoUi.documentType.clickVaryByCultureSlider(); + await umbracoUi.documentType.clickUpdateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].variesByCulture).toBeTruthy(); +}); + +test('can set appearance to label on top for a property in a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickEditorSettingsButton(); + await umbracoUi.documentType.clickLabelOnTopButton(); + await umbracoUi.documentType.clickUpdateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.properties[0].appearance.labelOnTop).toBeTruthy(); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeFolder.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeFolder.spec.ts new file mode 100644 index 0000000000..b6a8660ad9 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeFolder.spec.ts @@ -0,0 +1,128 @@ +import {ConstantHelper, test} from '@umbraco/playwright-testhelpers'; +import {expect} from '@playwright/test'; + +const documentFolderName = 'TestFolder'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentFolderName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentFolderName); +}); + +test('can create a empty document type folder', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Act + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.clickActionsMenuForName('Document Types'); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateDocumentFolderButton(); + await umbracoUi.documentType.enterFolderName(documentFolderName); + await umbracoUi.documentType.clickCreateFolderButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const folder = await umbracoApi.documentType.getByName(documentFolderName); + expect(folder.name).toBe(documentFolderName); + // Checks if the folder is in the root + await umbracoUi.documentType.reloadTree('Document Types'); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentFolderName); +}); + +test('can delete a document type folder', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createFolder(documentFolderName); + + // Act + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.clickRootFolderCaretButton(); + await umbracoUi.documentType.clickActionsMenuForName(documentFolderName); + await umbracoUi.documentType.deleteFolder(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + await umbracoApi.documentType.doesNameExist(documentFolderName); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentFolderName, false); +}); + +test('can rename a document type folder', async ({umbracoApi, umbracoUi}) => { + // Arrange + const oldFolderName = 'OldName'; + await umbracoApi.documentType.createFolder(oldFolderName); + + // Act + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.clickRootFolderCaretButton(); + await umbracoUi.documentType.clickActionsMenuForName(oldFolderName); + await umbracoUi.documentType.clickRenameFolderButton(); + await umbracoUi.documentType.enterFolderName(documentFolderName); + await umbracoUi.documentType.clickUpdateFolderButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const folder = await umbracoApi.documentType.getByName(documentFolderName); + expect(folder.name).toBe(documentFolderName); + await umbracoUi.documentType.isDocumentTreeItemVisible(oldFolderName, false); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentFolderName); +}); + +test('can create a document type folder in a folder', async ({umbracoApi, umbracoUi}) => { + // Arrange + const childFolderName = 'ChildFolder'; + await umbracoApi.documentType.ensureNameNotExists(childFolderName); + const parentFolderId = await umbracoApi.documentType.createFolder(documentFolderName); + + // Act + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.clickRootFolderCaretButton(); + await umbracoUi.documentType.clickActionsMenuForName(documentFolderName); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateDocumentFolderButton(); + await umbracoUi.documentType.enterFolderName(childFolderName); + await umbracoUi.documentType.clickCreateFolderButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const folder = await umbracoApi.documentType.getByName(childFolderName); + expect(folder.name).toBe(childFolderName); + // Checks if the parentFolder contains the ChildFolder as a child + const parentFolder = await umbracoApi.documentType.getChildren(parentFolderId); + expect(parentFolder[0].name).toBe(childFolderName); + + // Clean + await umbracoApi.documentType.ensureNameNotExists(childFolderName); +}); + +test('can create a folder in a folder in a folder', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + const grandParentFolderName = 'TheGrandFolder'; + const parentFolderName = 'TheParentFolder'; + await umbracoApi.documentType.ensureNameNotExists(grandParentFolderName); + await umbracoApi.documentType.ensureNameNotExists(parentFolderName); + const grandParentFolderId = await umbracoApi.documentType.createFolder(grandParentFolderName); + const parentFolderId = await umbracoApi.documentType.createFolder(parentFolderName, grandParentFolderId); + + // Act + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + await umbracoUi.documentType.clickRootFolderCaretButton(); + await umbracoUi.documentType.clickCaretButtonForName(grandParentFolderName); + await umbracoUi.documentType.clickActionsMenuForName(parentFolderName); + await umbracoUi.documentType.clickCreateButton(); + await umbracoUi.documentType.clickCreateDocumentFolderButton(); + await umbracoUi.documentType.enterFolderName(documentFolderName); + await umbracoUi.documentType.clickCreateFolderButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + await umbracoUi.documentType.reloadTree(parentFolderName); + await umbracoUi.documentType.isDocumentTreeItemVisible(documentFolderName); + const grandParentChildren = await umbracoApi.documentType.getChildren(grandParentFolderId); + expect(grandParentChildren[0].name).toBe(parentFolderName); + const parentChildren = await umbracoApi.documentType.getChildren(parentFolderId); + expect(parentChildren[0].name).toBe(documentFolderName); + + // Clean + await umbracoApi.documentType.ensureNameNotExists(grandParentFolderName); + await umbracoApi.documentType.ensureNameNotExists(parentFolderName); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeSettingsTab.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeSettingsTab.spec.ts new file mode 100644 index 0000000000..7463ff804b --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeSettingsTab.spec.ts @@ -0,0 +1,84 @@ +import {ConstantHelper, test} from "@umbraco/playwright-testhelpers"; +import {expect} from "@playwright/test"; + +const documentTypeName = 'TestDocumentType'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); +}); + +test('can add allow vary by culture for a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeSettingsTab(); + await umbracoUi.documentType.clickVaryByCultureButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.variesByCulture).toBeTruthy(); +}); + +test('can add allow segmentation for a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeSettingsTab(); + await umbracoUi.documentType.clickVaryBySegmentsButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.variesBySegment).toBeTruthy(); +}); + +test('can set is an element type for a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeSettingsTab(); + await umbracoUi.documentType.clickTextButtonWithName('Element type'); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.isElement).toBeTruthy(); +}); + +// TODO: Unskip. Currently The cleanup is not updated upon save +test.skip('can disable history cleanup for a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + // Is needed + await umbracoUi.waitForTimeout(200); + await umbracoUi.documentType.clickDocumentTypeSettingsTab(); + await umbracoUi.documentType.clickAutoCleanupButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.cleanup.preventCleanup).toBeTruthy(); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeStructureTab.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeStructureTab.spec.ts new file mode 100644 index 0000000000..2bf10c9157 --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeStructureTab.spec.ts @@ -0,0 +1,97 @@ +import {ConstantHelper, test} from "@umbraco/playwright-testhelpers"; +import {expect} from "@playwright/test"; + +const documentTypeName = 'TestDocumentType'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); +}); + +test('can add allow as root to a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickStructureTab(); + await umbracoUi.documentType.clickAllowAtRootButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedAsRoot).toBeTruthy(); +}); + +test('can add an allowed child node to a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickStructureTab(); + await umbracoUi.documentType.clickChooseButton(); + await umbracoUi.documentType.clickButtonWithName(documentTypeName); + await umbracoUi.documentType.clickAllowedChildNodesButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedDocumentTypes[0].documentType.id).toBe(documentTypeData.id); +}); + +test('can remove an allowed child node from a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const childDocumentTypeName = 'ChildDocumentType'; + await umbracoApi.documentType.ensureNameNotExists(childDocumentTypeName); + const childDocumentTypeId = await umbracoApi.documentType.createDefaultDocumentType(childDocumentTypeName); + await umbracoApi.documentType.createDocumentTypeWithAllowedChildNode(documentTypeName, childDocumentTypeId); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickStructureTab(); + await umbracoUi.documentType.clickRemoveButtonForName(childDocumentTypeName); + await umbracoUi.documentType.clickConfirmRemoveButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedDocumentTypes.length).toBe(0); + + // Clean + await umbracoApi.documentType.ensureNameNotExists(childDocumentTypeName); +}); + +test('can configure a collection for a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + const collectionDataTypeName = 'TestCollection'; + await umbracoApi.dataType.ensureNameNotExists(collectionDataTypeName); + const collectionDataTypeId = await umbracoApi.dataType.create(collectionDataTypeName, 'Umbraco.ListView', [], null, 'Umb.PropertyEditorUi.CollectionView'); + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickStructureTab(); + await umbracoUi.documentType.clickConfigureAsACollectionButton(); + await umbracoUi.documentType.clickTextButtonWithName(collectionDataTypeName); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.collection.id).toEqual(collectionDataTypeId); + + // Clean + await umbracoApi.dataType.ensureNameNotExists(collectionDataTypeName); +}); diff --git a/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeTemplatesTab.spec.ts b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeTemplatesTab.spec.ts new file mode 100644 index 0000000000..1390bbdc4f --- /dev/null +++ b/tests/Umbraco.Tests.AcceptanceTest/tests/DefaultConfig/Settings/DocumentType/DocumentTypeTemplatesTab.spec.ts @@ -0,0 +1,78 @@ +import {ConstantHelper, test} from "@umbraco/playwright-testhelpers"; +import {expect} from "@playwright/test"; + +const documentTypeName = 'TestDocumentType'; +const templateName = 'TestTemplate'; + +test.beforeEach(async ({umbracoUi, umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); + await umbracoUi.goToBackOffice(); +}); + +test.afterEach(async ({umbracoApi}) => { + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); +}); + +test('can add an allowed template to a document type', {tag: '@smoke'}, async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.documentType.createDefaultDocumentType(documentTypeName); + await umbracoApi.template.ensureNameNotExists(templateName); + const templateId = await umbracoApi.template.createDefaultTemplate(templateName); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeTemplatesTab(); + await umbracoUi.documentType.clickAddButton(); + await umbracoUi.documentType.clickLabelWithName(templateName); + await umbracoUi.documentType.clickChooseButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedTemplates[0].id).toBe(templateId); + + // Clean + await umbracoApi.template.ensureNameNotExists(templateName); +}); + +test('can set an allowed template as default for document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.template.ensureNameNotExists(templateName); + const templateId = await umbracoApi.template.createDefaultTemplate(templateName); + await umbracoApi.documentType.createDocumentTypeWithAllowedTemplate(documentTypeName, templateId); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeTemplatesTab(); + await umbracoUi.documentType.clickDefaultTemplateButton(); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedTemplates[0].id).toBe(templateId); + expect(documentTypeData.defaultTemplate.id).toBe(templateId); +}); + +// When removing a template, the defaultTemplateId is set to "" which is not correct +test.skip('can remove an allowed template from a document type', async ({umbracoApi, umbracoUi}) => { + // Arrange + await umbracoApi.template.ensureNameNotExists(templateName); + const templateId = await umbracoApi.template.createDefaultTemplate(templateName); + await umbracoApi.documentType.createDocumentTypeWithAllowedTemplate(documentTypeName, templateId); + await umbracoUi.documentType.goToSection(ConstantHelper.sections.settings); + + // Act + await umbracoUi.documentType.goToDocumentType(documentTypeName); + await umbracoUi.documentType.clickDocumentTypeTemplatesTab(); + await umbracoUi.documentType.clickRemoveWithName(templateName, true); + await umbracoUi.documentType.clickSaveButton(); + + // Assert + await umbracoUi.documentType.isSuccessNotificationVisible(); + const documentTypeData = await umbracoApi.documentType.getByName(documentTypeName); + expect(documentTypeData.allowedTemplates).toHaveLength(0); +});