|
| 1 | +import {AliasHelper, ConstantHelper, test} from '@umbraco/playwright-testhelpers'; |
| 2 | +import {expect} from "@playwright/test"; |
| 3 | + |
| 4 | +const contentName = 'TestContent'; |
| 5 | +const documentTypeName = 'TestDocumentTypeForContent'; |
| 6 | +const dataTypeName = 'Approved Color'; |
| 7 | + |
| 8 | +test.beforeEach(async ({umbracoApi, umbracoUi}) => { |
| 9 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 10 | + await umbracoApi.document.ensureNameNotExists(contentName); |
| 11 | + await umbracoUi.goToBackOffice(); |
| 12 | +}); |
| 13 | + |
| 14 | +test.afterEach(async ({umbracoApi}) => { |
| 15 | + await umbracoApi.document.ensureNameNotExists(contentName); |
| 16 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 17 | +}); |
| 18 | + |
| 19 | +test('can create content with the approved color data type', async ({umbracoApi, umbracoUi}) => { |
| 20 | + // Arrange |
| 21 | + const expectedState = 'Draft'; |
| 22 | + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); |
| 23 | + await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); |
| 24 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 25 | + |
| 26 | + // Act |
| 27 | + await umbracoUi.content.clickActionsMenuAtRoot(); |
| 28 | + await umbracoUi.content.clickCreateButton(); |
| 29 | + await umbracoUi.content.chooseDocumentType(documentTypeName); |
| 30 | + await umbracoUi.content.enterContentName(contentName); |
| 31 | + await umbracoUi.content.clickSaveButton(); |
| 32 | + |
| 33 | + // Assert |
| 34 | + await umbracoUi.content.isSuccessNotificationVisible(); |
| 35 | + expect(await umbracoApi.document.doesNameExist(contentName)).toBeTruthy(); |
| 36 | + const contentData = await umbracoApi.document.getByName(contentName); |
| 37 | + expect(contentData.variants[0].state).toBe(expectedState); |
| 38 | + expect(contentData.values).toEqual([]); |
| 39 | +}); |
| 40 | + |
| 41 | +test('can publish content with the approved color data type', async ({umbracoApi, umbracoUi}) => { |
| 42 | + // Arrange |
| 43 | + const expectedState = 'Published'; |
| 44 | + const dataTypeData = await umbracoApi.dataType.getByName(dataTypeName); |
| 45 | + const documentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, dataTypeName, dataTypeData.id); |
| 46 | + await umbracoApi.document.createDefaultDocument(contentName, documentTypeId); |
| 47 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 48 | + |
| 49 | + // Act |
| 50 | + await umbracoUi.content.goToContentWithName(contentName); |
| 51 | + await umbracoUi.content.clickSaveAndPublishButton(); |
| 52 | + |
| 53 | + // Assert |
| 54 | + await umbracoUi.content.doesSuccessNotificationsHaveCount(2); |
| 55 | + expect(await umbracoApi.document.doesNameExist(contentName)).toBeTruthy(); |
| 56 | + const contentData = await umbracoApi.document.getByName(contentName); |
| 57 | + expect(contentData.variants[0].state).toBe(expectedState); |
| 58 | + expect(contentData.values).toEqual([]); |
| 59 | +}); |
| 60 | + |
| 61 | +test('can create content with the custom approved color data type', async ({umbracoApi, umbracoUi}) => { |
| 62 | + // Arrange |
| 63 | + const customDataTypeName = 'CustomApprovedColor'; |
| 64 | + const colorValue = 'd73737'; |
| 65 | + const colorLabel = 'Test Label'; |
| 66 | + const customDataTypeId = await umbracoApi.dataType.createApprovedColorDataTypeWithOneItem(customDataTypeName, colorLabel, colorValue); |
| 67 | + const documentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, customDataTypeName, customDataTypeId); |
| 68 | + await umbracoApi.document.createDefaultDocument(contentName, documentTypeId); |
| 69 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 70 | + |
| 71 | + // Act |
| 72 | + await umbracoUi.content.goToContentWithName(contentName); |
| 73 | + await umbracoUi.content.clickApprovedColorByValue(colorValue); |
| 74 | + await umbracoUi.content.clickSaveAndPublishButton(); |
| 75 | + |
| 76 | + // Assert |
| 77 | + await umbracoUi.content.doesSuccessNotificationsHaveCount(2); |
| 78 | + expect(await umbracoApi.document.doesNameExist(contentName)).toBeTruthy(); |
| 79 | + const contentData = await umbracoApi.document.getByName(contentName); |
| 80 | + expect(contentData.values[0].alias).toEqual(AliasHelper.toAlias(customDataTypeName)); |
| 81 | + expect(contentData.values[0].value.label).toEqual(colorLabel); |
| 82 | + expect(contentData.values[0].value.value).toEqual('#' + colorValue); |
| 83 | + |
| 84 | + // Clean |
| 85 | + await umbracoApi.dataType.ensureNameNotExists(customDataTypeName); |
| 86 | +}); |
| 87 | + |
0 commit comments