UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

1,087 lines 69.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataTypeApiHelper = void 0; const json_models_builders_1 = require("@umbraco/json-models-builders"); class DataTypeApiHelper { api; constructor(api) { this.api = api; } async get(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + id); return await response.json(); } async create(name, editorAlias, editorUiAlias, values, parentId, id) { const dataType = { "name": name, "editorAlias": editorAlias, "editorUiAlias": editorUiAlias, "values": values, "id": id, "parent": parentId ? { "id": parentId } : null }; const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/data-type', dataType); // Returns the id of the created dataType return response.headers().location.split("v1/data-type/").pop(); } async update(id, dataType) { const updateDataType = { "name": dataType.name, "editorAlias": dataType.editorAlias, "editorUiAlias": dataType.editorUiAlias, "values": dataType.values, }; return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + id, updateDataType); } async delete(id) { return await this.api.delete(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + id); } async getAllAtRoot() { return await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/tree/data-type/root?skip=0&take=10000&foldersOnly=false'); } async doesExist(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + id); return response.status() === 200; } async getItems(ids) { let idArray = 'id=' + ids[0]; let i; for (i = 1; i < ids.length; ++i) { idArray += '&id=' + ids[i]; } const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/tree/data-type/item?' + idArray); return await response.json(); } async getByName(name) { const rootDataTypes = await this.getAllAtRoot(); const jsonDataTypes = await rootDataTypes.json(); for (const dataType of jsonDataTypes.items) { if (dataType.name === name) { return this.get(dataType.id); } else if (dataType.isContainer || dataType.hasChildren) { const result = await this.recurseChildren(name, dataType.id, false); if (result) { return result; } } } return false; } async ensureNameNotExists(name) { const rootDataTypes = await this.getAllAtRoot(); const jsonDataTypes = await rootDataTypes.json(); for (const dataType of jsonDataTypes.items) { if (dataType.name === name) { if (dataType.isFolder) { return await this.recurseDeleteChildren(dataType); } return await this.delete(dataType.id); } else if (dataType.hasChildren) { await this.recurseChildren(name, dataType.id, true); } } return null; } async doesNameExist(name) { return await this.getByName(name); } async moveToFolder(dataTypeId, folderId) { const folderIdBody = { "target": { id: folderId } }; return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + dataTypeId + '/move', folderIdBody); } async copyToFolder(dataTypeId, folderId) { const folderIdBody = { "target": { id: folderId } }; const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/data-type/' + dataTypeId + '/copy', folderIdBody); // Returns the id of the copied dataType return response.headers().location.split("v1/data-type/").pop(); } // FOLDER async getFolder(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/data-type/folder/' + id); return await response.json(); } async createFolder(name, parentId, id) { const folderData = { "name": name, "id": id, "parent": parentId ? { "id": parentId } : null }; const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/data-type/folder', folderData); // Returns the id of the created dataTypeFolder return response.headers().location.split("v1/data-type/folder/").pop(); } async renameFolder(id, name) { const folderData = { "name": name, }; return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/data-type/folder/' + id, folderData); } async deleteFolder(id) { return await this.api.delete(this.api.baseUrl + '/umbraco/management/api/v1/data-type/folder/' + id); } async doesFolderExist(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/data-type/folder/' + id); return response.status() === 200; } async getChildren(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/tree/data-type/children?parentId=' + id + '&skip=0&take=100&foldersOnly=false'); const items = await response.json(); return items.items; } async recurseDeleteChildren(dataFolder) { if (!dataFolder.hasChildren) { return await this.deleteFolder(dataFolder.id); } const items = await this.getChildren(dataFolder.id); for (const child of items) { if (child.hasChildren) { await this.recurseDeleteChildren(child); } else if (child.isFolder) { await this.deleteFolder(child.id); } else { await this.delete(child.id); } } return await this.deleteFolder(dataFolder.id); } async recurseChildren(name, id, toDelete) { const items = await this.getChildren(id); for (const child of items) { if (child.name === name) { if (!toDelete) { if (child.isFolder) { return await this.getFolder(child.id); } return await this.get(child.id); } if (child.isFolder) { return await this.recurseDeleteChildren(child); } return await this.delete(child.id); } else if (child.hasChildren) { return await this.recurseChildren(name, child.id, toDelete); } } return false; } async save(dataType) { const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/data-type', dataType); return response.headers().location.split("v1/data-type/").pop(); } async createDefaultDateTimeDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.DatePickerDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createCheckboxListDataType(name, options = []) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.CheckboxListDataTypeBuilder() .withName(name) .withItems(options) .build(); return await this.save(dataType); } async createContentPickerDataTypeWithStartNode(name, startNodeId) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ContentPickerDataTypeBuilder() .withName(name) .withStartNodeId(startNodeId) .build(); return await this.save(dataType); } async createContentPickerDataTypeWithShowOpenButton(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ContentPickerDataTypeBuilder() .withName(name) .withShowOpenButton(true) .build(); return await this.save(dataType); } async createContentPickerDataTypeWithIgnoreUserStartNodes(name, startNodeId) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ContentPickerDataTypeBuilder() .withName(name) .withStartNodeId(startNodeId) .withIgnoreUserStartNodes(true) .build(); return await this.save(dataType); } async createDateTimeDataTypeWithDateFormat(name, dateFormat) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.DatePickerDataTypeBuilder() .withName(name) .withFormat(dateFormat) .build(); return await this.save(dataType); } async createDropdownDataType(name, isMultiple, options) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.DropdownDataTypeBuilder() .withName(name) .withMultiple(isMultiple) .withItems(options) .build(); return await this.save(dataType); } // BlockListEditor async createEmptyBlockListDataType(name) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .build(); return await this.save(blockList); } async createBlockListDataTypeWithABlock(name, contentElementTypeId) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(contentElementTypeId) .done() .build(); return await this.save(blockList); } async createBlockListDataTypeWithContentAndSettingsElementType(name, contentElementTypeId, settingsElementTypeId) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withSettingsElementTypeKey(settingsElementTypeId) .done() .build(); return await this.save(blockList); } async createBlockListDataTypeWithMinAndMaxAmount(name, minAmount = 0, maxAmount = 0) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .withMinValue(minAmount) .withMaxValue(maxAmount) .build(); return await this.save(blockList); } async createBlockListDataTypeWithSingleBlockMode(name, enabled) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .withSingleBlockMode(enabled) .build(); return await this.save(blockList); } async createBlockListDataTypeWithLiveEditingMode(name, enabled) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .withLiveEditing(enabled) .build(); return await this.save(blockList); } async createBlockListDataTypeWithInlineEditingMode(name, enabled) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .withInlineEditingAsDefault(enabled) .build(); return await this.save(blockList); } async createBlockListDataTypeWithPropertyEditorWidth(name, width) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .withMaxPropertyWidth(width) .build(); return await this.save(blockList); } async createBlockListWithBlockWithEditorAppearance(name, elementTypeId, label = '', overlaySize = 'small') { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(elementTypeId) .withLabel(label) .withEditorSize(overlaySize) .done() .build(); return await this.save(blockList); } async createBlockListWithBlockWithCatalogueAppearance(name, elementTypeId, backgroundColor = '', iconColor = '', customStylesheet = '') { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(elementTypeId) .withBackgroundColor(backgroundColor) .withIconColor(iconColor) .withStylesheet(customStylesheet) .done() .build(); return await this.save(blockList); } async createBlockListWithBlockWithHideContentEditor(name, elementTypeId, hideContentEditor) { await this.ensureNameNotExists(name); const blockList = new json_models_builders_1.BlockListDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(elementTypeId) .withHideContentEditor(hideContentEditor) .done() .build(); return await this.save(blockList); } async isSingleBlockModeEnabledForBlockList(blockListName, enabled) { const blockList = await this.getByName(blockListName); const singleBlockModeValue = blockList.values.find(value => value.alias === 'useSingleBlockMode'); return singleBlockModeValue?.value === enabled; } async isInlineEditingModeEnabledForBlockList(blockListName, enabled) { const blockList = await this.getByName(blockListName); const inlineEditingModeValue = blockList.values.find(value => value.alias === 'useInlineEditingAsDefault'); return inlineEditingModeValue?.value === enabled; } // Block Grid async createEmptyBlockGrid(blockGridName) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .build(); return await this.save(blockGrid); } async createBlockGridWithABlock(blockGridName, contentElementTypeId) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withAllowAtRoot(true) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithABlockInAGroup(blockGridName, contentElementTypeId, groupName) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlockGroup() .withName(groupName) .done() .addBlock() .withContentElementTypeKey(contentElementTypeId) .withGroupName(groupName) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithMinAndMaxAmount(blockGridName, minAmount = 0, maxAmount = 0) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withMinValue(minAmount) .withMaxValue(maxAmount) .build(); return await this.save(blockGrid); } async createBlockGridWithLiveEditingMode(blockGridName, enabled) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withLiveEditing(enabled) .build(); return await this.save(blockGrid); } async createBlockGridWithPropertyEditorWidth(blockGridName, width) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withMaxPropertyWidth(width) .build(); return await this.save(blockGrid); } async createBlockGridWithCreateButtonLabel(blockGridName, label = '') { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withCreateLabel(label) .build(); return await this.save(blockGrid); } async createBlockGridWithGridColumns(blockGridName, columns = 12) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withGridColumns(columns) .build(); return await this.save(blockGrid); } async createBlockGridWithLayoutStylesheet(blockGridName, stylesheetName) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .withLayoutStylesheet('/wwwroot/css/' + stylesheetName) .build(); return await this.save(blockGrid); } async createBlockGridWithAnAreaInABlock(blockGridName, contentElementTypeId, areaAlias = 'area', createButtonLabel = '', columnSpan = 6, rowSpan = 1, minAllowed = 0, maxAllowed = 2) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withAllowAtRoot(true) .addArea() .withAlias(areaAlias) .withCreateLabel(createButtonLabel) .withColumnSpan(columnSpan) .withRowSpan(rowSpan) .withMinAllowed(minAllowed) .withMaxAllowed(maxAllowed) .done() .done() .build(); return await this.save(blockGrid); } async createBlockGridWithAnAreaInABlockWithAllowInAreas(blockGridName, contentElementTypeId, areaAlias = 'area', allowInAreas = false, createButtonLabel = 'CreateLabel', columnSpan = 6, rowSpan = 1, minAllowed = 0, maxAllowed = 2) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withAllowAtRoot(true) .withAllowInAreas(allowInAreas) .addArea() .withAlias(areaAlias) .withCreateLabel(createButtonLabel) .withColumnSpan(columnSpan) .withRowSpan(rowSpan) .withMinAllowed(minAllowed) .withMaxAllowed(maxAllowed) .done() .done() .build(); return await this.save(blockGrid); } async createBlockGridWithAnAreaInABlockWithAllowInAreasAndASecondBlock(blockGridName, contentElementTypeId, secondContentElementTypeId, areaAlias = 'area', allowInAreas = false, createButtonLabel = 'CreateLabel', columnSpan = 6, rowSpan = 1, minAllowed = 0, maxAllowed = 2, secondBlockAllowAtRoot = true, secondBlockAllowInAreas = true) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withAllowAtRoot(true) .withAllowInAreas(allowInAreas) .addArea() .withAlias(areaAlias) .withCreateLabel(createButtonLabel) .withColumnSpan(columnSpan) .withRowSpan(rowSpan) .withMinAllowed(minAllowed) .withMaxAllowed(maxAllowed) .done() .done() .addBlock() .withContentElementTypeKey(secondContentElementTypeId) .withAllowAtRoot(secondBlockAllowAtRoot) .withAllowInAreas(secondBlockAllowInAreas) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithAnAreaInABlockWithACreateLabel(blockGridName, contentElementTypeId, createButtonLabel = '', areaAlias = 'area') { return await this.createBlockGridWithAnAreaInABlockWithAllowInAreas(blockGridName, contentElementTypeId, areaAlias, true, createButtonLabel); } async createBlockGridWithAnAreaInABlockWithColumnSpanAndRowSpan(blockGridName, contentElementTypeId, columnSpan = 6, rowSpan = 1, areaAlias = 'area', createButtonLabel = 'CreateLabel') { return await this.createBlockGridWithAnAreaInABlockWithAllowInAreas(blockGridName, contentElementTypeId, areaAlias, true, createButtonLabel, columnSpan, rowSpan); } async createBlockGridWithAnAreaInABlockWithMinAndMaxAllowed(blockGridName, contentElementTypeId, secondContentElementTypeId, minAllowed = 0, maxAllowed = 2, areaAlias = 'area', createButtonLabel = 'CreateLabel') { return await this.createBlockGridWithAnAreaInABlockWithAllowInAreasAndASecondBlock(blockGridName, contentElementTypeId, secondContentElementTypeId, areaAlias, true, createButtonLabel, 6, 1, minAllowed, maxAllowed); } async createBlockGridWithAdvancedSettingsInBlock(blockGridName, contentElementTypeId, customViewPath = '', customStylesheetPath = '', overlaySize = 'small', inlineEditing = false, hideContentEditor = false) { await this.ensureNameNotExists(blockGridName); const encodedViewPath = await this.api.stylesheet.encodeStylesheetPath(customViewPath); const encodedStylesheetPath = await this.api.stylesheet.encodeStylesheetPath(customStylesheetPath); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withView(encodedViewPath) .withStylesheet(encodedStylesheetPath) .withEditorSize(overlaySize) .withInlineEditing(inlineEditing) .withHideContentEditor(hideContentEditor) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithCatalogueAppearanceInBlock(blockGridName, contentElementTypeId, backgroundColor = '', iconColor = '', thumbnail = '') { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withBackgroundColor(backgroundColor) .withIconColor(iconColor) .withThumbnail(thumbnail) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithContentAndSettingsElementType(blockGridName, contentElementTypeId, settingsElementTypeId, allowAtRoot = true) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withSettingsElementTypeKey(settingsElementTypeId) .withAllowAtRoot(allowAtRoot) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithLabel(blockGridName, contentElementTypeId, label, allowAtRoot = true) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withLabel(label) .withAllowAtRoot(allowAtRoot) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithPermissions(blockGridName, contentElementTypeId, toAllowInRoot = false, toAllowInAreas = false) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .withAllowAtRoot(toAllowInRoot) .withAllowInAreas(toAllowInAreas) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithSizeOptions(blockGridName, contentElementTypeId, columnSpans = 0, minRowSpan = 0, maxRowSpan = 12) { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(contentElementTypeId) .addColumnSpanOptions(columnSpans) .withMinRowSpan(minRowSpan) .withMaxRowSpan(maxRowSpan) .done() .build(); return await this.save(blockGrid); } async createBlockGridWithABlockWithInlineEditingModeAndABlockWithAnArea(blockGridName, firstBlockElementTypeId, inlineEditing, secondBlockElementTypeId, areaAlias = 'area') { await this.ensureNameNotExists(blockGridName); const blockGrid = new json_models_builders_1.BlockGridDataTypeBuilder() .withName(blockGridName) .addBlock() .withContentElementTypeKey(firstBlockElementTypeId) .withInlineEditing(inlineEditing) .withAllowInAreas(true) .done() .addBlock() .withContentElementTypeKey(secondBlockElementTypeId) .withAllowAtRoot(true) .addArea() .withAlias(areaAlias) .withColumnSpan(12) .withRowSpan(1) .addSpecifiedAllowance() .withElementTypeKey(firstBlockElementTypeId) .done() .done() .done() .build(); return await this.save(blockGrid); } async getBlockGridAreaKeyFromBlock(blockGridName, elementTypeKey, areaAlias) { const blockGrid = await this.getByName(blockGridName); const blocksValue = blockGrid.values.find(value => value.alias === 'blocks'); const block = blocksValue.value.find(block => block.contentElementTypeKey === elementTypeKey); const area = block.areas.find(area => area.alias === areaAlias); return area.key; } async doesBlockEditorContainBlocksWithContentTypeIds(blockEditorName, elementTypeIds) { if (!elementTypeIds || elementTypeIds.length === 0) { return false; } const blockEditor = await this.getByName(blockEditorName); const blocksValue = blockEditor.values.find(value => value.alias === 'blocks'); if (!blocksValue || blocksValue.value.length === 0) { return false; } const contentElementTypeKeys = blocksValue.value.map(block => block.contentElementTypeKey); return elementTypeIds.every(id => contentElementTypeKeys.includes(id)); } async doesBlockEditorContainBlocksWithSettingsTypeIds(blockEditorName, elementTypeIds) { if (!elementTypeIds || elementTypeIds.length === 0) { return false; } const blockEditor = await this.getByName(blockEditorName); const blocksValue = blockEditor.values.find(value => value.alias === 'blocks'); if (!blocksValue || blocksValue.value.length === 0) { return false; } const settingsElementTypeKeys = blocksValue.value.map(block => block.settingsElementTypeKey); return elementTypeIds.every(id => settingsElementTypeKeys.includes(id)); } async isLiveEditingModeEnabledForBlockEditor(blockEditorName, enabled) { const blockEditor = await this.getByName(blockEditorName); const liveEditingModeValue = blockEditor.values.find(value => value.alias === 'useLiveEditing'); return liveEditingModeValue?.value === enabled; } async doesMaxPropertyContainWidthForBlockEditor(blockEditorName, width) { const blockEditor = await this.getByName(blockEditorName); const maxPropertyWidthValue = blockEditor.values.find(value => value.alias === 'maxPropertyWidth'); return maxPropertyWidthValue?.value === width; } async doesBlockEditorBlockContainLabel(blockName, elementTypeKey, label) { const block = await this.getBlockWithContentElementTypeId(blockName, elementTypeKey); return block.label === label; } async doesBlockGridGroupContainCorrectBlocks(blockGridName, groupName, elementTypeIds) { if (!elementTypeIds || elementTypeIds.length === 0) { return false; } const blockEditor = await this.getByName(blockGridName); // We need to get the GroupKey, so we can use it to find the blocks that use the Key. const blockGroupsValue = blockEditor.values.find(value => value.alias === 'blockGroups'); if (!blockGroupsValue || blockGroupsValue.value.length === 0) { return false; } const blockGroupKey = blockGroupsValue.value.find(blockGroup => blockGroup.name === groupName).key; const blocksValue = blockEditor.values.find(value => value.alias === 'blocks'); if (!blocksValue || blocksValue.value.length === 0) { return false; } const blocksWithGroupKey = blocksValue.value.filter(block => block.groupKey === blockGroupKey); return elementTypeIds.every(id => blocksWithGroupKey.some(block => block.contentElementTypeKey === id)); } async doesBlockGridContainCreateButtonLabel(blockGridName, label) { const blockEditor = await this.getByName(blockGridName); const createLabelValue = blockEditor.values.find(value => value.alias === 'createLabel'); return createLabelValue?.value === label; } async doesBlockGridContainGridColumns(blockGridName, columns) { const blockEditor = await this.getByName(blockGridName); const gridColumnsValue = blockEditor.values.find(value => value.alias === 'gridColumns'); return gridColumnsValue?.value === columns; } async doesBlockEditorBlockHaveAllowInRootEnabled(blockGridName, elementTypeKey) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.allowAtRoot; } async doesBlockEditorBlockHaveAllowInAreasEnabled(blockGridName, elementTypeKey) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.allowInAreas; } async doesBlockEditorBlockContainColumnSpanOptions(blockGridName, elementTypeKey, expectedColumnSpans) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); // If the block does not have any columnSpanOptions, and we are not expecting any, return true if (block.columnSpanOptions.length === 0 && expectedColumnSpans.length === 0) { return true; } const columnSpans = block.columnSpanOptions.map(option => option.columnSpan); return expectedColumnSpans.every(span => columnSpans.includes(span)) && columnSpans.every(span => expectedColumnSpans.includes(span)); } async doesBlockEditorBlockContainRowSpanOptions(blockGridName, elementTypeKey, minRowSpan, maxRowSpan) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.rowMinSpan === minRowSpan && block.rowMaxSpan === maxRowSpan; } async doesBlockEditorBlockContainAreaGridColumns(blockGridName, elementTypeKey, areaGridColumns) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areaGridColumns === areaGridColumns; } async doesBlockEditorBlockContainAreaWithAlias(blockGridName, elementTypeKey, areaAlias = 'area') { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areas.find(area => area.alias === areaAlias); } async doesBlockEditorBlockContainAreaCount(blockGridName, elementTypeKey, areaCount) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areas.length === areaCount; } async doesBlockEditorBlockContainAreaWithCreateButtonLabel(blockGridName, elementTypeKey, areaAlias = 'area', createButtonLabel) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areas.find(area => area.createLabel === createButtonLabel && area.alias === areaAlias); } async doesBlockEditorBlockContainAreaWithMinAllowed(blockGridName, elementTypeKey, areaAlias = 'area', minAllowed) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areas.find(area => area.minAllowed === minAllowed && area.alias === areaAlias); } async doesBlockEditorBlockContainAreaWithMaxAllowed(blockGridName, elementTypeKey, areaAlias = 'area', maxAllowed) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.areas.find(area => area.maxAllowed === maxAllowed && area.alias === areaAlias); } async doesBlockEditorBlockContainStylesheet(blockGridName, elementTypeKey, stylesheetPath) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); const encodedSecondStylesheetPath = await this.api.stylesheet.encodeStylesheetPath(stylesheetPath); return block.stylesheet[0] === encodedSecondStylesheetPath; } async doesBlockEditorBlockContainOverlaySize(blockGridName, elementTypeKey, overlaySize) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.editorSize === overlaySize; } async doesBlockEditorBlockContainInlineEditing(blockGridName, elementTypeKey, inlineEditing) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.inlineEditing === inlineEditing; } async doesBlockEditorBlockContainHideContentEditor(blockGridName, elementTypeKey, hideContentEditor) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.hideContentEditor === hideContentEditor; } async doesBlockEditorBlockContainBackgroundColor(blockGridName, elementTypeKey, backgroundColor) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.backgroundColor === backgroundColor; } async doesBlockEditorBlockContainIconColor(blockGridName, elementTypeKey, iconColor) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.iconColor === iconColor; } async doesBlockEditorBlockContainThumbnail(blockGridName, elementTypeKey, thumbnail) { const block = await this.getBlockWithContentElementTypeId(blockGridName, elementTypeKey); return block.thumbnail === thumbnail; } async getBlockWithContentElementTypeId(blockGridName, contentElementTypeKey) { const blockEditor = await this.getByName(blockGridName); const blocks = blockEditor.values.find(value => value.alias === 'blocks'); return blocks.value.find(block => block.contentElementTypeKey === contentElementTypeKey); } async createImageCropperDataTypeWithOneCrop(name, cropLabel, cropWidth, cropHeight) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ImageCropperDataTypeBuilder() .withName(name) .addCrop() .withLabel(cropLabel) .withAlias(json_models_builders_1.AliasHelper.toAlias(cropLabel)) .withHeight(cropHeight) .withWidth(cropWidth) .done() .build(); return await this.save(dataType); } async createMediaPickerDataTypeWithStartNodeId(name, startNodeId) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.MediaPickerDataTypeBuilder() .withName(name) .withStartNodeId(startNodeId) .withIgnoreUserStartNodes(false) .build(); return await this.save(dataType); } async createRadioboxDataType(name, options = []) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.RadioboxDataTypeBuilder() .withName(name) .withItems(options) .build(); return await this.save(dataType); } async createImageMediaPickerDataType(name, minValue = 0, maxValue = 1, enableLocalFocalPoint = false, ignoreUserStartNodes = false) { await this.ensureNameNotExists(name); const mediaType = await this.api.mediaType.getByName('Image'); const dataType = new json_models_builders_1.MediaPickerDataTypeBuilder() .withName(name) .withFilter(mediaType.id) .withMultiple(false) .withMinValue(minValue) .withMaxValue(maxValue) .withEnableLocalFocalPoint(enableLocalFocalPoint) .withIgnoreUserStartNodes(ignoreUserStartNodes) .build(); return await this.save(dataType); } async createImageMediaPickerDataTypeWithStartNodeId(name, startNodeId) { await this.ensureNameNotExists(name); const mediaType = await this.api.mediaType.getByName('Image'); const dataType = new json_models_builders_1.MediaPickerDataTypeBuilder() .withName(name) .withFilter(mediaType.id) .withStartNodeId(startNodeId) .build(); return await this.save(dataType); } async createImageMediaPickerDataTypeWithCrop(name, label, width, height) { await this.ensureNameNotExists(name); const mediaType = await this.api.mediaType.getByName('Image'); const dataType = new json_models_builders_1.MediaPickerDataTypeBuilder() .withName(name) .withFilter(mediaType.id) .addCrop() .withLabel(label) .withAlias(json_models_builders_1.AliasHelper.toAlias(label)) .withHeight(height) .withWidth(width) .done() .build(); return await this.save(dataType); } async createTextareaDataType(name, maxChars = 0, rows = 0, minHeight = 0, maxHeight = 0) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TextAreaDataTypeBuilder() .withName(name) .withMaxChars(maxChars) .withRows(rows) .withMinHeight(minHeight) .withMaxHeight(maxHeight) .build(); return await this.save(dataType); } async createTextstringDataType(name, maxChars = 0) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TextStringDataTypeBuilder() .withName(name) .withMaxChars(maxChars) .build(); return await this.save(dataType); } async createTrueFalseDataTypeWithInitialState(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TrueFalseDataTypeBuilder() .withName(name) .withIsDefault(true) .build(); return await this.save(dataType); } async createTrueFalseDataTypeWithLabelOn(name, labelOn) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TrueFalseDataTypeBuilder() .withName(name) .withShowLabels(true) .withLabelOn(labelOn) .build(); return await this.save(dataType); } async createTrueFalseDataTypeWithLabelOff(name, labelOff) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TrueFalseDataTypeBuilder() .withName(name) .withShowLabels(true) .withLabelOff(labelOff) .build(); return await this.save(dataType); } async createEmailAddressDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.EmailAddressDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createCodeEditorDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.CodeEditorDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createMarkdownEditorDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.MarkdownEditorDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createDecimalDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.DecimalDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createMultipleTextStringDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.MultipleTextStringDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createSliderDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.SliderDataTypeBuilder() .withName(name) .withMaxValue(100) .withStep(1) .build(); return await this.save(dataType); } // List View - Content data type async createListViewContentDataType(name = 'List View - Content Test') { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ListViewDataTypeBuilder() .withName(name) .withPageSize(100) .addLayout() .withName('List') .withIcon('icon-list') .withCollectionView('Umb.CollectionView.Document.Table') .done() .addLayout() .withName('Grid') .withIcon('icon-grid') .withCollectionView('Umb.CollectionView.Document.Grid') .done() .addColumnDisplayedProperty() .withAlias('updateDate') .withHeader('Last edited') .withIsSystem(true) .done() .addColumnDisplayedProperty() .withAlias('creator') .withHeader('Updated by') .withIsSystem(true) .done() .build(); return await this.save(dataType); } async createListViewContentDataTypeWithAllPermissions(name = 'List View - Content Test') { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ListViewDataTypeBuilder() .withName(name) .withPageSize(100) .addLayout() .withName('List') .withIcon('icon-list') .withCollectionView('Umb.CollectionView.Document.Table') .done() .addLayout() .withName('Grid') .withIcon('icon-grid') .withCollectionView('Umb.CollectionView.Document.Grid') .done() .addColumnDisplayedProperty() .withAlias('updateDate') .withHeader('Last edited') .done() .addColumnDisplayedProperty() .withAlias('creator') .withHeader('Updated by') .done() .addBulkActionPermissions() .withAllowBulkCopy(true) .withAllowBulkDelete(true) .withAllowBulkMove(true) .withAllowBulkPublish(true) .withAllowBulkUnPublish(true) .done() .build(); return await this.save(dataType); } // List View - Media data type async updateListViewMediaDataType(alias, newValue) { const listViewMediaData = await this.getByName('List View - Media'); const valueData = listViewMediaData.values.find(value => value.alias === alias); if (valueData) { valueData.value = newValue; } else { listViewMediaData.values.push({ "alias": alias, "value": newValue }); } return await this.update(listViewMediaData.id, listViewMediaData); } async createDefaultTiptapDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TiptapDataTypeBuilder() .withName(name) .build(); return await this.save(dataType); } async createTipTapDataTypeWithABlock(name, contentElementTypeKey) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TiptapDataTypeBuilder() .withName(name) .addBlock() .withContentElementTypeKey(contentElementTypeKey) .done() .addToolbarRow() .addToolbarGroup() .withBlockPicker(true) .done() .done() .addExtension() .withBlock(true) .done() .build(); return await this.save(dataType); } ; async createApprovedColorDataTypeWithOneItem(name, itemLabel, itemValue) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.ApprovedColorDataTypeBuilder() .withName(name) .withUseLabel(true) .addItem() .withLabel(itemLabel) .withValue(itemValue) .done() .build(); return await this.save(dataType); } async getTiptapExtensionsCount(tipTapName) { const tipTapData = await this.getByName(tipTapName); const extensionsValue = tipTapData.values.find(value => value.alias === 'extensions'); return extensionsValue?.value.length; } async getTiptapToolbarGroupInRowCount(tipTapName, rowIndex = 0) { const tipTapData = await this.getByName(tipTapName); const toolbarValue = tipTapData.values.find(value => value.alias === 'toolbar'); return toolbarValue?.value[rowIndex].length; } async getTiptapToolbarGroupValueInRow(tipTapName, groupIndex, rowIndex = 0) { const tipTapData = await this.getByName(tipTapName); const toolbarValue = tipTapData.values.find(value => value.alias === 'toolbar'); return toolbarValue?.value[rowIndex][groupIndex]; } async getTiptapToolbarRowCount(tipTapName) { const tipTapData = await this.getByName(tipTapName); const toolbarValue = tipTapData.values.find(value => value.alias === 'toolbar'); return toolbarValue?.value.length; } async createDefaultTinyMCEDataType(name) { await this.ensureNameNotExists(name); const dataType = new json_models_builders_1.TinyMCEDataTypeBuilder() .withName(name) .addToolbar() .withStyles(true) .withBold(true) .withItalic(true) .withAlignLeft(true) .withAlignCenter(true) .withAlignRight(true) .withBulList(true) .withNumList(true) .withOutdent(true) .withIndent(true) .withSourceCode(true) .withLink(true) .withUmbEmbedDialog(true) .withUmbMediaPicker(true) .done() .withEditorMode('Classic') .withMaxImageSize(500) .build(); return await this.save(dataType); } async getTinyMCEToolbarItemsCount(tinyMCEName) { const tinyMCEData = await this.getByName(tinyMCEName); const toolbarValue = tinyMCEData.values.find(value => value.alias === 'toolbar'); return toolbarValue?.value.length; } async doesTinyMCEToolbarItemsMatchCount(tinyMCEName, count) { const tinyMCEData = await this.getByName(tin