UNPKG

@umbraco/playwright-testhelpers

Version:

Test helpers for making playwright tests for Umbraco solutions

1,087 lines (1,086 loc) 70.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DocumentApiHelper = void 0; const AliasHelper_1 = require("./AliasHelper"); const json_models_builders_1 = require("@umbraco/json-models-builders"); class DocumentApiHelper { api; constructor(api) { this.api = api; } async get(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id); return await response.json(); } async doesExist(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id); return response.status() === 200; } async create(document) { if (document == null) { return; } const response = await this.api.post(this.api.baseUrl + '/umbraco/management/api/v1/document', document); return response.headers().location.split("v1/document/").pop(); } async delete(id) { if (id == null) { return; } const response = await this.api.delete(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id); return response.status(); } async update(id, document) { if (document == null) { return; } const variantsData = document.variants.map(variant => ({ culture: variant.culture, segment: variant.segment, name: variant.name })); const updateData = { values: document.values, variants: variantsData, template: document.template }; return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id, updateData); } async getAllAtRoot() { return await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/tree/document/root?skip=0&take=10000'); } async getChildren(id) { const response = await this.api.get(`${this.api.baseUrl}/umbraco/management/api/v1/tree/document/children?parentId=${id}&skip=0&take=10000`); const items = await response.json(); return items.items; } async getChildrenAmount(id) { const response = await this.api.get(`${this.api.baseUrl}/umbraco/management/api/v1/tree/document/children?parentId=${id}&skip=0&take=10000`); const items = await response.json(); return items.total; } async doesNameExist(name) { return await this.getByName(name); } async recurseDeleteChildren(id) { const items = await this.getChildren(id); for (const child of items) { if (child.hasChildren) { await this.recurseDeleteChildren(child.id); } else { await this.delete(child.id); } } return await this.delete(id); } async recurseChildren(name, id, toDelete) { const items = await this.getChildren(id); for (const child of items) { for (const variant of child.variants) { if (variant.name === name) { if (!toDelete) { return await this.get(child.id); } if (child.hasChildren) { return await this.recurseDeleteChildren(child.id); } else { return await this.delete(child.id); } } } if (child.hasChildren) { const result = await this.recurseChildren(name, child.id, toDelete); if (result) { return result; } } } return false; } async getByName(name) { const rootDocuments = await this.getAllAtRoot(); const jsonDocuments = await rootDocuments.json(); for (const document of jsonDocuments.items) { for (const variant of document.variants) { if (variant.name === name) { return this.get(document.id); } } if (document.hasChildren) { const result = await this.recurseChildren(name, document.id, false); if (result) { return result; } } } return false; } async ensureNameNotExists(name) { const rootDocuments = await this.getAllAtRoot(); const jsonDocuments = await rootDocuments.json(); for (const document of jsonDocuments.items) { for (const variant of document.variants) { if (variant.name === name) { if (document.hasChildren) { await this.recurseDeleteChildren(document.id); } await this.delete(document.id); } else { if (document.hasChildren) { await this.recurseChildren(name, document.id, true); } } } } } async publish(id, publishSchedulesData = { "publishSchedules": [{ "culture": null }] }) { if (id == null) { return; } const response = await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/publish', publishSchedulesData); return response.status(); } async getDocumentUrl(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/urls?id=' + id); const urls = await response.json(); return urls[0].urlInfos[0].url; } async moveToRecycleBin(id) { if (id == null) { return; } const response = await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/move-to-recycle-bin'); return response.status(); } async createDefaultDocument(documentName, documentTypeId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .build(); return await this.create(document); } async createDocumentWithTextContent(documentName, documentTypeId, textContent, dataTypeName) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(dataTypeName)) .withValue(textContent) .done() .build(); return await this.create(document); } async createDefaultDocumentWithParent(documentName, documentTypeId, parentId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .withParentId(parentId) .addVariant() .withName(documentName) .done() .build(); return await this.create(document); } async createDocumentWithTemplate(documentName, documentTypeId, templateId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .withTemplateId(templateId) .build(); return await this.create(document); } async createDocumentWithContentPicker(documentName, documentTypeId, contentPickerId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias('contentPicker') .withValue(contentPickerId) .done() .build(); return await this.create(document); } async createDocumentWithOneMediaPicker(documentName, documentTypeId, mediaPickerId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias('mediaPicker') .addMediaPickerValue() .withMediaKey(mediaPickerId) .done() .done() .build(); return await this.create(document); } async createDocumentWithTwoMediaPicker(documentName, documentTypeId, firstMediaPickerId, secondMediaPickerId, alias = 'multipleMediaPicker') { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(alias) .addMediaPickerValue() .withMediaKey(firstMediaPickerId) .done() .addMediaPickerValue() .withMediaKey(secondMediaPickerId) .done() .done() .build(); return await this.create(document); } async createDocumentWithMemberPicker(documentName, documentTypeId, memberId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias('memberPicker') .withValue(memberId) .done() .build(); return await this.create(document); } async createDocumentWithTags(documentName, documentTypeId, tagsName) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias('tags') .withValue(tagsName) .done() .build(); return await this.create(document); } async createDocumentWithExternalLinkURLPicker(documentName, documentTypeId, link, linkTitle) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias('multiUrlPicker') .addURLPickerValue() .withIcon('icon-link') .withName(linkTitle) .withType('external') .withUrl(link) .done() .done() .build(); return await this.create(document); } // Domains async getDomains(id) { const response = await this.api.get(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/domains'); return await response.json(); } async updateDomains(id, domains) { return await this.api.put(this.api.baseUrl + '/umbraco/management/api/v1/document/' + id + '/domains', domains); } // Image Media Picker async createDocumentWithImageMediaPicker(documentName, documentTypeId, propertyAlias, mediaKey, focalPoint = { left: 0, top: 0 }) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(propertyAlias) .addMediaPickerValue() .withMediaKey(mediaKey) .withFocalPoint(focalPoint) .done() .done() .build(); return await this.create(document); } async doesImageMediaPickerContainImage(id, propertyAlias, mediaKey) { const contentData = await this.getByName(id); return contentData.values.some(value => value.alias === propertyAlias && value.value.some(item => item.mediaKey === mediaKey)); } async doesImageMediaPickerContainImageWithFocalPoint(id, propertyAlias, mediaKey, focalPoint) { const contentData = await this.getByName(id); if (focalPoint.left <= 0 || focalPoint.top <= 0) { return contentData.values.some(value => value.alias === propertyAlias && value.value.some(item => { return item.mediaKey === mediaKey && item.focalPoint === null; })); } // When selecting a focalpoint, it is not exact down to the decimal, so we need a small tolerance to account for that. const tolerance = 0.02; return contentData.values.some(value => value.alias === propertyAlias && value.value.some(item => { // Check if the mediaKey is the same and the focalPoint is within the tolerance return item.mediaKey === mediaKey && Math.abs(item.focalPoint.left - focalPoint.left) <= tolerance * focalPoint.left && Math.abs(item.focalPoint.top - focalPoint.top) <= tolerance * focalPoint.top; })); } async createDocumentWithUploadFile(documentName, documentTypeId, dataTypeName, uploadFileName, mineType) { await this.ensureNameNotExists(documentName); const temporaryFile = await this.api.temporaryFile.createTemporaryFile(uploadFileName, 'File', mineType); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(dataTypeName)) .withTemporaryFileId(temporaryFile.temporaryFileId) .done() .build(); return await this.create(document); } async createDefaultDocumentWithEnglishCulture(documentName, documentTypeId) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .withCulture('en-US') .done() .build(); return await this.create(document); } async createDefaultDocumentWithCulture(documentName, documentTypeId, isoCode) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .withCulture(isoCode) .done() .build(); return await this.create(document); } async createDocumentWithMultipleVariants(documentName, documentTypeId, dataTypeAlias, cultureVariants) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .build(); for (const variant of cultureVariants) { document.variants.push({ name: variant.name, culture: variant.isoCode, segment: null }); document.values.push({ alias: dataTypeAlias, value: variant.value, culture: variant.isoCode, segment: null, editorAlias: 'Umbraco.TextBox', entityType: 'document-property-value' }); } return await this.create(document); } async createDocumentWithMultipleVariantsWithSharedProperty(documentName, documentTypeId, dataTypeAlias, dataTypeEditorAlias, cultureVariants, value) { await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .build(); for (const variant of cultureVariants) { document.variants.push({ name: variant.name, culture: variant.isoCode, segment: null }); } document.values.push({ alias: dataTypeAlias, value: value, culture: null, segment: null, editorAlias: dataTypeEditorAlias, entityType: 'document-property-value' }); return await this.create(document); } async createDocumentWithEnglishCultureAndTextContent(documentName, documentTypeId, textContent, dataTypeName, varyByCultureForText = false) { await this.ensureNameNotExists(documentName); const cultureValue = varyByCultureForText ? 'en-US' : null; const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .withCulture('en-US') .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(dataTypeName)) .withValue(textContent) .withCulture(cultureValue) .done() .build(); return await this.create(document); } async createPublishedDocumentWithValue(documentName, value, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .withValue(value) .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document const publishData = { "publishSchedules": [{ "culture": null }] }; await this.publish(documentId, publishData); return documentId; } async isDocumentPublished(id) { const document = await this.get(id); return document.variants[0].state === 'Published'; } async createPublishedDocumentWithImageCropper(documentName, cropValue, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type', focalPoint = { left: 0.5, top: 0.5 }) { // Create temporary file const temporaryFile = await this.api.temporaryFile.createDefaultTemporaryImageFile(); // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addImageCropperValue() .withCrop(cropValue) .withFocalPoint(focalPoint) .withTemporaryFileId(temporaryFile.temporaryFileId) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createPublishedDocumentWithUploadFile(documentName, uploadFileName, mineType, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Create temporary file const temporaryFile = await this.api.temporaryFile.createTemporaryFile(uploadFileName, 'File', mineType); // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .withTemporaryFileId(temporaryFile.temporaryFileId) .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return { 'documentId': documentId, 'temporaryFileId': temporaryFile.temporaryFileId }; } async createPublishedDocumentWithExternalLinkURLPicker(documentName, linkTitle, linkUrl, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addURLPickerValue() .withName(linkTitle) .withType('external') .withUrl(linkUrl) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createPublishedDocumentWithDocumentLinkURLPicker(documentName, linkedDocumentName, linkedDocumentId, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Get the url of the linked document const linkedDocumentData = await this.getByName(linkedDocumentName); const linkedDocumentUrl = await this.getDocumentUrl(linkedDocumentData.id); // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addURLPickerValue() .withIcon('icon-document') .withName(linkedDocumentName) .withType('document') .withUnique(linkedDocumentId) .withUrl(linkedDocumentUrl) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createPublishedDocumentWithImageLinkURLPicker(documentName, imageName, imageId, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Get the url of the linked document const mediaData = await this.api.media.getByName(imageName); const mediaUrl = await this.api.media.getFullMediaUrl(mediaData.id); // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addURLPickerValue() .withIcon('icon-picture') .withName(imageName) .withType('media') .withUnique(imageId) .withUrl(mediaUrl) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createPublishedDocumentWithImageLinkAndExternalLink(documentName, imageName, imageId, externalLinkTitle, externalLinkUrl, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Get the url of the linked document const mediaData = await this.api.media.getByName(imageName); const mediaUrl = await this.api.media.getFullMediaUrl(mediaData.id); // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addURLPickerValue() .withIcon('icon-picture') .withName(imageName) .withType('media') .withUnique(imageId) .withUrl(mediaUrl) .done() .addURLPickerValue() .withName(externalLinkTitle) .withType('external') .withUrl(externalLinkUrl) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createPublishedDocumentWithTwoMediaPicker(documentName, firstMediaPickerId, secondMediaPickerId, dataTypeId, templateId, propertyName = 'Test Property Name', documentTypeName = 'Test Document Type') { // Create document type let documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, dataTypeId, propertyName, templateId); documentTypeId = documentTypeId === undefined ? '' : documentTypeId; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(propertyName)) .addMediaPickerValue() .withMediaKey(firstMediaPickerId) .done() .addMediaPickerValue() .withMediaKey(secondMediaPickerId) .done() .done() .build(); // Create document let documentId = await this.create(document); documentId = documentId === undefined ? '' : documentId; // Publish document await this.publish(documentId); return documentId; } async createDefaultDocumentWithABlockGridEditor(documentName, elementTypeId, documentTypeName, blockGridDataTypeName) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockGridDataTypeId = await this.api.dataType.createBlockGridWithABlock(blockGridDataTypeName, elementTypeId) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockGridDataTypeName)) .addBlockGridValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockGridEditorAndBlockWithValue(documentName, documentTypeName, blockGridDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', templateId) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockGridDataTypeId = await this.api.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, elementTypeId, true) || ''; let documentTypeId; if (templateId) { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, blockGridDataTypeId, blockGridDataTypeName, templateId) || ''; } else { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, groupName) || ''; } await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockGridDataTypeName)) .addBlockGridValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockGridEditorAndBlockWithValueAndTwoGroups(documentName, documentTypeName, blockGridDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondPropertyName, secondGroupName = 'GroupTwoName') { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockGridDataTypeId = await this.api.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, elementTypeId, true) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndTwoGroups(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, groupName, secondPropertyName, blockGridDataTypeId, secondGroupName) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockGridDataTypeName)) .addBlockGridValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockGridEditorAndBlockWithTwoValues(documentName, documentTypeName, blockGridDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondElementTypePropertyValue, templateId) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const secondBlockContentKey = crypto.randomUUID(); const blockGridDataTypeId = await this.api.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, elementTypeId, true) || ''; let documentTypeId; if (templateId) { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, blockGridDataTypeId, blockGridDataTypeName, templateId) || ''; } else { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, groupName) || ''; } await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockGridDataTypeName)) .addBlockGridValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addContentData() .withContentTypeKey(elementTypeId) .withKey(secondBlockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(secondElementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addExpose() .withContentKey(secondBlockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(secondBlockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockGridEditorAndBlockWithTwoValuesAndTwoGroups(documentName, documentTypeName, blockGridDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondElementTypePropertyValue, secondPropertyName, secondGroupName) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const secondBlockContentKey = crypto.randomUUID(); const blockGridDataTypeId = await this.api.dataType.createBlockGridWithABlockAndAllowAtRoot(blockGridDataTypeName, elementTypeId, true) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndTwoGroups(documentTypeName, blockGridDataTypeName, blockGridDataTypeId, groupName, secondPropertyName, blockGridDataTypeId, secondGroupName) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockGridDataTypeName)) .addBlockGridValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addContentData() .withContentTypeKey(elementTypeId) .withKey(secondBlockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(secondElementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addExpose() .withContentKey(secondBlockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(secondBlockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockListEditorAndBlockWithValue(documentName, documentTypeName, blockListDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName, templateId) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockListDataTypeId = await this.api.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, elementTypeId) || ''; let documentTypeId; if (templateId) { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, blockListDataTypeId, blockListDataTypeName, templateId) || ''; } else { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockListDataTypeName, blockListDataTypeId, groupName) || ''; } await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockListDataTypeName)) .addBlockListValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockListEditor(documentName, elementTypeId, documentTypeName, blockListDataTypeName) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockListDataTypeId = await this.api.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, elementTypeId) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockListDataTypeName, blockListDataTypeId) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockListDataTypeName)) .addBlockListValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockListEditorAndBlockWithValueAndTwoGroups(documentName, documentTypeName, blockListDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondPropertyName, secondGroupName = 'GroupTwoName') { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const blockListDataTypeId = await this.api.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, elementTypeId) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndTwoGroups(documentTypeName, blockListDataTypeName, blockListDataTypeId, groupName, secondPropertyName, blockListDataTypeId, secondGroupName) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockListDataTypeName)) .addBlockListValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockListEditorAndBlockWithTwoValues(documentName, documentTypeName, blockListDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondElementTypePropertyValue, templateId) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const secondBlockContentKey = crypto.randomUUID(); const blockListDataTypeId = await this.api.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, elementTypeId) || ''; let documentTypeId; if (templateId) { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndAllowedTemplate(documentTypeName, blockListDataTypeId, blockListDataTypeName, templateId) || ''; } else { documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditor(documentTypeName, blockListDataTypeName, blockListDataTypeId, groupName) || ''; } await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockListDataTypeName)) .addBlockListValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addContentData() .withContentTypeKey(elementTypeId) .withKey(secondBlockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(secondElementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addExpose() .withContentKey(secondBlockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(secondBlockContentKey) .done() .done() .done() .build(); return await this.create(document); } async createDefaultDocumentWithABlockListEditorAndBlockWithTwoValuesAndTwoGroups(documentName, documentTypeName, blockListDataTypeName, elementTypeId, elementTypePropertyAlias, elementTypePropertyValue, elementTypePropertyEditorAlias, groupName = 'TestGroup', secondElementTypePropertyValue, secondPropertyName, secondGroupName) { const crypto = require('crypto'); const blockContentKey = crypto.randomUUID(); const secondBlockContentKey = crypto.randomUUID(); const blockListDataTypeId = await this.api.dataType.createBlockListDataTypeWithABlock(blockListDataTypeName, elementTypeId) || ''; const documentTypeId = await this.api.documentType.createDocumentTypeWithPropertyEditorAndTwoGroups(documentTypeName, blockListDataTypeName, blockListDataTypeId, groupName, secondPropertyName, blockListDataTypeId, secondGroupName) || ''; await this.ensureNameNotExists(documentName); const document = new json_models_builders_1.DocumentBuilder() .withDocumentTypeId(documentTypeId) .addVariant() .withName(documentName) .done() .addValue() .withAlias(AliasHelper_1.AliasHelper.toAlias(blockListDataTypeName)) .addBlockListValue() .addContentData() .withContentTypeKey(elementTypeId) .withKey(blockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(elementTypePropertyValue) .done() .done() .addContentData() .withContentTypeKey(elementTypeId) .withKey(secondBlockContentKey) .addContentDataValue() .withAlias(elementTypePropertyAlias) .withEditorAlias(elementTypePropertyEditorAlias) .withValue(secondElementTypePropertyValue) .done() .done() .addExpose() .withContentKey(blockContentKey) .done() .addExpose() .withContentKey(secondBlockContentKey) .done() .addLayout() .withContentKey(blockContentKey) .done() .addLayout() .withContentKey(secondBlockContentKey) .done()