From d7f73293fe7aa458d10768bc1273b1b093a9f432 Mon Sep 17 00:00:00 2001
From: pkupczyk <piotr.kupczyk@id.ethz.ch>
Date: Tue, 22 Sep 2020 16:03:24 +0200
Subject: [PATCH] NG_UI : types : SSDM-10193 - add tests for internal property
 types/assignments and system internal property types/assignments

---
 .../types/form/TypeFormComponent.test.js      | 134 ++++++++++++++++++
 .../TypeFormParametersPropertyWrapper.js      |  18 ++-
 2 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponent.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponent.test.js
index 2b6f892e35d..c0f600a3838 100644
--- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponent.test.js
+++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponent.test.js
@@ -53,6 +53,7 @@ describe('TypeFormComponent', () => {
   test('validate type', testValidateType)
   test('validate property', testValidateProperty)
   test('validate type and property', testValidateTypeAndProperty)
+  test('internal', testInternal)
 })
 
 async function testLoadNew() {
@@ -1498,6 +1499,139 @@ async function testValidateTypeAndProperty() {
   })
 }
 
+async function testInternal() {
+  await doTestInternal(true, fixture.SYSTEM_USER_DTO, fixture.SYSTEM_USER_DTO)
+  await doTestInternal(false, fixture.SYSTEM_USER_DTO, fixture.SYSTEM_USER_DTO)
+  await doTestInternal(true, fixture.SYSTEM_USER_DTO, fixture.TEST_USER_DTO)
+  await doTestInternal(false, fixture.SYSTEM_USER_DTO, fixture.TEST_USER_DTO)
+  await doTestInternal(true, fixture.TEST_USER_DTO, fixture.TEST_USER_DTO)
+  await doTestInternal(false, fixture.TEST_USER_DTO, fixture.TEST_USER_DTO)
+  await doTestInternal(true, fixture.TEST_USER_DTO, fixture.SYSTEM_USER_DTO)
+  await doTestInternal(false, fixture.TEST_USER_DTO, fixture.SYSTEM_USER_DTO)
+}
+
+async function doTestInternal(
+  propertyTypeInternal,
+  propertyTypeRegistrator,
+  propertyAssignmentRegistrator
+) {
+  const isSystemInternalPropertyType =
+    propertyTypeInternal &&
+    propertyTypeRegistrator.userId === fixture.SYSTEM_USER_DTO.userId
+
+  const isSystemInternalPropertyAssignment =
+    propertyTypeInternal &&
+    propertyAssignmentRegistrator.userId === fixture.SYSTEM_USER_DTO.userId
+
+  const propertyType = new openbis.PropertyType()
+  propertyType.setCode('TEST_PROPERTY')
+  propertyType.setManagedInternally(propertyTypeInternal)
+  propertyType.setRegistrator(propertyTypeRegistrator)
+  propertyType.setDataType(openbis.DataType.VARCHAR)
+
+  const propertyAssignment = new openbis.PropertyAssignment()
+  propertyAssignment.setPropertyType(propertyType)
+  propertyAssignment.setPlugin(fixture.TEST_PLUGIN_DTO)
+  propertyAssignment.setRegistrator(propertyAssignmentRegistrator)
+
+  const type = new openbis.SampleType()
+  type.setCode('TEST_TYPE')
+  type.setPropertyAssignments([propertyAssignment])
+
+  facade.loadType.mockReturnValue(Promise.resolve(type))
+  facade.loadDynamicPlugins.mockReturnValue(
+    Promise.resolve([propertyAssignment.plugin])
+  )
+
+  const form = await common.mount({
+    id: type.getCode(),
+    type: objectTypes.OBJECT_TYPE
+  })
+
+  form.getButtons().getEdit().click()
+  await form.update()
+
+  form.expectJSON({
+    parameters: {
+      type: {
+        title: 'Type',
+        code: {
+          value: type.getCode(),
+          enabled: false
+        },
+        description: {
+          value: type.getDescription(),
+          enabled: true
+        }
+      }
+    }
+  })
+
+  form.getPreview().getSections()[0].getProperties()[0].click()
+  await form.update()
+
+  form.expectJSON({
+    parameters: {
+      property: {
+        title: 'Property',
+        code: {
+          value: propertyType.getCode(),
+          enabled: false
+        },
+        dataType: {
+          value: propertyType.getDataType(),
+          enabled: !isSystemInternalPropertyType
+        },
+        label: {
+          value: propertyType.getLabel(),
+          enabled: !isSystemInternalPropertyType
+        },
+        description: {
+          value: propertyType.getDescription(),
+          enabled: !isSystemInternalPropertyType
+        },
+        plugin: {
+          value: propertyAssignment.plugin.getName(),
+          enabled: !isSystemInternalPropertyAssignment
+        },
+        mandatory: {
+          value: propertyAssignment.isMandatory(),
+          enabled: !isSystemInternalPropertyAssignment
+        },
+        visible: {
+          value: propertyAssignment.isShowInEditView(),
+          enabled: !isSystemInternalPropertyAssignment
+        }
+      }
+    },
+    buttons: {
+      remove: {
+        enabled: !isSystemInternalPropertyAssignment
+      }
+    }
+  })
+
+  form.getPreview().getSections()[0].click()
+  await form.update()
+
+  form.expectJSON({
+    parameters: {
+      section: {
+        title: 'Section',
+        name: {
+          value: propertyAssignment.getSection(),
+          enabled: true
+        }
+      }
+    },
+    buttons: {
+      remove: {
+        enabled: !isSystemInternalPropertyAssignment
+      }
+    }
+  })
+}
+
 async function mountNew() {
   return await common.mount({
     type: objectTypes.NEW_OBJECT_TYPE
diff --git a/openbis_ng_ui/srcTest/js/components/types/form/wrapper/TypeFormParametersPropertyWrapper.js b/openbis_ng_ui/srcTest/js/components/types/form/wrapper/TypeFormParametersPropertyWrapper.js
index dacec757900..1ce57cc4e72 100644
--- a/openbis_ng_ui/srcTest/js/components/types/form/wrapper/TypeFormParametersPropertyWrapper.js
+++ b/openbis_ng_ui/srcTest/js/components/types/form/wrapper/TypeFormParametersPropertyWrapper.js
@@ -1,9 +1,11 @@
 import AutocompleterField from '@src/js/components/common/form/AutocompleterField.jsx'
 import SelectField from '@src/js/components/common/form/SelectField.jsx'
 import TextField from '@src/js/components/common/form/TextField.jsx'
+import CheckboxField from '@src/js/components/common/form/CheckboxField.jsx'
 import Message from '@src/js/components/common/form/Message.jsx'
 import TextFieldWrapper from '@srcTest/js/components/common/form/wrapper/TextFieldWrapper.js'
 import SelectFieldWrapper from '@srcTest/js/components/common/form/wrapper/SelectFieldWrapper.js'
+import CheckboxFieldWrapper from '@srcTest/js/components/common/form/wrapper/CheckboxFieldWrapper.js'
 import AutocompleterFieldWrapper from '@srcTest/js/components/common/form/wrapper/AutocompleterFieldWrapper.js'
 import MessageWrapper from '@srcTest/js/components/common/form/wrapper/MessageWrapper.js'
 import TypeFormParametersCommonWrapper from './TypeFormParametersCommonWrapper.js'
@@ -91,6 +93,18 @@ export default class TypeFormParametersPropertyWrapper extends TypeFormParameter
     )
   }
 
+  getMandatory() {
+    return new CheckboxFieldWrapper(
+      this.findComponent(CheckboxField).filter({ name: 'mandatory' })
+    )
+  }
+
+  getVisible() {
+    return new CheckboxFieldWrapper(
+      this.findComponent(CheckboxField).filter({ name: 'showInEditView' })
+    )
+  }
+
   toJSON() {
     return {
       ...super.toJSON(),
@@ -104,7 +118,9 @@ export default class TypeFormParametersPropertyWrapper extends TypeFormParameter
       vocabulary: this.getVocabulary().toJSON(),
       materialType: this.getMaterialType().toJSON(),
       schema: this.getSchema().toJSON(),
-      transformation: this.getTransformation().toJSON()
+      transformation: this.getTransformation().toJSON(),
+      mandatory: this.getMandatory().toJSON(),
+      visible: this.getVisible().toJSON()
     }
   }
 }
-- 
GitLab