Skip to content

Commit 61a47e3

Browse files
authored
V17 Updated test helper for document with both variant and invariant blocks (#343)
* Updated ui helper for block list properties * Updated api helper for creating a document type with variant and invariant block lists * Bumped version * Removed params desscription * Removed unused comment
1 parent 41881da commit 61a47e3

File tree

4 files changed

+153
-3
lines changed

4 files changed

+153
-3
lines changed

lib/helpers/ContentUiHelper.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export class ContentUiHelper extends UiBaseLocators {
177177
private readonly hostNameItem: Locator;
178178
private readonly languageToggle: Locator;
179179
private readonly contentVariantDropdown: Locator;
180+
private readonly blockProperty: Locator;
180181

181182
constructor(page: Page) {
182183
super(page);
@@ -365,6 +366,7 @@ export class ContentUiHelper extends UiBaseLocators {
365366
this.entityPickerTree = page.locator('umb-tree[alias="Umb.Tree.EntityDataPicker"]');
366367
this.languageToggle = page.getByTestId('input:entity-name').locator('#toggle');
367368
this.contentVariantDropdown = page.locator('umb-document-workspace-split-view-variant-selector uui-popover-container #dropdown');
369+
this.blockProperty = page.locator('umb-block-workspace-view-edit-property');
368370
}
369371

370372
async enterContentName(name: string) {
@@ -1813,4 +1815,34 @@ export class ContentUiHelper extends UiBaseLocators {
18131815
await languageOptionLocator.click();
18141816
await expect(languageOptionLocator).toContainClass('selected');
18151817
}
1818+
1819+
async clickAddBlockListElementWithName(blockName: string) {
1820+
const createNewButtonLocator = this.page.getByTestId('property:' + blockName.toLowerCase()).getByLabel('Create new');
1821+
await expect(createNewButtonLocator).toBeVisible();
1822+
await createNewButtonLocator.click();
1823+
}
1824+
1825+
async isAddBlockListElementWithNameDisabled(blockName: string) {
1826+
const createNewButtonLocator = this.page.getByTestId('property:' + blockName.toLowerCase()).locator('uui-button[label="Create new"]');
1827+
await expect(createNewButtonLocator).toHaveAttribute('disabled');
1828+
}
1829+
1830+
async isAddBlockListElementWithNameVisible(blockName: string) {
1831+
const createNewButtonLocator = this.page.getByTestId('property:' + blockName.toLowerCase()).locator('uui-button[label="Create new"]');
1832+
await expect(createNewButtonLocator).toBeVisible();
1833+
await expect(createNewButtonLocator).not.toHaveAttribute('disabled');
1834+
}
1835+
1836+
async enterBlockPropertyValue(propertyName: string, value: string) {
1837+
const property = this.blockProperty.filter({hasText: propertyName});
1838+
await expect(property).toBeVisible();
1839+
await property.locator('input').clear();
1840+
await property.locator('input').fill(value);
1841+
}
1842+
1843+
async isBlockPropertyEditable(propertyName: string, isEditable: boolean = true) {
1844+
const propertyLocator = this.blockProperty.filter({hasText: propertyName}).locator('#input');
1845+
await expect(propertyLocator).toBeVisible();
1846+
await expect(propertyLocator).toBeEditable({editable: isEditable});
1847+
}
18161848
}

lib/helpers/DocumentTypeApiHelper.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,4 +810,122 @@ export class DocumentTypeApiHelper {
810810
return null;
811811
}
812812
}
813+
814+
async createElementTypeWithTwoPropertyEditors(elementTypeName: string, firstDataTypeName: string, firstDataTypeId: string, secondDataTypeName: string, secondDataTypeId: string, elementTypeVaryByCulture: boolean = false, firstPropertyVaryByCulture: boolean = false, secondPropertyVaryByCulture: boolean = false) {
815+
const crypto = require('crypto');
816+
await this.ensureNameNotExists(elementTypeName);
817+
818+
const containerId = crypto.randomUUID();
819+
const elementType = new DocumentTypeBuilder()
820+
.withName(elementTypeName)
821+
.withAlias(AliasHelper.toAlias(elementTypeName))
822+
.withIsElement(true)
823+
.withVariesByCulture(elementTypeVaryByCulture)
824+
.withIcon("icon-plugin")
825+
.addContainer()
826+
.withName('Content')
827+
.withId(containerId)
828+
.withType("Group")
829+
.done()
830+
.addProperty()
831+
.withContainerId(containerId)
832+
.withAlias(AliasHelper.toAlias(firstDataTypeName))
833+
.withName(firstDataTypeName)
834+
.withDataTypeId(firstDataTypeId)
835+
.withVariesByCulture(firstPropertyVaryByCulture)
836+
.done()
837+
.addProperty()
838+
.withContainerId(containerId)
839+
.withAlias(AliasHelper.toAlias(secondDataTypeName))
840+
.withName(secondDataTypeName)
841+
.withDataTypeId(secondDataTypeId)
842+
.withVariesByCulture(secondPropertyVaryByCulture)
843+
.done()
844+
.build();
845+
846+
return await this.create(elementType);
847+
}
848+
849+
/**
850+
* Creates a document type with variant and invariant block lists for testing multilingual scenarios.
851+
*
852+
* Structure created:
853+
* - Document Type (Vary by culture)
854+
* - Text 1 (Vary by culture)
855+
* - Text 2 (Shared)
856+
* - Block List 1 (Vary by culture) - contains Block 1 and Block 2
857+
* - Block List 2 (Shared) - contains Block 1 and Block 2
858+
*
859+
* - Block 1 Element Type (Vary by culture)
860+
* - Text 1 (Vary by culture)
861+
* - Text 2 (Shared)
862+
*
863+
* - Block 2 Element Type (Shared/Invariant)
864+
* - Text 1
865+
* - Text 2
866+
*/
867+
async createDocumentTypeWithVariantAndInvariantBlockLists(documentTypeName: string, firstDataTypeName: string, firstDataTypeId: string, secondDataTypeName: string, secondDataTypeId: string, blockList1DataTypeName: string, blockList2DataTypeName: string, block1ElementTypeName: string, block2ElementTypeName: string) {
868+
const crypto = require('crypto');
869+
await this.ensureNameNotExists(documentTypeName);
870+
871+
// Create Block 1 Element Type (Vary by culture) with first property (vary by culture) and second property (shared)
872+
const block1ElementTypeId = await this.createElementTypeWithTwoPropertyEditors(block1ElementTypeName, firstDataTypeName, firstDataTypeId, secondDataTypeName, secondDataTypeId, true, true, false) as string;
873+
874+
// Create Block 2 Element Type (Shared/Invariant) with first property and second property
875+
const block2ElementTypeId = await this.createElementTypeWithTwoPropertyEditors(block2ElementTypeName, firstDataTypeName, firstDataTypeId, secondDataTypeName, secondDataTypeId, false, false, false) as string;
876+
877+
// Create Block List 1 Data Type (will be used with vary by culture property)
878+
const blockList1DataTypeId = await this.api.dataType.createBlockListDataTypeWithTwoBlocks(blockList1DataTypeName, block1ElementTypeId, block2ElementTypeId) as string;
879+
880+
// Create Block List 2 Data Type (will be used with shared property)
881+
const blockList2DataTypeId = await this.api.dataType.createBlockListDataTypeWithTwoBlocks(blockList2DataTypeName, block1ElementTypeId, block2ElementTypeId) as string;
882+
883+
// Create Document Type (Vary by culture)
884+
const containerId = crypto.randomUUID();
885+
const documentType = new DocumentTypeBuilder()
886+
.withName(documentTypeName)
887+
.withAlias(AliasHelper.toAlias(documentTypeName))
888+
.withAllowedAsRoot(true)
889+
.withVariesByCulture(true)
890+
.addContainer()
891+
.withName('Content')
892+
.withId(containerId)
893+
.withType("Group")
894+
.done()
895+
.addProperty()
896+
.withContainerId(containerId)
897+
.withAlias(AliasHelper.toAlias(firstDataTypeName))
898+
.withName(firstDataTypeName)
899+
.withDataTypeId(firstDataTypeId)
900+
.withVariesByCulture(true)
901+
.withSortOrder(0)
902+
.done()
903+
.addProperty()
904+
.withContainerId(containerId)
905+
.withAlias(AliasHelper.toAlias(secondDataTypeName))
906+
.withName(secondDataTypeName)
907+
.withDataTypeId(secondDataTypeId)
908+
.withVariesByCulture(false)
909+
.withSortOrder(1)
910+
.done()
911+
.addProperty()
912+
.withContainerId(containerId)
913+
.withAlias(AliasHelper.toAlias(blockList1DataTypeName))
914+
.withName(blockList1DataTypeName)
915+
.withDataTypeId(blockList1DataTypeId)
916+
.withVariesByCulture(true)
917+
.withSortOrder(2)
918+
.done()
919+
.addProperty()
920+
.withContainerId(containerId)
921+
.withAlias(AliasHelper.toAlias(blockList2DataTypeName))
922+
.withName(blockList2DataTypeName)
923+
.withDataTypeId(blockList2DataTypeId)
924+
.withVariesByCulture(false)
925+
.withSortOrder(3)
926+
.done()
927+
.build();
928+
929+
return await this.create(documentType);
930+
}
813931
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@umbraco/playwright-testhelpers",
3-
"version": "17.0.15",
3+
"version": "17.0.16",
44
"description": "Test helpers for making playwright tests for Umbraco solutions",
55
"main": "dist/lib/index.js",
66
"files": [

0 commit comments

Comments
 (0)