|
| 1 | +import {AliasHelper, ConstantHelper, NotificationConstantHelper, test} from '@umbraco/playwright-testhelpers'; |
| 2 | +import {expect} from "@playwright/test"; |
| 3 | + |
| 4 | +// Content Name |
| 5 | +const contentName = 'ContentName'; |
| 6 | + |
| 7 | +// Document Type |
| 8 | +const documentTypeName = 'DocumentTypeName'; |
| 9 | +let documentTypeId = null; |
| 10 | +const documentTypeGroupName = 'DocumentGroup'; |
| 11 | + |
| 12 | +// Block Grid |
| 13 | +const blockGridDataTypeName = 'BlockGridName'; |
| 14 | +let blockGridDataTypeId = null; |
| 15 | + |
| 16 | +// Text String |
| 17 | +const textStringElementTypeName = 'TextStringElementName'; |
| 18 | +let textStringElementTypeId = null; |
| 19 | +let textStringGroupName = 'TextGroup'; |
| 20 | +const textStringDataTypeName = 'Textstring'; |
| 21 | + |
| 22 | +test.beforeEach(async ({umbracoApi}) => { |
| 23 | + await umbracoApi.document.ensureNameNotExists(contentName); |
| 24 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 25 | + await umbracoApi.dataType.ensureNameNotExists(blockGridDataTypeName); |
| 26 | +}); |
| 27 | + |
| 28 | +test.afterEach(async ({umbracoApi}) => { |
| 29 | + await umbracoApi.document.ensureNameNotExists(contentName); |
| 30 | + await umbracoApi.documentType.ensureNameNotExists(documentTypeName); |
| 31 | + await umbracoApi.dataType.ensureNameNotExists(blockGridDataTypeName); |
| 32 | +}); |
| 33 | + |
| 34 | +test('can publish a block grid editor with a rich text editor', async ({umbracoApi, umbracoUi}) => { |
| 35 | + // Arrange |
| 36 | + const richTextEditorValue = 'Hello World'; |
| 37 | + const expectedRichTextEditorOutputValue = '<p>Hello World</p>'; |
| 38 | + const richTextDataTypeName = 'RichTextDataTypeName'; |
| 39 | + const richTextElementTypeName = 'RichTextElementName'; |
| 40 | + const richTextElementGroupName = 'RichTextElementGroupName'; |
| 41 | + await umbracoApi.dataType.ensureNameNotExists(richTextDataTypeName); |
| 42 | + await umbracoApi.documentType.ensureNameNotExists(richTextElementTypeName); |
| 43 | + |
| 44 | + const richTextEditorDataTypeId = await umbracoApi.dataType.createDefaultTiptapDataType(richTextDataTypeName); |
| 45 | + const richTextElementTypeId = await umbracoApi.documentType.createDefaultElementType(richTextElementTypeName, richTextElementGroupName, richTextDataTypeName, richTextEditorDataTypeId); |
| 46 | + blockGridDataTypeId = await umbracoApi.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, richTextElementTypeId, true); |
| 47 | + documentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, documentTypeGroupName); |
| 48 | + await umbracoApi.document.createDefaultDocument(contentName, documentTypeId); |
| 49 | + await umbracoUi.goToBackOffice(); |
| 50 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 51 | + await umbracoUi.content.goToContentWithName(contentName); |
| 52 | + |
| 53 | + // Act |
| 54 | + await umbracoUi.content.clickAddBlockElementButton(); |
| 55 | + await umbracoUi.content.clickBlockCardWithName(richTextElementTypeName, true); |
| 56 | + await umbracoUi.content.enterRTETipTapEditor(richTextEditorValue); |
| 57 | + await umbracoUi.content.clickCreateModalButton(); |
| 58 | + await umbracoUi.content.clickSaveAndPublishButton(); |
| 59 | + |
| 60 | + // Assert |
| 61 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.saved); |
| 62 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.published); |
| 63 | + // Asserts that the value in the RTE is as expected |
| 64 | + const documentData = await umbracoApi.document.getByName(contentName); |
| 65 | + const documentValues = documentData.values.find(value => value.alias === AliasHelper.toAlias(blockGridDataTypeName)); |
| 66 | + expect(documentValues.value.contentData[0].values[0].value.markup).toContain(expectedRichTextEditorOutputValue); |
| 67 | + |
| 68 | + // Clean |
| 69 | + await umbracoApi.dataType.ensureNameNotExists(richTextDataTypeName); |
| 70 | + await umbracoApi.documentType.ensureNameNotExists(richTextElementTypeName); |
| 71 | +}); |
| 72 | + |
| 73 | +test('can publish a block grid editor with a block list editor', async ({umbracoApi, umbracoUi}) => { |
| 74 | + // Arrange |
| 75 | + const textStringValue = 'Hello World'; |
| 76 | + const blockListDataTypeName = 'BlockListName'; |
| 77 | + const blockListElementTypeName = 'BlockListElementName'; |
| 78 | + const blockListElementGroupName = 'BlockListElementGroupName'; |
| 79 | + await umbracoApi.dataType.ensureNameNotExists(blockListDataTypeName); |
| 80 | + await umbracoApi.documentType.ensureNameNotExists(textStringElementTypeName); |
| 81 | + await umbracoApi.documentType.ensureNameNotExists(blockListElementTypeName); |
| 82 | + |
| 83 | + const textStringDataType = await umbracoApi.dataType.getByName(textStringDataTypeName); |
| 84 | + textStringElementTypeId = await umbracoApi.documentType.createDefaultElementType(textStringElementTypeName, textStringGroupName, textStringDataTypeName, textStringDataType.id); |
| 85 | + const blockListDataTypeId = await umbracoApi.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, textStringElementTypeId); |
| 86 | + const blockListElementTypeId = await umbracoApi.documentType.createDefaultElementType(blockListElementTypeName, blockListElementGroupName, blockListDataTypeName, blockListDataTypeId); |
| 87 | + blockGridDataTypeId = await umbracoApi.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, blockListElementTypeId, true); |
| 88 | + documentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, documentTypeGroupName); |
| 89 | + await umbracoApi.document.createDefaultDocument(contentName, documentTypeId); |
| 90 | + await umbracoUi.goToBackOffice(); |
| 91 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 92 | + await umbracoUi.content.goToContentWithName(contentName); |
| 93 | + |
| 94 | + // Act |
| 95 | + await umbracoUi.content.clickAddBlockElementButton(); |
| 96 | + await umbracoUi.content.clickBlockCardWithName(blockListElementTypeName, true); |
| 97 | + await umbracoUi.content.clickAddBlockWithNameButton(textStringElementTypeName); |
| 98 | + await umbracoUi.content.clickBlockCardWithName(textStringElementTypeName, true); |
| 99 | + await umbracoUi.content.enterTextstring(textStringValue); |
| 100 | + await umbracoUi.content.clickCreateForModalWithHeadline('Add ' + textStringElementTypeName); |
| 101 | + await umbracoUi.content.clickCreateModalButton(); |
| 102 | + await umbracoUi.content.clickSaveAndPublishButton(); |
| 103 | + |
| 104 | + // Assert |
| 105 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.saved); |
| 106 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.published); |
| 107 | + // Asserts that the value in the BlockList is as expected |
| 108 | + const documentData = await umbracoApi.document.getByName(contentName); |
| 109 | + const documentValues = documentData.values.find(value => value.alias === AliasHelper.toAlias(blockGridDataTypeName)); |
| 110 | + expect(documentValues.value.contentData[0].values[0].value.contentData[0].values[0].value).toContain(textStringValue); |
| 111 | + |
| 112 | + // Clean |
| 113 | + await umbracoApi.dataType.ensureNameNotExists(blockListDataTypeName); |
| 114 | + await umbracoApi.documentType.ensureNameNotExists(textStringElementTypeName); |
| 115 | + await umbracoApi.documentType.ensureNameNotExists(blockListElementTypeName); |
| 116 | +}); |
| 117 | + |
| 118 | +test('can publish a block grid editor with a block grid editor', async ({umbracoApi, umbracoUi}) => { |
| 119 | + // Arrange |
| 120 | + const textStringValue = 'Hello World'; |
| 121 | + const secondBlockGridDataTypeName = 'SecondBlockGridDataTypeName'; |
| 122 | + const blockGridElementTypeName = 'BlockGridElementTypeName'; |
| 123 | + const blockGridElementGroupName = 'BlockGridElementGroupName'; |
| 124 | + await umbracoApi.dataType.ensureNameNotExists(secondBlockGridDataTypeName); |
| 125 | + await umbracoApi.documentType.ensureNameNotExists(textStringElementTypeName); |
| 126 | + await umbracoApi.documentType.ensureNameNotExists(blockGridElementTypeName); |
| 127 | + |
| 128 | + const textStringDataType = await umbracoApi.dataType.getByName(textStringDataTypeName); |
| 129 | + textStringElementTypeId = await umbracoApi.documentType.createDefaultElementType(textStringElementTypeName, textStringGroupName, textStringDataTypeName, textStringDataType.id); |
| 130 | + const secondBlockGridDataTypeId = await umbracoApi.dataType.createBlockGridWithABlockAndAllowAtRoot(secondBlockGridDataTypeName, textStringElementTypeId); |
| 131 | + const blockGridElementTypeId = await umbracoApi.documentType.createDefaultElementType(blockGridElementTypeName, blockGridElementGroupName, secondBlockGridDataTypeName, secondBlockGridDataTypeId); |
| 132 | + blockGridDataTypeId = await umbracoApi.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, blockGridElementTypeId, true); |
| 133 | + documentTypeId = await umbracoApi.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, documentTypeGroupName); |
| 134 | + await umbracoApi.document.createDefaultDocument(contentName, documentTypeId); |
| 135 | + await umbracoUi.goToBackOffice(); |
| 136 | + await umbracoUi.content.goToSection(ConstantHelper.sections.content); |
| 137 | + await umbracoUi.content.goToContentWithName(contentName); |
| 138 | + |
| 139 | + // Act |
| 140 | + await umbracoUi.content.clickAddBlockElementButton(); |
| 141 | + await umbracoUi.content.clickBlockCardWithName(blockGridElementTypeName, true); |
| 142 | + await umbracoUi.content.clickAddBlockWithNameButton(textStringElementTypeName); |
| 143 | + await umbracoUi.content.clickBlockCardWithName(textStringElementTypeName, true); |
| 144 | + await umbracoUi.content.enterTextstring(textStringValue); |
| 145 | + await umbracoUi.content.clickCreateForModalWithHeadline('Add ' + textStringElementTypeName); |
| 146 | + await umbracoUi.content.clickCreateModalButton(); |
| 147 | + await umbracoUi.content.clickSaveAndPublishButton(); |
| 148 | + |
| 149 | + // Assert |
| 150 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.saved); |
| 151 | + await umbracoUi.content.doesSuccessNotificationHaveText(NotificationConstantHelper.success.published); |
| 152 | + // Asserts that the value in the BlockGrid is as expected |
| 153 | + const documentData = await umbracoApi.document.getByName(contentName); |
| 154 | + const documentValues = documentData.values.find(value => value.alias === AliasHelper.toAlias(blockGridDataTypeName)); |
| 155 | + expect(documentValues.value.contentData[0].values[0].value.contentData[0].values[0].value).toContain(textStringValue); |
| 156 | + |
| 157 | + // Clean |
| 158 | + await umbracoApi.dataType.ensureNameNotExists(secondBlockGridDataTypeName); |
| 159 | + await umbracoApi.documentType.ensureNameNotExists(textStringElementTypeName); |
| 160 | + await umbracoApi.documentType.ensureNameNotExists(blockGridElementTypeName); |
| 161 | +}); |
0 commit comments