Skip to content
Snippets Groups Projects
Commit 4614ab65 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

NG_UI : plugins : SSDM-10401 - plugin form tests

parent 051caac2
No related branches found
No related tags found
No related merge requests found
Showing
with 751 additions and 0 deletions
......@@ -28,6 +28,7 @@ module.exports = {
moment: '<rootDir>/srcV3/lib/moment/js/moment.js',
stjs: '<rootDir>/srcV3/lib/stjs/js/stjs.js',
underscore: '<rootDir>/srcV3/lib/underscore/js/underscore.js',
'\\.css$': '<rootDir>/srcTest/js/mockStyles.js',
'openbis.js': '<rootDir>/srcTest/js/services/openbis.js',
'^@src/(.*)$': '<rootDir>/src/$1',
'^@srcTest/(.*)$': '<rootDir>/srcTest/$1',
......
import FieldWrapper from './FieldWrapper.js'
export default class SourceCodeFieldWrapper extends FieldWrapper {
getFocused() {
if (this.getMode() === 'edit') {
return (
document.activeElement === this.wrapper.find('textarea').getDOMNode()
)
} else {
return false
}
}
}
import PluginFormComponentTest from '@srcTest/js/components/tools/form/plugin/PluginFormComponentTest.js'
import PluginFormTestData from '@srcTest/js/components/tools/form/plugin/PluginFormTestData.js'
let common = null
beforeEach(() => {
common = new PluginFormComponentTest()
common.beforeEach()
})
describe(PluginFormComponentTest.SUITE, () => {
test('change DYNAMIC_PROPERTY', async () => {
const { testDynamicPropertyJythonPlugin } = PluginFormTestData
await testChange(testDynamicPropertyJythonPlugin)
})
test('change ENTITY_VALIDATION', async () => {
const { testEntityValidationJythonPlugin } = PluginFormTestData
await testChange(testEntityValidationJythonPlugin)
})
})
async function testChange(plugin) {
const form = await common.mountExisting(plugin)
form.getButtons().getEdit().click()
await form.update()
form.getScript().getScript().change('updated script')
await form.update()
form.getParameters().getDescription().change('updated description')
await form.update()
form.expectJSON({
script: {
title: 'Script',
script: {
label: 'Script',
value: 'updated script',
enabled: true,
mode: 'edit'
}
},
parameters: {
title: 'Plugin',
name: {
label: 'Name',
value: plugin.getName(),
enabled: false,
mode: 'edit'
},
entityKind: {
label: 'Entity Kind',
value:
plugin.getEntityKinds().length === 1
? plugin.getEntityKinds()[0]
: null,
options: [
{ label: 'MATERIAL' },
{ label: 'EXPERIMENT' },
{ label: 'SAMPLE' },
{ label: 'DATA_SET' }
],
enabled: false,
mode: 'edit'
},
description: {
label: 'Description',
value: 'updated description',
enabled: true,
mode: 'edit'
}
},
buttons: {
save: {
enabled: true
},
cancel: {
enabled: true
},
edit: null,
message: {
text: 'You have unsaved changes.',
type: 'warning'
}
}
})
}
import PluginFormComponentTest from '@srcTest/js/components/tools/form/plugin/PluginFormComponentTest.js'
import PluginFormTestData from '@srcTest/js/components/tools/form/plugin/PluginFormTestData.js'
import openbis from '@srcTest/js/services/openbis.js'
let common = null
beforeEach(() => {
common = new PluginFormComponentTest()
common.beforeEach()
})
describe(PluginFormComponentTest.SUITE, () => {
test('load new DYNAMIC_PROPERTY', async () => {
await testLoadNew(openbis.PluginType.DYNAMIC_PROPERTY)
})
test('load new ENTITY_VALIDATION', async () => {
await testLoadNew(openbis.PluginType.ENTITY_VALIDATION)
})
test('load existing DYNAMIC_PROPERTY JYTHON', async () => {
const { testDynamicPropertyJythonPlugin } = PluginFormTestData
await testLoadExistingJython(testDynamicPropertyJythonPlugin)
})
test('load existing ENTITY_VALIDATION JYTHON', async () => {
const { testEntityValidationJythonPlugin } = PluginFormTestData
await testLoadExistingJython(testEntityValidationJythonPlugin)
})
test('load existing DYNAMIC_PROPERTY PREDEPLOYED', async () => {
const { testDynamicPropertyPredeployedPlugin } = PluginFormTestData
await testLoadExistingPredeployed(testDynamicPropertyPredeployedPlugin)
})
test('load existing ENTITY_VALIDATION PREDEPLOYED', async () => {
const { testEntityValidationPredeployedPlugin } = PluginFormTestData
await testLoadExistingPredeployed(testEntityValidationPredeployedPlugin)
})
})
async function testLoadNew(pluginType) {
const form = await common.mountNew(pluginType)
form.expectJSON({
script: {
title: 'Script',
script: {
label: 'Script',
value: null,
enabled: true,
mode: 'edit'
}
},
parameters: {
title: 'Plugin',
name: {
label: 'Name',
value: null,
enabled: true,
mode: 'edit'
},
entityKind: {
label: 'Entity Kind',
value: null,
options: [
{ label: 'MATERIAL' },
{ label: 'EXPERIMENT' },
{ label: 'SAMPLE' },
{ label: 'DATA_SET' }
],
enabled: true,
mode: 'edit'
},
description: {
label: 'Description',
value: null,
enabled: true,
mode: 'edit'
}
},
buttons: {
save: {
enabled: true
},
edit: null,
cancel: null,
message: null
}
})
}
async function testLoadExistingJython(plugin) {
const form = await common.mountExisting(plugin)
form.expectJSON({
script: {
title: 'Script',
script: {
label: 'Script',
value: plugin.script,
mode: 'view'
}
},
parameters: {
title: 'Plugin',
name: {
label: 'Name',
value: plugin.getName(),
mode: 'view'
},
entityKind: {
label: 'Entity Kind',
value:
plugin.getEntityKinds().length === 1
? plugin.getEntityKinds()[0]
: null,
options: [
{ label: 'MATERIAL' },
{ label: 'EXPERIMENT' },
{ label: 'SAMPLE' },
{ label: 'DATA_SET' }
],
mode: 'view'
},
description: {
label: 'Description',
value: plugin.getDescription(),
mode: 'view'
}
},
buttons: {
edit: {
enabled: true
},
save: null,
cancel: null,
message: null
}
})
form.getButtons().getEdit().click()
await form.update()
form.expectJSON({
script: {
title: 'Script',
script: {
label: 'Script',
value: plugin.script,
enabled: true,
mode: 'edit'
}
},
parameters: {
title: 'Plugin',
name: {
label: 'Name',
value: plugin.getName(),
enabled: false,
mode: 'edit'
},
entityKind: {
label: 'Entity Kind',
value:
plugin.getEntityKinds().length === 1
? plugin.getEntityKinds()[0]
: null,
options: [
{ label: 'MATERIAL' },
{ label: 'EXPERIMENT' },
{ label: 'SAMPLE' },
{ label: 'DATA_SET' }
],
enabled: false,
mode: 'edit'
},
description: {
label: 'Description',
value: plugin.getDescription(),
enabled: true,
mode: 'edit'
}
},
buttons: {
save: {
enabled: true
},
cancel: {
enabled: true
},
edit: null,
message: null
}
})
}
async function testLoadExistingPredeployed(plugin) {
const form = await common.mountExisting(plugin)
form.expectJSON({
script: null,
parameters: {
title: 'Plugin',
messages: [
{
text: 'The plugin is disabled.',
type: 'warning'
},
{
text:
'This is a predeployed Java plugin. Its parameters and logic are defined in the plugin Java class and therefore cannot be changed from the UI.',
type: 'info'
}
],
name: {
label: 'Name',
value: plugin.getName(),
mode: 'view'
},
entityKind: {
label: 'Entity Kind',
value:
plugin.getEntityKinds().length === 1
? plugin.getEntityKinds()[0]
: null,
options: [
{ label: 'MATERIAL' },
{ label: 'EXPERIMENT' },
{ label: 'SAMPLE' },
{ label: 'DATA_SET' }
],
mode: 'view'
},
description: {
label: 'Description',
value: plugin.getDescription(),
mode: 'view'
}
},
buttons: {
edit: null,
save: null,
cancel: null,
message: null
}
})
}
import PluginFormComponentTest from '@srcTest/js/components/tools/form/plugin/PluginFormComponentTest.js'
import PluginFormTestData from '@srcTest/js/components/tools/form/plugin/PluginFormTestData.js'
import openbis from '@srcTest/js/services/openbis.js'
let common = null
beforeEach(() => {
common = new PluginFormComponentTest()
common.beforeEach()
})
describe(PluginFormComponentTest.SUITE, () => {
test('save create DYNAMIC_PROPERTY', async () => {
await testSaveCreate(openbis.PluginType.DYNAMIC_PROPERTY)
})
test('save create ENTITY_VALIDATION', async () => {
await testSaveCreate(openbis.PluginType.ENTITY_VALIDATION)
})
test('save update DYNAMIC_PROPERTY', async () => {
const { testDynamicPropertyJythonPlugin } = PluginFormTestData
await testSaveUpdate(testDynamicPropertyJythonPlugin)
})
test('save update ENTITY_VALIDATION', async () => {
const { testEntityValidationJythonPlugin } = PluginFormTestData
await testSaveUpdate(testEntityValidationJythonPlugin)
})
})
async function testSaveCreate(pluginType) {
const form = await common.mountNew(pluginType)
form.getParameters().getName().change('test-plugin')
await form.update()
form.getParameters().getEntityKind().change(openbis.EntityKind.SAMPLE)
await form.update()
form.getParameters().getDescription().change('test description')
await form.update()
form.getScript().getScript().change('test script')
await form.update()
form.getButtons().getSave().click()
await form.update()
expectExecuteOperations([
createPluginOperation({
pluginType,
name: 'test-plugin',
entityKind: openbis.EntityKind.SAMPLE,
description: 'test description',
script: 'test script'
})
])
}
async function testSaveUpdate(plugin) {
const form = await common.mountExisting(plugin)
form.getButtons().getEdit().click()
await form.update()
form.getParameters().getDescription().change('updated description')
await form.update()
form.getScript().getScript().change('updated script')
await form.update()
form.getButtons().getSave().click()
await form.update()
expectExecuteOperations([
updatePluginOperation({
name: plugin.getName(),
description: 'updated description',
script: 'updated script'
})
])
}
function createPluginOperation({
pluginType,
name,
entityKind,
description,
script
}) {
const creation = new openbis.PluginCreation()
creation.setPluginType(pluginType)
creation.setEntityKind(entityKind)
creation.setName(name)
creation.setDescription(description)
creation.setScript(script)
return new openbis.CreatePluginsOperation([creation])
}
function updatePluginOperation({ name, description, script }) {
const update = new openbis.PluginUpdate()
update.setPluginId(new openbis.PluginPermId(name))
update.setDescription(description)
update.setScript(script)
return new openbis.UpdatePluginsOperation([update])
}
function expectExecuteOperations(expectedOperations) {
expect(common.facade.executeOperations).toHaveBeenCalledTimes(1)
const actualOperations = common.facade.executeOperations.mock.calls[0][0]
expect(actualOperations.length).toEqual(expectedOperations.length)
actualOperations.forEach((actualOperation, index) => {
expect(actualOperation).toMatchObject(expectedOperations[index])
})
}
import React from 'react'
import ComponentTest from '@srcTest/js/components/common/ComponentTest.js'
import PluginForm from '@src/js/components/tools/form/plugin/PluginForm.jsx'
import PluginFormWrapper from '@srcTest/js/components/tools/form/plugin/wrapper/PluginFormWrapper.js'
import PluginFormController from '@src/js/components/tools/form/plugin/PluginFormController.js'
import PluginFormFacade from '@src/js/components/tools/form/plugin/PluginFormFacade'
import objectTypes from '@src/js/common/consts/objectType.js'
import openbis from '@srcTest/js/services/openbis.js'
jest.mock('@src/js/components/tools/form/plugin/PluginFormFacade')
export default class PluginFormComponentTest extends ComponentTest {
static SUITE = 'PluginFormComponent'
constructor() {
super(
object => <PluginForm object={object} controller={this.controller} />,
wrapper => new PluginFormWrapper(wrapper)
)
this.facade = null
this.controller = null
}
async beforeEach() {
super.beforeEach()
this.facade = new PluginFormFacade()
this.controller = new PluginFormController(this.facade)
}
async mountNew(pluginType) {
if (pluginType === openbis.PluginType.DYNAMIC_PROPERTY) {
return await this.mount({
type: objectTypes.NEW_DYNAMIC_PROPERTY_PLUGIN
})
} else if (pluginType === openbis.PluginType.ENTITY_VALIDATION) {
return await this.mount({
type: objectTypes.NEW_ENTITY_VALIDATION_PLUGIN
})
} else {
throw Error('Unsupported plugin type: ' + pluginType)
}
}
async mountExisting(plugin) {
this.facade.loadPlugin.mockReturnValue(Promise.resolve(plugin))
if (plugin.pluginType === openbis.PluginType.DYNAMIC_PROPERTY) {
return await this.mount({
id: plugin.getName(),
type: objectTypes.DYNAMIC_PROPERTY_PLUGIN
})
} else if (plugin.pluginType === openbis.PluginType.ENTITY_VALIDATION) {
return await this.mount({
id: plugin.getName(),
type: objectTypes.ENTITY_VALIDATION_PLUGIN
})
} else {
throw Error('Unsupported plugin type: ' + plugin.pluginType)
}
}
}
import PluginFormComponentTest from '@srcTest/js/components/tools/form/plugin/PluginFormComponentTest.js'
import openbis from '@srcTest/js/services/openbis.js'
let common = null
beforeEach(() => {
common = new PluginFormComponentTest()
common.beforeEach()
})
describe(PluginFormComponentTest.SUITE, () => {
test('validate DYNAMIC_PROPERTY', async () => {
await testValidate(openbis.PluginType.DYNAMIC_PROPERTY)
})
test('validate ENTITY_VALIDATION', async () => {
await testValidate(openbis.PluginType.ENTITY_VALIDATION)
})
})
async function testValidate(pluginType) {
const form = await common.mountNew(pluginType)
form.getButtons().getSave().click()
await form.update()
form.expectJSON({
script: {
title: 'Script',
script: {
label: 'Script',
value: null,
error: 'Script cannot be empty',
enabled: true,
mode: 'edit'
}
},
parameters: {
title: 'Plugin',
name: {
label: 'Name',
value: null,
error: 'Name cannot be empty',
enabled: true,
mode: 'edit'
},
entityKind: {
label: 'Entity Kind',
value: null,
enabled: true,
mode: 'edit'
},
description: {
label: 'Description',
value: null,
enabled: true,
mode: 'edit'
}
},
buttons: {
save: {
enabled: true
},
edit: null,
cancel: null,
message: null
}
})
}
import openbis from '@srcTest/js/services/openbis.js'
const testDynamicPropertyJythonPlugin = new openbis.Plugin()
testDynamicPropertyJythonPlugin.setName('TEST_DYNAMIC_PROPERTY_JYTHON')
testDynamicPropertyJythonPlugin.setPluginKind(openbis.PluginKind.JYTHON)
testDynamicPropertyJythonPlugin.setPluginType(
openbis.PluginType.DYNAMIC_PROPERTY
)
testDynamicPropertyJythonPlugin.setEntityKinds([openbis.EntityKind.SAMPLE])
testDynamicPropertyJythonPlugin.setDescription(
'Description of TEST_DYNAMIC_PROPERTY_JYTHON'
)
testDynamicPropertyJythonPlugin.setScript('def calculate():\n return "abc"')
const testDynamicPropertyPredeployedPlugin = new openbis.Plugin()
testDynamicPropertyPredeployedPlugin.setName(
'TEST_DYNAMIC_PROPERTY_PREDEPLOYED'
)
testDynamicPropertyPredeployedPlugin.setPluginKind(
openbis.PluginKind.PREDEPLOYED
)
testDynamicPropertyPredeployedPlugin.setPluginType(
openbis.PluginType.DYNAMIC_PROPERTY
)
testDynamicPropertyPredeployedPlugin.setEntityKinds([
openbis.EntityKind.EXPERIMENT
])
testDynamicPropertyPredeployedPlugin.setDescription(
'Description of TEST_DYNAMIC_PROPERTY_PREDEPLOYED'
)
const testEntityValidationJythonPlugin = new openbis.Plugin()
testEntityValidationJythonPlugin.setName('TEST_ENTITY_VALIDATION_JYTHON')
testEntityValidationJythonPlugin.setPluginKind(openbis.PluginKind.JYTHON)
testEntityValidationJythonPlugin.setPluginType(
openbis.PluginType.ENTITY_VALIDATION
)
testEntityValidationJythonPlugin.setEntityKinds([openbis.EntityKind.DATA_SET])
testEntityValidationJythonPlugin.setDescription(
'Description of TEST_ENTITY_VALIDATION_JYTHON'
)
testEntityValidationJythonPlugin.setScript('def validate():\n return True')
const testEntityValidationPredeployedPlugin = new openbis.Plugin()
testEntityValidationPredeployedPlugin.setName(
'TEST_ENTITY_VALIDATION_PREDEPLOYED'
)
testEntityValidationPredeployedPlugin.setPluginKind(
openbis.PluginKind.PREDEPLOYED
)
testEntityValidationPredeployedPlugin.setPluginType(
openbis.PluginType.ENTITY_VALIDATION
)
testEntityValidationPredeployedPlugin.setEntityKinds([
openbis.EntityKind.SAMPLE,
openbis.EntityKind.EXPERIMENT,
openbis.EntityKind.DATA_SET,
openbis.EntityKind.MATERIAL
])
testEntityValidationPredeployedPlugin.setDescription(
'Description of TEST_ENTITY_VALIDATION_PREDEPLOYED'
)
export default {
testDynamicPropertyJythonPlugin,
testDynamicPropertyPredeployedPlugin,
testEntityValidationJythonPlugin,
testEntityValidationPredeployedPlugin
}
import PageButtonsWrapper from '@srcTest/js/components/common/page/wrapper/PageButtonsWrapper.js'
export default class PluginFormButtonsWrapper extends PageButtonsWrapper {}
import TextField from '@src/js/components/common/form/TextField.jsx'
import TextFieldWrapper from '@srcTest/js/components/common/form/wrapper/TextFieldWrapper.js'
import SelectField from '@src/js/components/common/form/SelectField.jsx'
import SelectFieldWrapper from '@srcTest/js/components/common/form/wrapper/SelectFieldWrapper.js'
import PageParametersPanelWrapper from '@srcTest/js/components/common/page/wrapper/PageParametersPanelWrapper.js'
export default class PluginFormParametersWrapper extends PageParametersPanelWrapper {
getName() {
return new TextFieldWrapper(
this.findComponent(TextField).filter({ name: 'name' })
)
}
getEntityKind() {
return new SelectFieldWrapper(
this.findComponent(SelectField).filter({ name: 'entityKind' })
)
}
getDescription() {
return new TextFieldWrapper(
this.findComponent(TextField).filter({ name: 'description' })
)
}
toJSON() {
return {
...super.toJSON(),
name: this.getName().toJSON(),
entityKind: this.getEntityKind().toJSON(),
description: this.getDescription().toJSON()
}
}
}
import BaseWrapper from '@srcTest/js/components/common/wrapper/BaseWrapper.js'
import Header from '@src/js/components/common/form/Header.jsx'
import SourceCodeField from '@src/js/components/common/form/SourceCodeField.jsx'
import SourceCodeFieldWrapper from '@srcTest/js/components/common/form/wrapper/SourceCodeFieldWrapper.js'
export default class PluginFormScriptWrapper extends BaseWrapper {
getTitle() {
return this.findComponent(Header)
}
getScript() {
return new SourceCodeFieldWrapper(this.findComponent(SourceCodeField))
}
toJSON() {
if (this.wrapper.exists()) {
return {
title: this.getTitle().exists() ? this.getTitle().text() : null,
script: this.getScript().toJSON()
}
} else {
return null
}
}
}
import BaseWrapper from '@srcTest/js/components/common/wrapper/BaseWrapper.js'
import PluginFormScript from '@src/js/components/tools/form/plugin/PluginFormScript.jsx'
import PluginFormScriptWrapper from '@srcTest/js/components/tools/form/plugin/wrapper/PluginFormScriptWrapper.js'
import PluginFormParameters from '@src/js/components/tools/form/plugin/PluginFormParameters.jsx'
import PluginFormParametersWrapper from '@srcTest/js/components/tools/form/plugin/wrapper/PluginFormParametersWrapper.js'
import PluginFormButtons from '@src/js/components/tools/form/plugin/PluginFormButtons.jsx'
import PluginFormButtonsWrapper from '@srcTest/js/components/tools/form/plugin/wrapper/PluginFormButtonsWrapper.js'
export default class PluginFormWrapper extends BaseWrapper {
getScript() {
return new PluginFormScriptWrapper(this.findComponent(PluginFormScript))
}
getParameters() {
return new PluginFormParametersWrapper(
this.findComponent(PluginFormParameters)
)
}
getButtons() {
return new PluginFormButtonsWrapper(this.findComponent(PluginFormButtons))
}
toJSON() {
return {
script: this.getScript().toJSON(),
parameters: this.getParameters().toJSON(),
buttons: this.getButtons().toJSON()
}
}
}
// styles are not needed for the tests
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment