From a4c68dcb555e42c5c0c6b01e249e362d71cab80f Mon Sep 17 00:00:00 2001 From: pkupczyk <piotr.kupczyk@id.ethz.ch> Date: Fri, 25 Sep 2020 14:11:15 +0200 Subject: [PATCH] NG_UI : vocabularies : SSDM-10193 - restructure other tests --- .../js/components/AppComponentLogin.test.js | 67 + ....js => AppComponentOpenCloseTypes.test.js} | 86 +- .../srcTest/js/components/AppComponentTest.js | 36 + .../components/login/LoginComponent.test.js | 95 -- .../login/LoginComponentLogin.test.js | 91 ++ .../js/components/login/LoginComponentTest.js | 15 + .../browser/TypeBrowserComponent.test.js | 235 --- .../TypeBrowserComponentFilter.test.js | 58 + .../browser/TypeBrowserComponentLoad.test.js | 29 + .../TypeBrowserComponentOpenClose.test.js | 51 + .../TypeBrowserComponentSelect.test.js | 107 ++ .../types/browser/TypeBrowserComponentTest.js | 39 + .../browser/TypeBrowserController.test.js | 186 --- .../TypeBrowserControllerAddNode.test.js | 22 + .../TypeBrowserControllerFilter.test.js | 60 + .../browser/TypeBrowserControllerLoad.test.js | 46 + .../TypeBrowserControllerRemoveNode.test.js | 67 + .../browser/TypeBrowserControllerTest.js | 44 + .../form/TypeFormComponentAddProperty.test.js | 2 +- .../form/TypeFormComponentAddSection.test.js | 2 +- .../TypeFormComponentChangeProperty.test.js | 2 +- .../TypeFormComponentChangeSection.test.js | 2 +- .../form/TypeFormComponentChangeType.test.js | 2 +- .../form/TypeFormComponentInternal.test.js | 2 +- .../types/form/TypeFormComponentLoad.test.js | 2 +- .../TypeFormComponentRemoveProperty.test.js | 2 +- .../TypeFormComponentRemoveSection.test.js | 2 +- .../TypeFormComponentSelectProperty.test.js | 2 +- .../TypeFormComponentSelectSection.test.js | 2 +- .../types/form/TypeFormComponentTest.js | 2 + .../form/TypeFormComponentValidate.test.js | 2 +- .../TypeFormControllerAddProperty.test.js | 355 +++-- .../form/TypeFormControllerAddSection.test.js | 364 +++-- .../form/TypeFormControllerChange.test.js | 256 ++-- .../types/form/TypeFormControllerLoad.test.js | 567 ++++--- .../TypeFormControllerOrderChange.test.js | 296 ++-- .../form/TypeFormControllerRemove.test.js | 1311 ++++++++--------- .../types/form/TypeFormControllerSave.test.js | 731 +++++---- .../TypeFormControllerSelectionChange.test.js | 135 +- .../types/form/TypeFormControllerTest.js | 32 + .../form/TypeFormControllerValidate.test.js | 86 ++ .../VocabularyFormComponentAddTerm.test.js | 2 +- .../VocabularyFormComponentChangeTerm.test.js | 2 +- ...ularyFormComponentChangeVocabulary.test.js | 2 +- .../VocabularyFormComponentFilter.test.js | 2 +- .../VocabularyFormComponentInternal.test.js | 2 +- .../form/VocabularyFormComponentLoad.test.js | 2 +- .../form/VocabularyFormComponentPage.test.js | 2 +- .../VocabularyFormComponentRemoveTerm.test.js | 2 +- .../VocabularyFormComponentSelectTerm.test.js | 2 +- .../form/VocabularyFormComponentSort.test.js | 2 +- .../types/form/VocabularyFormComponentTest.js | 2 + .../VocabularyFormComponentValidate.test.js | 2 +- .../browser/UserBrowserComponent.test.js | 144 -- .../UserBrowserComponentFilter.test.js | 48 + .../browser/UserBrowserComponentLoad.test.js | 26 + .../UserBrowserComponentOpenClose.test.js | 79 + .../users/browser/UserBrowserComponentTest.js | 28 + .../browser/UserBrowserController.test.js | 305 ---- ...rowserControllerExpandCollapseNode.test.js | 53 + .../UserBrowserControllerFilter.test.js | 55 + .../browser/UserBrowserControllerLoad.test.js | 40 + .../UserBrowserControllerSelectNode.test.js | 178 +++ .../browser/UserBrowserControllerTest.js | 29 + 64 files changed, 3372 insertions(+), 3130 deletions(-) create mode 100644 openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js rename openbis_ng_ui/srcTest/js/components/{AppComponent.test.js => AppComponentOpenCloseTypes.test.js} (58%) create mode 100644 openbis_ng_ui/srcTest/js/components/AppComponentTest.js delete mode 100644 openbis_ng_ui/srcTest/js/components/login/LoginComponent.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/login/LoginComponentLogin.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/login/LoginComponentTest.js delete mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponent.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentLoad.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentOpenClose.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentSelect.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentTest.js delete mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserController.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerAddNode.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerFilter.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerLoad.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerRemoveNode.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerTest.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerTest.js create mode 100644 openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerValidate.test.js delete mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponent.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentFilter.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentLoad.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentOpenClose.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentTest.js delete mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserController.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerExpandCollapseNode.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerFilter.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerLoad.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerSelectNode.test.js create mode 100644 openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerTest.js diff --git a/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js b/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js new file mode 100644 index 00000000000..0d10d5cb632 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/AppComponentLogin.test.js @@ -0,0 +1,67 @@ +import AppComponentTest from '@srcTest/js/components/AppComponentTest.js' + +let common = null + +beforeEach(() => { + common = new AppComponentTest() + common.beforeEach() +}) + +describe(AppComponentTest.SUITE, () => { + test('login', testLogin) +}) + +async function testLogin() { + const app = await common.mount() + + app.expectJSON({ + login: { + user: { + value: null, + enabled: true + }, + password: { + value: null, + enabled: true + }, + button: { + enabled: true + } + }, + menu: null, + types: null, + users: null + }) + + await common.login(app) + + app.expectJSON({ + login: null, + menu: { + tabs: [ + { + label: 'Types', + selected: true + } + ] + }, + types: { + browser: { + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 0, text: 'Collection Types' }, + { level: 0, text: 'Data Set Types' }, + { level: 0, text: 'Material Types' }, + { level: 0, text: 'Vocabulary Types' } + ] + }, + content: { + tabs: [] + } + }, + users: null + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/AppComponent.test.js b/openbis_ng_ui/srcTest/js/components/AppComponentOpenCloseTypes.test.js similarity index 58% rename from openbis_ng_ui/srcTest/js/components/AppComponent.test.js rename to openbis_ng_ui/srcTest/js/components/AppComponentOpenCloseTypes.test.js index 91d7772cafd..91ad207e4ad 100644 --- a/openbis_ng_ui/srcTest/js/components/AppComponent.test.js +++ b/openbis_ng_ui/srcTest/js/components/AppComponentOpenCloseTypes.test.js @@ -1,89 +1,18 @@ -import React from 'react' -import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' -import AppWrapper from '@srcTest/js/components/wrapper/AppWrapper.js' -import App from '@src/js/components/App.jsx' +import AppComponentTest from '@srcTest/js/components/AppComponentTest.js' import openbis from '@srcTest/js/services/openbis.js' import fixture from '@srcTest/js/common/fixture.js' let common = null beforeEach(() => { - common = new ComponentTest( - () => <App />, - wrapper => new AppWrapper(wrapper) - ) + common = new AppComponentTest() common.beforeEach() - - openbis.login.mockReturnValue(Promise.resolve('testSession')) - openbis.mockSearchSampleTypes([]) - openbis.mockSearchExperimentTypes([]) - openbis.mockSearchDataSetTypes([]) - openbis.mockSearchMaterialTypes([]) - openbis.mockSearchVocabularies([]) - openbis.mockSearchPersons([]) - openbis.mockSearchGroups([]) }) -describe('app', () => { - test('login', testLogin) +describe(AppComponentTest.SUITE, () => { test('open/close types', testOpenCloseTypes) }) -async function testLogin() { - const app = await common.mount() - - app.expectJSON({ - login: { - user: { - value: null, - enabled: true - }, - password: { - value: null, - enabled: true - }, - button: { - enabled: true - } - }, - menu: null, - types: null, - users: null - }) - - await login(app) - - app.expectJSON({ - login: null, - menu: { - tabs: [ - { - label: 'Types', - selected: true - } - ] - }, - types: { - browser: { - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 0, text: 'Collection Types' }, - { level: 0, text: 'Data Set Types' }, - { level: 0, text: 'Material Types' }, - { level: 0, text: 'Vocabulary Types' } - ] - }, - content: { - tabs: [] - } - }, - users: null - }) -} - async function testOpenCloseTypes() { openbis.mockSearchSampleTypes([ fixture.TEST_SAMPLE_TYPE_DTO, @@ -92,7 +21,7 @@ async function testOpenCloseTypes() { const app = await common.mount() - await login(app) + await common.login(app) app.getTypes().getBrowser().getNodes()[0].getIcon().click() await app.update() @@ -172,10 +101,3 @@ async function testOpenCloseTypes() { } }) } - -async function login(app) { - app.getLogin().getUser().change('testUser') - app.getLogin().getPassword().change('testPassword') - app.getLogin().getButton().click() - await app.update() -} diff --git a/openbis_ng_ui/srcTest/js/components/AppComponentTest.js b/openbis_ng_ui/srcTest/js/components/AppComponentTest.js new file mode 100644 index 00000000000..ea692cf30a1 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/AppComponentTest.js @@ -0,0 +1,36 @@ +import React from 'react' +import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' +import AppWrapper from '@srcTest/js/components/wrapper/AppWrapper.js' +import App from '@src/js/components/App.jsx' +import openbis from '@srcTest/js/services/openbis.js' + +export default class AppComponentTest extends ComponentTest { + static SUITE = 'AppComponent' + + constructor() { + super( + () => <App />, + wrapper => new AppWrapper(wrapper) + ) + } + + async beforeEach() { + super.beforeEach() + + openbis.login.mockReturnValue(Promise.resolve('testSession')) + openbis.mockSearchSampleTypes([]) + openbis.mockSearchExperimentTypes([]) + openbis.mockSearchDataSetTypes([]) + openbis.mockSearchMaterialTypes([]) + openbis.mockSearchVocabularies([]) + openbis.mockSearchPersons([]) + openbis.mockSearchGroups([]) + } + + async login(app) { + app.getLogin().getUser().change('testUser') + app.getLogin().getPassword().change('testPassword') + app.getLogin().getButton().click() + await app.update() + } +} diff --git a/openbis_ng_ui/srcTest/js/components/login/LoginComponent.test.js b/openbis_ng_ui/srcTest/js/components/login/LoginComponent.test.js deleted file mode 100644 index 4fd904e0fe8..00000000000 --- a/openbis_ng_ui/srcTest/js/components/login/LoginComponent.test.js +++ /dev/null @@ -1,95 +0,0 @@ -import React from 'react' -import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' -import Login from '@src/js/components/login/Login.jsx' -import LoginWrapper from '@srcTest/js/components/login/wrapper/LoginWrapper.js' - -let common = null - -beforeEach(() => { - common = new ComponentTest( - () => <Login />, - wrapper => new LoginWrapper(wrapper) - ) - common.beforeEach() -}) - -describe('login', () => { - test('test', async () => { - const login = await common.mount() - - login.expectJSON({ - user: { - value: null, - focused: true, - error: null - }, - password: { - value: null, - focused: false, - error: null - }, - button: { - enabled: true - } - }) - - login.getButton().click() - await login.update() - - login.expectJSON({ - user: { - value: null, - focused: true, - error: 'User cannot be empty' - }, - password: { - value: null, - focused: false, - error: 'Password cannot be empty' - }, - button: { - enabled: true - } - }) - - login.getUser().change('testUser') - login.getButton().click() - await login.update() - - login.expectJSON({ - user: { - value: 'testUser', - focused: false, - error: null - }, - password: { - value: null, - focused: true, - error: 'Password cannot be empty' - }, - button: { - enabled: true - } - }) - - login.getPassword().change('testPassword') - login.getButton().click() - await login.update() - - login.expectJSON({ - user: { - value: 'testUser', - focused: false, - error: null - }, - password: { - value: 'testPassword', - focused: true, - error: null - }, - button: { - enabled: true - } - }) - }) -}) diff --git a/openbis_ng_ui/srcTest/js/components/login/LoginComponentLogin.test.js b/openbis_ng_ui/srcTest/js/components/login/LoginComponentLogin.test.js new file mode 100644 index 00000000000..900bdee2ab1 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/login/LoginComponentLogin.test.js @@ -0,0 +1,91 @@ +import LoginComponentTest from '@srcTest/js/components/login/LoginComponentTest.js' + +let common = null + +beforeEach(() => { + common = new LoginComponentTest() + common.beforeEach() +}) + +describe(LoginComponentTest.SUITE, () => { + test('login', testLogin) +}) + +async function testLogin() { + const login = await common.mount() + + login.expectJSON({ + user: { + value: null, + focused: true, + error: null + }, + password: { + value: null, + focused: false, + error: null + }, + button: { + enabled: true + } + }) + + login.getButton().click() + await login.update() + + login.expectJSON({ + user: { + value: null, + focused: true, + error: 'User cannot be empty' + }, + password: { + value: null, + focused: false, + error: 'Password cannot be empty' + }, + button: { + enabled: true + } + }) + + login.getUser().change('testUser') + login.getButton().click() + await login.update() + + login.expectJSON({ + user: { + value: 'testUser', + focused: false, + error: null + }, + password: { + value: null, + focused: true, + error: 'Password cannot be empty' + }, + button: { + enabled: true + } + }) + + login.getPassword().change('testPassword') + login.getButton().click() + await login.update() + + login.expectJSON({ + user: { + value: 'testUser', + focused: false, + error: null + }, + password: { + value: 'testPassword', + focused: true, + error: null + }, + button: { + enabled: true + } + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/login/LoginComponentTest.js b/openbis_ng_ui/srcTest/js/components/login/LoginComponentTest.js new file mode 100644 index 00000000000..930ffef13a5 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/login/LoginComponentTest.js @@ -0,0 +1,15 @@ +import React from 'react' +import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' +import Login from '@src/js/components/login/Login.jsx' +import LoginWrapper from '@srcTest/js/components/login/wrapper/LoginWrapper.js' + +export default class LoginComponentTest extends ComponentTest { + static SUITE = 'LoginComponent' + + constructor() { + super( + () => <Login />, + wrapper => new LoginWrapper(wrapper) + ) + } +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponent.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponent.test.js deleted file mode 100644 index ab13b2a73d8..00000000000 --- a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponent.test.js +++ /dev/null @@ -1,235 +0,0 @@ -import React from 'react' -import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' -import BrowserWrapper from '@srcTest/js/components/common/browser/wrapper/BrowserWrapper.js' -import TypeBrowser from '@src/js/components/types/browser/TypeBrowser.jsx' -import openbis from '@srcTest/js/services/openbis.js' -import fixture from '@srcTest/js/common/fixture.js' - -let common = null - -beforeEach(() => { - common = new ComponentTest( - () => <TypeBrowser />, - wrapper => new BrowserWrapper(wrapper) - ) - common.beforeEach() - - openbis.mockSearchSampleTypes([ - fixture.TEST_SAMPLE_TYPE_DTO, - fixture.ANOTHER_SAMPLE_TYPE_DTO - ]) - - openbis.mockSearchExperimentTypes([fixture.TEST_EXPERIMENT_TYPE_DTO]) - openbis.mockSearchDataSetTypes([fixture.TEST_DATA_SET_TYPE_DTO]) - - openbis.mockSearchMaterialTypes([ - fixture.TEST_MATERIAL_TYPE_DTO, - fixture.ANOTHER_MATERIAL_TYPE_DTO - ]) - - openbis.mockSearchVocabularies([ - fixture.TEST_VOCABULARY_DTO, - fixture.ANOTHER_VOCABULARY_DTO - ]) -}) - -describe('type browser', () => { - test('load', testLoad) - test('open/close', testOpenClose) - test('filter', testFilter) - test('select entity kind', testSelectEntityKind) - test('select entity type', testSelectEntityType) -}) - -async function testLoad() { - const browser = await common.mount() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 0, text: 'Collection Types' }, - { level: 0, text: 'Data Set Types' }, - { level: 0, text: 'Material Types' }, - { level: 0, text: 'Vocabulary Types' } - ] - }) -} - -async function testOpenClose() { - const browser = await common.mount() - - browser.getNodes()[0].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, - { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code }, - { level: 0, text: 'Collection Types' }, - { level: 0, text: 'Data Set Types' }, - { level: 0, text: 'Material Types' }, - { level: 0, text: 'Vocabulary Types' } - ] - }) - - browser.getNodes()[0].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 0, text: 'Collection Types' }, - { level: 0, text: 'Data Set Types' }, - { level: 0, text: 'Material Types' }, - { level: 0, text: 'Vocabulary Types' } - ] - }) -} - -async function testFilter() { - const browser = await common.mount() - - browser.getFilter().change('ANOTHER') - await browser.update() - - browser.expectJSON({ - filter: { - value: 'ANOTHER' - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, - { level: 0, text: 'Material Types' }, - { level: 1, text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code }, - { level: 0, text: 'Vocabulary Types' }, - { level: 1, text: fixture.ANOTHER_VOCABULARY_DTO.code } - ] - }) - - browser.getFilter().getClearIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Object Types' }, - { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, - { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code }, - { level: 0, text: 'Collection Types' }, - { level: 1, text: fixture.TEST_EXPERIMENT_TYPE_DTO.code }, - { level: 0, text: 'Data Set Types' }, - { level: 1, text: fixture.TEST_DATA_SET_TYPE_DTO.code }, - { level: 0, text: 'Material Types' }, - { level: 1, text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code }, - { level: 1, text: fixture.TEST_MATERIAL_TYPE_DTO.code }, - { level: 0, text: 'Vocabulary Types' }, - { level: 1, text: fixture.ANOTHER_VOCABULARY_DTO.code }, - { level: 1, text: fixture.TEST_VOCABULARY_DTO.code } - ] - }) -} - -async function testSelectEntityKind() { - const browser = await common.mount() - - browser.expectJSON({ - nodes: [ - { level: 0, text: 'Object Types', selected: false }, - { level: 0, text: 'Collection Types', selected: false }, - { level: 0, text: 'Data Set Types', selected: false }, - { level: 0, text: 'Material Types', selected: false }, - { level: 0, text: 'Vocabulary Types', selected: false } - ], - buttons: { - add: { - enabled: false - }, - remove: { - enabled: false - } - } - }) - - browser.getNodes()[0].click() - await browser.update() - - browser.expectJSON({ - nodes: [ - { level: 0, text: 'Object Types', selected: true }, - { level: 0, text: 'Collection Types', selected: false }, - { level: 0, text: 'Data Set Types', selected: false }, - { level: 0, text: 'Material Types', selected: false }, - { level: 0, text: 'Vocabulary Types', selected: false } - ], - buttons: { - add: { - enabled: true - }, - remove: { - enabled: false - } - } - }) -} - -async function testSelectEntityType() { - const browser = await common.mount() - - browser.getNodes()[0].getIcon().click() - await browser.update() - - browser.expectJSON({ - nodes: [ - { level: 0, text: 'Object Types', selected: false }, - { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, selected: false }, - { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code, selected: false }, - { level: 0, text: 'Collection Types', selected: false }, - { level: 0, text: 'Data Set Types', selected: false }, - { level: 0, text: 'Material Types', selected: false }, - { level: 0, text: 'Vocabulary Types', selected: false } - ], - buttons: { - add: { - enabled: false - }, - remove: { - enabled: false - } - } - }) - - browser.getNodes()[1].click() - await browser.update() - - browser.expectJSON({ - nodes: [ - { level: 0, text: 'Object Types', selected: false }, - { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, selected: true }, - { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code, selected: false }, - { level: 0, text: 'Collection Types', selected: false }, - { level: 0, text: 'Data Set Types', selected: false }, - { level: 0, text: 'Material Types', selected: false }, - { level: 0, text: 'Vocabulary Types', selected: false } - ], - buttons: { - add: { - enabled: false - }, - remove: { - enabled: true - } - } - }) -} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js new file mode 100644 index 00000000000..d492b88bc3b --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentFilter.test.js @@ -0,0 +1,58 @@ +import TypeBrowserComponentTest from '@srcTest/js/components/types/browser/TypeBrowserComponentTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserComponentTest() + common.beforeEach() +}) + +describe(TypeBrowserComponentTest.SUITE, () => { + test('filter', testFilter) +}) + +async function testFilter() { + const browser = await common.mount() + + browser.getFilter().change('ANOTHER') + await browser.update() + + browser.expectJSON({ + filter: { + value: 'ANOTHER' + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, + { level: 0, text: 'Material Types' }, + { level: 1, text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code }, + { level: 0, text: 'Vocabulary Types' }, + { level: 1, text: fixture.ANOTHER_VOCABULARY_DTO.code } + ] + }) + + browser.getFilter().getClearIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, + { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code }, + { level: 0, text: 'Collection Types' }, + { level: 1, text: fixture.TEST_EXPERIMENT_TYPE_DTO.code }, + { level: 0, text: 'Data Set Types' }, + { level: 1, text: fixture.TEST_DATA_SET_TYPE_DTO.code }, + { level: 0, text: 'Material Types' }, + { level: 1, text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code }, + { level: 1, text: fixture.TEST_MATERIAL_TYPE_DTO.code }, + { level: 0, text: 'Vocabulary Types' }, + { level: 1, text: fixture.ANOTHER_VOCABULARY_DTO.code }, + { level: 1, text: fixture.TEST_VOCABULARY_DTO.code } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentLoad.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentLoad.test.js new file mode 100644 index 00000000000..6516511132d --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentLoad.test.js @@ -0,0 +1,29 @@ +import TypeBrowserComponentTest from '@srcTest/js/components/types/browser/TypeBrowserComponentTest.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserComponentTest() + common.beforeEach() +}) + +describe(TypeBrowserComponentTest.SUITE, () => { + test('load', testLoad) +}) + +async function testLoad() { + const browser = await common.mount() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 0, text: 'Collection Types' }, + { level: 0, text: 'Data Set Types' }, + { level: 0, text: 'Material Types' }, + { level: 0, text: 'Vocabulary Types' } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentOpenClose.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentOpenClose.test.js new file mode 100644 index 00000000000..d389cd3e8c3 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentOpenClose.test.js @@ -0,0 +1,51 @@ +import TypeBrowserComponentTest from '@srcTest/js/components/types/browser/TypeBrowserComponentTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserComponentTest() + common.beforeEach() +}) + +describe(TypeBrowserComponentTest.SUITE, () => { + test('open/close', testOpenClose) +}) + +async function testOpenClose() { + const browser = await common.mount() + + browser.getNodes()[0].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code }, + { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code }, + { level: 0, text: 'Collection Types' }, + { level: 0, text: 'Data Set Types' }, + { level: 0, text: 'Material Types' }, + { level: 0, text: 'Vocabulary Types' } + ] + }) + + browser.getNodes()[0].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Object Types' }, + { level: 0, text: 'Collection Types' }, + { level: 0, text: 'Data Set Types' }, + { level: 0, text: 'Material Types' }, + { level: 0, text: 'Vocabulary Types' } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentSelect.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentSelect.test.js new file mode 100644 index 00000000000..1e05a49bea1 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentSelect.test.js @@ -0,0 +1,107 @@ +import TypeBrowserComponentTest from '@srcTest/js/components/types/browser/TypeBrowserComponentTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserComponentTest() + common.beforeEach() +}) + +describe(TypeBrowserComponentTest.SUITE, () => { + test('select entity kind', testSelectEntityKind) + test('select entity type', testSelectEntityType) +}) + +async function testSelectEntityKind() { + const browser = await common.mount() + + browser.expectJSON({ + nodes: [ + { level: 0, text: 'Object Types', selected: false }, + { level: 0, text: 'Collection Types', selected: false }, + { level: 0, text: 'Data Set Types', selected: false }, + { level: 0, text: 'Material Types', selected: false }, + { level: 0, text: 'Vocabulary Types', selected: false } + ], + buttons: { + add: { + enabled: false + }, + remove: { + enabled: false + } + } + }) + + browser.getNodes()[0].click() + await browser.update() + + browser.expectJSON({ + nodes: [ + { level: 0, text: 'Object Types', selected: true }, + { level: 0, text: 'Collection Types', selected: false }, + { level: 0, text: 'Data Set Types', selected: false }, + { level: 0, text: 'Material Types', selected: false }, + { level: 0, text: 'Vocabulary Types', selected: false } + ], + buttons: { + add: { + enabled: true + }, + remove: { + enabled: false + } + } + }) +} + +async function testSelectEntityType() { + const browser = await common.mount() + + browser.getNodes()[0].getIcon().click() + await browser.update() + + browser.expectJSON({ + nodes: [ + { level: 0, text: 'Object Types', selected: false }, + { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, selected: false }, + { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code, selected: false }, + { level: 0, text: 'Collection Types', selected: false }, + { level: 0, text: 'Data Set Types', selected: false }, + { level: 0, text: 'Material Types', selected: false }, + { level: 0, text: 'Vocabulary Types', selected: false } + ], + buttons: { + add: { + enabled: false + }, + remove: { + enabled: false + } + } + }) + + browser.getNodes()[1].click() + await browser.update() + + browser.expectJSON({ + nodes: [ + { level: 0, text: 'Object Types', selected: false }, + { level: 1, text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, selected: true }, + { level: 1, text: fixture.TEST_SAMPLE_TYPE_DTO.code, selected: false }, + { level: 0, text: 'Collection Types', selected: false }, + { level: 0, text: 'Data Set Types', selected: false }, + { level: 0, text: 'Material Types', selected: false }, + { level: 0, text: 'Vocabulary Types', selected: false } + ], + buttons: { + add: { + enabled: false + }, + remove: { + enabled: true + } + } + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentTest.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentTest.js new file mode 100644 index 00000000000..eb943ad8621 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserComponentTest.js @@ -0,0 +1,39 @@ +import React from 'react' +import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' +import BrowserWrapper from '@srcTest/js/components/common/browser/wrapper/BrowserWrapper.js' +import TypeBrowser from '@src/js/components/types/browser/TypeBrowser.jsx' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +export default class TypeBrowserComponentTest extends ComponentTest { + static SUITE = 'TypeBrowserComponent' + + constructor() { + super( + () => <TypeBrowser />, + wrapper => new BrowserWrapper(wrapper) + ) + } + + async beforeEach() { + super.beforeEach() + + openbis.mockSearchSampleTypes([ + fixture.TEST_SAMPLE_TYPE_DTO, + fixture.ANOTHER_SAMPLE_TYPE_DTO + ]) + + openbis.mockSearchExperimentTypes([fixture.TEST_EXPERIMENT_TYPE_DTO]) + openbis.mockSearchDataSetTypes([fixture.TEST_DATA_SET_TYPE_DTO]) + + openbis.mockSearchMaterialTypes([ + fixture.TEST_MATERIAL_TYPE_DTO, + fixture.ANOTHER_MATERIAL_TYPE_DTO + ]) + + openbis.mockSearchVocabularies([ + fixture.TEST_VOCABULARY_DTO, + fixture.ANOTHER_VOCABULARY_DTO + ]) + } +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserController.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserController.test.js deleted file mode 100644 index 964a707d722..00000000000 --- a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserController.test.js +++ /dev/null @@ -1,186 +0,0 @@ -import TypeBrowserController from '@src/js/components/types/browser/TypeBrowserController.js' -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import openbis from '@srcTest/js/services/openbis.js' -import pages from '@src/js/common/consts/pages.js' -import objectType from '@src/js/common/consts/objectType.js' -import actions from '@src/js/store/actions/actions.js' -import fixture from '@srcTest/js/common/fixture.js' - -let context = null -let controller = null - -beforeEach(() => { - jest.resetAllMocks() - - context = new ComponentContext() - controller = new TypeBrowserController() - controller.init(context) - - openbis.mockSearchSampleTypes([ - fixture.TEST_SAMPLE_TYPE_DTO, - fixture.ANOTHER_SAMPLE_TYPE_DTO - ]) - - openbis.mockSearchExperimentTypes([fixture.TEST_EXPERIMENT_TYPE_DTO]) - openbis.mockSearchDataSetTypes([fixture.TEST_DATA_SET_TYPE_DTO]) - - openbis.mockSearchMaterialTypes([ - fixture.TEST_MATERIAL_TYPE_DTO, - fixture.ANOTHER_MATERIAL_TYPE_DTO - ]) - - openbis.mockSearchVocabularies([ - fixture.TEST_VOCABULARY_DTO, - fixture.ANOTHER_VOCABULARY_DTO - ]) -}) - -describe('browser', () => { - test('load', async () => { - await controller.load() - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Object Types', - expanded: false, - selected: false - }, - { - text: 'Collection Types', - expanded: false, - selected: false - }, - { - text: 'Data Set Types', - expanded: false, - selected: false - }, - { - text: 'Material Types', - expanded: false, - selected: false - }, - { - text: 'Vocabulary Types', - expanded: false, - selected: false - } - ]) - - context.expectNoActions() - }) - - test('filter', async () => { - await controller.load() - - controller.filterChange('ANOTHER') - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Object Types', - expanded: true, - selected: false, - children: [ - { - text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, - expanded: false, - selected: false - } - ] - }, - { - text: 'Material Types', - expanded: true, - selected: false, - children: [ - { - text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code, - expanded: false, - selected: false - } - ] - }, - { - text: 'Vocabulary Types', - expanded: true, - selected: false, - children: [ - { - text: fixture.ANOTHER_VOCABULARY_DTO.code, - expanded: false, - selected: false - } - ] - } - ]) - - context.expectNoActions() - }) - - test('add node', async () => { - await controller.load() - - controller.nodeSelect('objectTypes') - controller.nodeAdd() - - expectNewTypeAction(objectType.NEW_OBJECT_TYPE) - }) - - test('remove node', async () => { - openbis.mockSearchPropertyTypes([fixture.TEST_PROPERTY_TYPE_1_DTO]) - openbis.deleteSampleTypes.mockReturnValue(Promise.resolve()) - - await controller.load() - - expect(controller.isRemoveNodeDialogOpen()).toBe(false) - expect(openbis.deleteSampleTypes).toHaveBeenCalledTimes(0) - - controller.nodeSelect('objectTypes/' + fixture.TEST_SAMPLE_TYPE_DTO.code) - controller.nodeRemove() - - expect(controller.isRemoveNodeDialogOpen()).toBe(true) - expect(openbis.deleteSampleTypes).toHaveBeenCalledTimes(0) - - await controller.nodeRemoveConfirm() - - expect(controller.isRemoveNodeDialogOpen()).toBe(false) - - const createDeleteTypeOperation = typeCode => { - const id = new openbis.EntityTypePermId(typeCode) - const options = new openbis.SampleTypeDeletionOptions() - options.setReason('deleted via ng_ui') - return new openbis.DeleteSampleTypesOperation([id], options) - } - - const createDeletePropertyTypeOperation = propertyTypeCode => { - const id = new openbis.PropertyTypePermId(propertyTypeCode) - const options = new openbis.PropertyTypeDeletionOptions() - options.setReason('deleted via ng_ui') - return new openbis.DeletePropertyTypesOperation([id], options) - } - - const options = new openbis.SynchronousOperationExecutionOptions() - options.setExecuteInOrder(true) - - expect(openbis.executeOperations).toHaveBeenCalledWith( - [ - createDeleteTypeOperation(fixture.TEST_SAMPLE_TYPE_DTO.code), - createDeletePropertyTypeOperation(fixture.TEST_PROPERTY_TYPE_1_DTO.code) - ], - options - ) - - expectDeleteTypeAction( - objectType.OBJECT_TYPE, - fixture.TEST_SAMPLE_TYPE_DTO.code - ) - }) -}) - -function expectNewTypeAction(type) { - context.expectAction(actions.objectNew(pages.TYPES, type)) -} - -function expectDeleteTypeAction(type, id) { - context.expectAction(actions.objectDelete(pages.TYPES, type, id)) -} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerAddNode.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerAddNode.test.js new file mode 100644 index 00000000000..e6ac9bb3162 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerAddNode.test.js @@ -0,0 +1,22 @@ +import TypeBrowserControllerTest from '@srcTest/js/components/types/browser/TypeBrowserControllerTest.js' +import objectType from '@src/js/common/consts/objectType.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserControllerTest() + common.beforeEach() +}) + +describe(TypeBrowserControllerTest.SUITE, () => { + test('add node', testAddNode) +}) + +async function testAddNode() { + await common.controller.load() + + common.controller.nodeSelect('objectTypes') + common.controller.nodeAdd() + + common.expectNewTypeAction(objectType.NEW_OBJECT_TYPE) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerFilter.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerFilter.test.js new file mode 100644 index 00000000000..3de48fb648e --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerFilter.test.js @@ -0,0 +1,60 @@ +import TypeBrowserControllerTest from '@srcTest/js/components/types/browser/TypeBrowserControllerTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserControllerTest() + common.beforeEach() +}) + +describe(TypeBrowserControllerTest.SUITE, () => { + test('filter', testFilter) +}) + +async function testFilter() { + await common.controller.load() + + common.controller.filterChange('ANOTHER') + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Object Types', + expanded: true, + selected: false, + children: [ + { + text: fixture.ANOTHER_SAMPLE_TYPE_DTO.code, + expanded: false, + selected: false + } + ] + }, + { + text: 'Material Types', + expanded: true, + selected: false, + children: [ + { + text: fixture.ANOTHER_MATERIAL_TYPE_DTO.code, + expanded: false, + selected: false + } + ] + }, + { + text: 'Vocabulary Types', + expanded: true, + selected: false, + children: [ + { + text: fixture.ANOTHER_VOCABULARY_DTO.code, + expanded: false, + selected: false + } + ] + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerLoad.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerLoad.test.js new file mode 100644 index 00000000000..85c4b3a9138 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerLoad.test.js @@ -0,0 +1,46 @@ +import TypeBrowserControllerTest from '@srcTest/js/components/types/browser/TypeBrowserControllerTest.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserControllerTest() + common.beforeEach() +}) + +describe(TypeBrowserControllerTest.SUITE, () => { + test('load', testLoad) +}) + +async function testLoad() { + await common.controller.load() + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Object Types', + expanded: false, + selected: false + }, + { + text: 'Collection Types', + expanded: false, + selected: false + }, + { + text: 'Data Set Types', + expanded: false, + selected: false + }, + { + text: 'Material Types', + expanded: false, + selected: false + }, + { + text: 'Vocabulary Types', + expanded: false, + selected: false + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerRemoveNode.test.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerRemoveNode.test.js new file mode 100644 index 00000000000..1efd40bd895 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerRemoveNode.test.js @@ -0,0 +1,67 @@ +import TypeBrowserControllerTest from '@srcTest/js/components/types/browser/TypeBrowserControllerTest.js' +import objectType from '@src/js/common/consts/objectType.js' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new TypeBrowserControllerTest() + common.beforeEach() +}) + +describe(TypeBrowserControllerTest.SUITE, () => { + test('remove node', testRemoveNode) +}) + +async function testRemoveNode() { + openbis.mockSearchPropertyTypes([fixture.TEST_PROPERTY_TYPE_1_DTO]) + openbis.deleteSampleTypes.mockReturnValue(Promise.resolve()) + + await common.controller.load() + + expect(common.controller.isRemoveNodeDialogOpen()).toBe(false) + expect(openbis.deleteSampleTypes).toHaveBeenCalledTimes(0) + + common.controller.nodeSelect( + 'objectTypes/' + fixture.TEST_SAMPLE_TYPE_DTO.code + ) + common.controller.nodeRemove() + + expect(common.controller.isRemoveNodeDialogOpen()).toBe(true) + expect(openbis.deleteSampleTypes).toHaveBeenCalledTimes(0) + + await common.controller.nodeRemoveConfirm() + + expect(common.controller.isRemoveNodeDialogOpen()).toBe(false) + + const createDeleteTypeOperation = typeCode => { + const id = new openbis.EntityTypePermId(typeCode) + const options = new openbis.SampleTypeDeletionOptions() + options.setReason('deleted via ng_ui') + return new openbis.DeleteSampleTypesOperation([id], options) + } + + const createDeletePropertyTypeOperation = propertyTypeCode => { + const id = new openbis.PropertyTypePermId(propertyTypeCode) + const options = new openbis.PropertyTypeDeletionOptions() + options.setReason('deleted via ng_ui') + return new openbis.DeletePropertyTypesOperation([id], options) + } + + const options = new openbis.SynchronousOperationExecutionOptions() + options.setExecuteInOrder(true) + + expect(openbis.executeOperations).toHaveBeenCalledWith( + [ + createDeleteTypeOperation(fixture.TEST_SAMPLE_TYPE_DTO.code), + createDeletePropertyTypeOperation(fixture.TEST_PROPERTY_TYPE_1_DTO.code) + ], + options + ) + + common.expectDeleteTypeAction( + objectType.OBJECT_TYPE, + fixture.TEST_SAMPLE_TYPE_DTO.code + ) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerTest.js b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerTest.js new file mode 100644 index 00000000000..d7fd9e3c177 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/browser/TypeBrowserControllerTest.js @@ -0,0 +1,44 @@ +import TypeBrowserController from '@src/js/components/types/browser/TypeBrowserController.js' +import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' +import openbis from '@srcTest/js/services/openbis.js' +import pages from '@src/js/common/consts/pages.js' +import actions from '@src/js/store/actions/actions.js' +import fixture from '@srcTest/js/common/fixture.js' + +export default class TypeBrowserControllerTest { + static SUITE = 'TypeBrowserController' + + beforeEach() { + jest.resetAllMocks() + + this.context = new ComponentContext() + this.controller = new TypeBrowserController() + this.controller.init(this.context) + + openbis.mockSearchSampleTypes([ + fixture.TEST_SAMPLE_TYPE_DTO, + fixture.ANOTHER_SAMPLE_TYPE_DTO + ]) + + openbis.mockSearchExperimentTypes([fixture.TEST_EXPERIMENT_TYPE_DTO]) + openbis.mockSearchDataSetTypes([fixture.TEST_DATA_SET_TYPE_DTO]) + + openbis.mockSearchMaterialTypes([ + fixture.TEST_MATERIAL_TYPE_DTO, + fixture.ANOTHER_MATERIAL_TYPE_DTO + ]) + + openbis.mockSearchVocabularies([ + fixture.TEST_VOCABULARY_DTO, + fixture.ANOTHER_VOCABULARY_DTO + ]) + } + + expectNewTypeAction(type) { + this.context.expectAction(actions.objectNew(pages.TYPES, type)) + } + + expectDeleteTypeAction(type, id) { + this.context.expectAction(actions.objectDelete(pages.TYPES, type, id)) + } +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddProperty.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddProperty.test.js index 8c55ac5593e..30f7729caa7 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddProperty.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddProperty.test.js @@ -10,7 +10,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentAddProperty', () => { +describe(TypeFormComponentTest.SUITE, () => { test('add local property', testAddLocalProperty) test('add new global property', testAddNewGlobalProperty) test('add existing global property', testAddExistingGlobalProperty) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddSection.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddSection.test.js index 3672245a920..8bf337318ce 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddSection.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentAddSection.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentAddSection', () => { +describe(TypeFormComponentTest.SUITE, () => { test('add section', testAddSection) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeProperty.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeProperty.test.js index b8a36cefa3d..4675d2303fe 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeProperty.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeProperty.test.js @@ -9,7 +9,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentChangeProperty', () => { +describe(TypeFormComponentTest.SUITE, () => { test('change property', testChangeProperty) test('convert property', testConvertProperty) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeSection.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeSection.test.js index 939dd4cb2e7..7531cddcf5d 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeSection.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeSection.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentChangeSection', () => { +describe(TypeFormComponentTest.SUITE, () => { test('change section', testChangeSection) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeType.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeType.test.js index b10103afa1d..6b61509eb75 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeType.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentChangeType.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentChangeType', () => { +describe(TypeFormComponentTest.SUITE, () => { test('change type', testChangeType) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentInternal.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentInternal.test.js index c5f24cc6256..ecf0117db81 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentInternal.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentInternal.test.js @@ -10,7 +10,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentInternal', () => { +describe(TypeFormComponentTest.SUITE, () => { test('internal', testInternal) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentLoad.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentLoad.test.js index 7dd76a5801e..d13c97bbcc8 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentLoad.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentLoad.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentLoad', () => { +describe(TypeFormComponentTest.SUITE, () => { test('load new', testLoadNew) test('load existing', testLoadExisting) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveProperty.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveProperty.test.js index 50005ad1f45..269feb492fb 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveProperty.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveProperty.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentRemoveProperty', () => { +describe(TypeFormComponentTest.SUITE, () => { test('remove property', testRemoveProperty) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveSection.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveSection.test.js index 365ba639299..5d7da08e00f 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveSection.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentRemoveSection.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentRemoveSection', () => { +describe(TypeFormComponentTest.SUITE, () => { test('remove section', testRemoveSection) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectProperty.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectProperty.test.js index abdfea7d26d..1e3d1ff021b 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectProperty.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectProperty.test.js @@ -10,7 +10,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentSelectProperty', () => { +describe(TypeFormComponentTest.SUITE, () => { test('select property local unused', testSelectPropertyLocalUnused) test('select property local used', testSelectPropertyLocalUsed) test('select property global unused', testSelectPropertyGlobalUnused) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectSection.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectSection.test.js index 3baaeebd811..90e7b101670 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectSection.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentSelectSection.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentSelectSection', () => { +describe(TypeFormComponentTest.SUITE, () => { test('select section', testSelectSection) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentTest.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentTest.js index b0476dd17c2..13931192b82 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentTest.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentTest.js @@ -9,6 +9,8 @@ import objectTypes from '@src/js/common/consts/objectType.js' jest.mock('@src/js/components/types/form/TypeFormFacade') export default class TypeFormComponentTest extends ComponentTest { + static SUITE = 'TypeFormComponent' + constructor() { super( object => <TypeForm object={object} controller={this.controller} />, diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentValidate.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentValidate.test.js index ad0a59e4a23..80548a67766 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentValidate.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormComponentValidate.test.js @@ -7,7 +7,7 @@ beforeEach(() => { common.beforeEach() }) -describe('TypeFormComponentValidate', () => { +describe(TypeFormComponentTest.SUITE, () => { test('validate type', testValidateType) test('validate property', testValidateProperty) test('validate type and property', testValidateTypeAndProperty) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddProperty.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddProperty.test.js index a1884dc71e5..f65e8d3341a 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddProperty.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddProperty.test.js @@ -1,209 +1,200 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() }) -describe('TypeFormController.handleAddProperty', () => { - test('add with a section selected', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) +describe(TypeFormControllerTest.SUITE, () => { + test('add property with a section selected', testAddWithSectionSelected) + test('add property with a property selected', testAddWithPropertySelected) +}) - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-1' - }) +async function testAddWithSectionSelected() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-1' - } + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-1' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - controller.handleAddProperty() + common.controller.handleAddProperty() - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-3' - } + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-3' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - }, - { - id: 'property-3', - code: { value: null } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2', 'property-3'] - } - ] - }) + { + id: 'property-3', + code: { value: null } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2', 'property-3'] + } + ] }) +} - test('add with a property selected', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) +async function testAddWithPropertySelected() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1' - }) + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1' + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - controller.handleAddProperty() + common.controller.handleAddProperty() - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-3' - } + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-3' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - }, - { - id: 'property-3', - code: { value: null } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-3', 'property-2'] - } - ] - }) + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + }, + { + id: 'property-3', + code: { value: null } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-3', 'property-2'] + } + ] }) -}) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddSection.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddSection.test.js index dbbbcb0ecd1..368cefd8146 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddSection.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerAddSection.test.js @@ -1,208 +1,200 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() +}) + +describe(TypeFormControllerTest.SUITE, () => { + test('add section with nothing selected', testAddWithNothingSelected) + test('add section with a property selected', testAddWithPropertySelected) + test('add section with a section selected', testAddWithSectionSelected) }) -describe('TypeFormController.handleAddProperty', () => { - test('add with nothing selected', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - selection: null, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleAddSection() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-2' - } +async function testAddWithNothingSelected() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + selection: null, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] }, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - }, - { - id: 'section-2', - name: { value: null }, - properties: [] - } - ] - }) + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) - test('add with a property selected', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0' - }) - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-0' - } + common.controller.handleAddSection() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-2' + } + }, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] }, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleAddSection() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-2' - } + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + }, + { + id: 'section-2', + name: { value: null }, + properties: [] + } + ] + }) +} + +async function testAddWithPropertySelected() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-0' + } + }, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] }, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-2', - name: { value: null }, - properties: [] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) - test('add with a section selected', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } + common.controller.handleAddSection() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-2' + } + }, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] }, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleAddSection() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-2' - } + { + id: 'section-2', + name: { value: null }, + properties: [] }, - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-2', - name: { value: null }, - properties: [] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) -}) +} + +async function testAddWithSectionSelected() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + common.controller.handleAddSection() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-2' + } + }, + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-2', + name: { value: null }, + properties: [] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerChange.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerChange.test.js index 54d63ebcd39..e47eacf5d3e 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerChange.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerChange.test.js @@ -1,155 +1,147 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() }) -describe('TypeFormController.handleChange', () => { - test('type', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) +describe(TypeFormControllerTest.SUITE, () => { + test('change type', testChangeType) + test('change section', testChangeSection) + test('change property', testChangeProperty) +}) - await controller.load() +async function testChangeType() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) - expect(context.getState()).toMatchObject({ - type: { - description: { value: 'TEST_DESCRIPTION' } + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + type: { + description: { value: 'TEST_DESCRIPTION' } + } + }) + + common.controller.handleChange(TypeFormSelectionType.TYPE, { + field: 'description', + value: 'NEW_DESCRIPTION' + }) + + expect(common.context.getState()).toMatchObject({ + type: { + description: { value: 'NEW_DESCRIPTION' } + } + }) +} + +async function testChangeSection() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] } - }) + ] + }) - controller.handleChange(TypeFormSelectionType.TYPE, { - field: 'description', - value: 'NEW_DESCRIPTION' - }) + common.controller.handleChange(TypeFormSelectionType.SECTION, { + id: 'section-1', + field: 'name', + value: 'TEST_NAME' + }) - expect(context.getState()).toMatchObject({ - type: { - description: { value: 'NEW_DESCRIPTION' } + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_NAME' }, + properties: ['property-1', 'property-2'] } - }) + ] + }) +} + +async function testChangeProperty() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + description: { value: null } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ] }) - test('section', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleChange(TypeFormSelectionType.SECTION, { - id: 'section-1', - field: 'name', - value: 'TEST_NAME' - }) - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_NAME' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1', + field: 'description', + value: 'TEST_DESCRIPTION' }) - test('property', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - description: { value: null } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ] - }) - - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1', - field: 'description', - value: 'TEST_DESCRIPTION' - }) - - expect(context.getState()).toMatchObject({ - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - description: { value: 'TEST_DESCRIPTION' } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ] - }) + expect(common.context.getState()).toMatchObject({ + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + description: { value: 'TEST_DESCRIPTION' } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ] }) -}) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerLoad.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerLoad.test.js index 6e64884070f..91bbd1df4ad 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerLoad.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerLoad.test.js @@ -1,11 +1,287 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import openbis from '@srcTest/js/services/openbis.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') +let common = null + +beforeEach(() => { + common = new TypeFormControllerTest() + common.beforeEach() +}) + +describe(TypeFormControllerTest.SUITE, () => { + test('load successful existing', testLoadSuccessfulExisting) + test('load successful new', testLoadSuccessfulNew) + test('load maintains section selection', testLoadMaintainsSectionSelection) + test('load maintains property selection', testLoadMaintainsPropertySelection) +}) + +async function testLoadSuccessfulExisting() { + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE + }) + + common.facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) + common.facade.loadUsages.mockReturnValue( + Promise.resolve({ + type: 10, + propertyLocal: { + [TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1, + [TEST_PROPERTY_TYPE_2_DTO.getCode()]: 2 + }, + propertyGlobal: { + [TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10, + [TEST_PROPERTY_TYPE_2_DTO.getCode()]: 20 + } + }) + ) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + loading: false, + selection: null, + type: { + code: { value: 'TEST_TYPE' }, + description: { value: 'TEST_DESCRIPTION' }, + listable: { value: true }, + showContainer: { value: true }, + showParents: { value: true }, + showParentMetadata: { value: true }, + autoGeneratedCode: { value: true }, + generatedCodePrefix: { value: 'TEST_PREFIX' }, + subcodeUnique: { value: true }, + validationPlugin: { value: 'TEST_PLUGIN_2' }, + usages: 10 + }, + properties: [ + { + id: 'property-0', + code: { value: 'TEST_PROPERTY_TYPE_1' }, + label: { value: 'TEST_LABEL_1' }, + description: { value: 'TEST_DESCRIPTION_1' }, + dataType: { value: 'INTEGER' }, + plugin: { value: 'TEST_PLUGIN_1' }, + mandatory: { value: true }, + showInEditView: { value: true }, + showRawValueInForms: { value: true }, + usagesLocal: 1, + usagesGlobal: 10, + section: 'section-0' + }, + { + id: 'property-1', + code: { value: 'TEST_PROPERTY_TYPE_2' }, + label: { value: 'TEST_LABEL_2' }, + description: { value: 'TEST_DESCRIPTION_2' }, + dataType: { value: 'CONTROLLEDVOCABULARY' }, + vocabulary: { value: 'TEST_VOCABULARY' }, + mandatory: { value: true }, + showInEditView: { value: false }, + showRawValueInForms: { value: true }, + usagesLocal: 2, + usagesGlobal: 20, + section: 'section-1' + }, + { + id: 'property-2', + code: { value: 'TEST_PROPERTY_TYPE_3' }, + label: { value: 'TEST_LABEL_3' }, + description: { value: 'TEST_DESCRIPTION_3' }, + dataType: { value: 'MATERIAL' }, + materialType: { value: 'TEST_MATERIAL_TYPE' }, + mandatory: { value: false }, + showInEditView: { value: true }, + showRawValueInForms: { value: false }, + usagesLocal: 0, + usagesGlobal: 0, + section: 'section-1' + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + expect(common.facade.loadType).toHaveBeenCalledWith( + common.context.getProps().object + ) + expect(common.facade.loadUsages).toHaveBeenCalledWith( + common.context.getProps().object + ) +} + +async function testLoadSuccessfulNew() { + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.NEW_OBJECT_TYPE + }) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + loading: false, + selection: null, + type: { + code: { value: null }, + description: { value: null }, + listable: { value: true }, + showContainer: { value: false }, + showParents: { value: true }, + showParentMetadata: { value: false }, + autoGeneratedCode: { value: true }, + generatedCodePrefix: { value: null }, + subcodeUnique: { value: false }, + validationPlugin: { value: null }, + usages: 0 + }, + properties: [], + sections: [] + }) +} + +async function testLoadMaintainsSectionSelection() { + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE + }) + + common.facade.loadType.mockReturnValue( + Promise.resolve(new openbis.SampleType()) + ) + common.facade.loadUsages.mockReturnValue({}) + + await common.controller.load() + + common.controller.handleAddSection() + common.controller.handleAddProperty() + common.controller.handleAddProperty() + common.controller.handleAddSection() + common.controller.handleAddProperty() + common.controller.handleOrderChange(TypeFormSelectionType.SECTION, { + fromIndex: 0, + toIndex: 1 + }) + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { id: 'section-0' } + }, + sections: [ + { + id: 'section-1', + properties: ['property-2'] + }, + { + id: 'section-0', + properties: ['property-0', 'property-1'] + } + ] + }) + + common.facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) + common.facade.loadUsages.mockReturnValue({}) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { id: 'section-1' } + }, + sections: [ + { + id: 'section-0', + properties: ['property-0'] + }, + { + id: 'section-1', + properties: ['property-1', 'property-2'] + } + ] + }) +} + +async function testLoadMaintainsPropertySelection() { + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE + }) + + common.facade.loadType.mockReturnValue( + Promise.resolve(new openbis.SampleType()) + ) + common.facade.loadUsages.mockReturnValue({}) + + await common.controller.load() + + common.controller.handleAddSection() + common.controller.handleAddProperty() + common.controller.handleAddProperty() + common.controller.handleAddSection() + common.controller.handleAddProperty() + common.controller.handleOrderChange(TypeFormSelectionType.SECTION, { + fromIndex: 0, + toIndex: 1 + }) + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { id: 'property-1' } + }, + sections: [ + { + id: 'section-1', + properties: ['property-2'] + }, + { + id: 'section-0', + properties: ['property-0', 'property-1'] + } + ] + }) + + common.facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) + common.facade.loadUsages.mockReturnValue({}) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { id: 'property-2' } + }, + sections: [ + { + id: 'section-0', + properties: ['property-0'] + }, + { + id: 'section-1', + properties: ['property-1', 'property-2'] + } + ] + }) +} const TEST_PLUGIN_1 = new openbis.Plugin() TEST_PLUGIN_1.setName('TEST_PLUGIN_1') @@ -77,286 +353,3 @@ TEST_SAMPLE_TYPE_DTO.setPropertyAssignments([ TEST_PROPERTY_ASSIGNMENT_2, TEST_PROPERTY_ASSIGNMENT_3 ]) - -let context = null -let facade = null -let controller = null - -beforeEach(() => { - jest.resetAllMocks() - - context = new ComponentContext() - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) -}) - -describe('TypeFormController.load', () => { - test('successful existing', async () => { - facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) - facade.loadUsages.mockReturnValue( - Promise.resolve({ - type: 10, - propertyLocal: { - [TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1, - [TEST_PROPERTY_TYPE_2_DTO.getCode()]: 2 - }, - propertyGlobal: { - [TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10, - [TEST_PROPERTY_TYPE_2_DTO.getCode()]: 20 - } - }) - ) - - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } - }) - - controller.init(context) - await controller.load() - - expect(context.getState()).toMatchObject({ - loading: false, - selection: null, - type: { - code: { value: 'TEST_TYPE' }, - description: { value: 'TEST_DESCRIPTION' }, - listable: { value: true }, - showContainer: { value: true }, - showParents: { value: true }, - showParentMetadata: { value: true }, - autoGeneratedCode: { value: true }, - generatedCodePrefix: { value: 'TEST_PREFIX' }, - subcodeUnique: { value: true }, - validationPlugin: { value: 'TEST_PLUGIN_2' }, - usages: 10 - }, - properties: [ - { - id: 'property-0', - code: { value: 'TEST_PROPERTY_TYPE_1' }, - label: { value: 'TEST_LABEL_1' }, - description: { value: 'TEST_DESCRIPTION_1' }, - dataType: { value: 'INTEGER' }, - plugin: { value: 'TEST_PLUGIN_1' }, - mandatory: { value: true }, - showInEditView: { value: true }, - showRawValueInForms: { value: true }, - usagesLocal: 1, - usagesGlobal: 10, - section: 'section-0' - }, - { - id: 'property-1', - code: { value: 'TEST_PROPERTY_TYPE_2' }, - label: { value: 'TEST_LABEL_2' }, - description: { value: 'TEST_DESCRIPTION_2' }, - dataType: { value: 'CONTROLLEDVOCABULARY' }, - vocabulary: { value: 'TEST_VOCABULARY' }, - mandatory: { value: true }, - showInEditView: { value: false }, - showRawValueInForms: { value: true }, - usagesLocal: 2, - usagesGlobal: 20, - section: 'section-1' - }, - { - id: 'property-2', - code: { value: 'TEST_PROPERTY_TYPE_3' }, - label: { value: 'TEST_LABEL_3' }, - description: { value: 'TEST_DESCRIPTION_3' }, - dataType: { value: 'MATERIAL' }, - materialType: { value: 'TEST_MATERIAL_TYPE' }, - mandatory: { value: false }, - showInEditView: { value: true }, - showRawValueInForms: { value: false }, - usagesLocal: 0, - usagesGlobal: 0, - section: 'section-1' - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) - }) - - test('successful new', async () => { - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.NEW_OBJECT_TYPE - } - }) - controller.init(context) - await controller.load() - - expect(context.getState()).toMatchObject({ - loading: false, - selection: null, - type: { - code: { value: null }, - description: { value: null }, - listable: { value: true }, - showContainer: { value: false }, - showParents: { value: true }, - showParentMetadata: { value: false }, - autoGeneratedCode: { value: true }, - generatedCodePrefix: { value: null }, - subcodeUnique: { value: false }, - validationPlugin: { value: null }, - usages: 0 - }, - properties: [], - sections: [] - }) - }) - - test('maintain section selection', async () => { - const emptyType = new openbis.SampleType() - - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } - }) - controller.init(context) - - facade.loadType.mockReturnValue(Promise.resolve(emptyType)) - facade.loadUsages.mockReturnValue({}) - await controller.load() - - controller.handleAddSection() - controller.handleAddProperty() - controller.handleAddProperty() - controller.handleAddSection() - controller.handleAddProperty() - controller.handleOrderChange(TypeFormSelectionType.SECTION, { - fromIndex: 0, - toIndex: 1 - }) - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { id: 'section-0' } - }, - sections: [ - { - id: 'section-1', - properties: ['property-2'] - }, - { - id: 'section-0', - properties: ['property-0', 'property-1'] - } - ] - }) - - facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) - facade.loadUsages.mockReturnValue({}) - await controller.load() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { id: 'section-1' } - }, - sections: [ - { - id: 'section-0', - properties: ['property-0'] - }, - { - id: 'section-1', - properties: ['property-1', 'property-2'] - } - ] - }) - }) - - test('maintain property selection', async () => { - const emptyType = new openbis.SampleType() - - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } - }) - controller.init(context) - - facade.loadType.mockReturnValue(Promise.resolve(emptyType)) - facade.loadUsages.mockReturnValue({}) - await controller.load() - - controller.handleAddSection() - controller.handleAddProperty() - controller.handleAddProperty() - controller.handleAddSection() - controller.handleAddProperty() - controller.handleOrderChange(TypeFormSelectionType.SECTION, { - fromIndex: 0, - toIndex: 1 - }) - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1' - }) - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { id: 'property-1' } - }, - sections: [ - { - id: 'section-1', - properties: ['property-2'] - }, - { - id: 'section-0', - properties: ['property-0', 'property-1'] - } - ] - }) - - facade.loadType.mockReturnValue(Promise.resolve(TEST_SAMPLE_TYPE_DTO)) - facade.loadUsages.mockReturnValue({}) - await controller.load() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { id: 'property-2' } - }, - sections: [ - { - id: 'section-0', - properties: ['property-0'] - }, - { - id: 'section-1', - properties: ['property-1', 'property-2'] - } - ] - }) - }) -}) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerOrderChange.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerOrderChange.test.js index 92b87fef7af..ac74ebc5c28 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerOrderChange.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerOrderChange.test.js @@ -1,169 +1,161 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() +}) + +describe(TypeFormControllerTest.SUITE, () => { + test('move section', testMoveSection) + test('move property within section', testMovePropertyWithinSection) + test('move property between sections', testMovePropertyBetweenSections) }) -describe('TypeFormController.handleOrderChange', () => { - test('section', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleOrderChange(TypeFormSelectionType.SECTION, { - fromIndex: 0, - toIndex: 1 - }) - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - }, - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - } - ] - }) +async function testMoveSection() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) - test('property within section', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleOrderChange(TypeFormSelectionType.PROPERTY, { - fromSectionId: 'section-1', - toSectionId: 'section-1', - fromIndex: 0, - toIndex: 1 - }) - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-2', 'property-1'] - } - ] - }) + common.controller.handleOrderChange(TypeFormSelectionType.SECTION, { + fromIndex: 0, + toIndex: 1 }) - test('property between sections', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) - - controller.handleOrderChange(TypeFormSelectionType.PROPERTY, { - fromSectionId: 'section-1', - toSectionId: 'section-0', - fromIndex: 1, - toIndex: 0 - }) - - expect(context.getState()).toMatchObject({ - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-2', 'property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1'] - } - ] - }) + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + }, + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + } + ] }) -}) +} + +async function testMovePropertyWithinSection() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + common.controller.handleOrderChange(TypeFormSelectionType.PROPERTY, { + fromSectionId: 'section-1', + toSectionId: 'section-1', + fromIndex: 0, + toIndex: 1 + }) + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-2', 'property-1'] + } + ] + }) +} + +async function testMovePropertyBetweenSections() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + common.controller.handleOrderChange(TypeFormSelectionType.PROPERTY, { + fromSectionId: 'section-1', + toSectionId: 'section-0', + fromIndex: 1, + toIndex: 0 + }) + + expect(common.context.getState()).toMatchObject({ + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-2', 'property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1'] + } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerRemove.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerRemove.test.js index 14b925509d1..ba9ed49bf18 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerRemove.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerRemove.test.js @@ -1,703 +1,698 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() }) -describe('TypeFormController.handleRemove', () => { - test('section not used', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) +describe(TypeFormControllerTest.SUITE, () => { + test('remove section not used', testRemoveSectionNotUsed) + test('remove section used and confirmed', testRemoveSectionUsedAndConfirmed) + test('remove section used and cancelled', testRemoveSectionUsedAndCancelled) + test('remove property not used', testRemovePropertyNotUsed) + test('remove property used and confirmed', testRemovePropertyUsedAndConfirmed) + test('remove property used and cancelled', testRemovePropertyUsedAndCancelled) +}) - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) +async function testRemoveSectionNotUsed() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' + }) - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - selection: null, - properties: [ - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) - test('section used and confirmed', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue( - Promise.resolve({ - propertyLocal: { - [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1 - }, - propertyGlobal: { - [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10 - } - }) - ) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) + common.controller.handleRemove() - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] + expect(common.context.getState()).toMatchObject({ + selection: null, + properties: [ + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) +} + +async function testRemoveSectionUsedAndConfirmed() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue( + Promise.resolve({ + propertyLocal: { + [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1 + }, + propertyGlobal: { + [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10 + } }) + ) - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - removeSectionDialogOpen: true, - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' + }) - controller.handleRemoveConfirm() - - expect(context.getState()).toMatchObject({ - removeSectionDialogOpen: false, - selection: null, - properties: [ - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] }) - test('section used and cancelled', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue( - Promise.resolve({ - propertyLocal: { - [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1 - }, - propertyGlobal: { - [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10 - } - }) - ) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) + common.controller.handleRemove() + + expect(common.context.getState()).toMatchObject({ + removeSectionDialogOpen: true, + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleRemoveConfirm() - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - removeSectionDialogOpen: true, - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] + expect(common.context.getState()).toMatchObject({ + removeSectionDialogOpen: false, + selection: null, + properties: [ + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) +} + +async function testRemoveSectionUsedAndCancelled() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue( + Promise.resolve({ + propertyLocal: { + [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 1 + }, + propertyGlobal: { + [fixture.TEST_PROPERTY_TYPE_1_DTO.getCode()]: 10 + } }) + ) - controller.handleRemoveCancel() - - expect(context.getState()).toMatchObject({ - removeSectionDialogOpen: false, - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' }) - test('property not used', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1' - }) + common.controller.handleRemove() + + expect(common.context.getState()).toMatchObject({ + removeSectionDialogOpen: true, + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleRemoveCancel() + + expect(common.context.getState()).toMatchObject({ + removeSectionDialogOpen: false, + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) +} - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - selection: null, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-2'] - } - ] - }) +async function testRemovePropertyNotUsed() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1' }) - test('property used and confirmed', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue( - Promise.resolve({ - propertyLocal: { - [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 1 - }, - propertyGlobal: { - [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 10 - } - }) - ) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1' - }) + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleRemove() - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - removePropertyDialogOpen: true, - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] + expect(common.context.getState()).toMatchObject({ + selection: null, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-2'] + } + ] + }) +} + +async function testRemovePropertyUsedAndConfirmed() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue( + Promise.resolve({ + propertyLocal: { + [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 1 + }, + propertyGlobal: { + [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 10 + } }) + ) - controller.handleRemoveConfirm() - - expect(context.getState()).toMatchObject({ - removePropertyDialogOpen: false, - selection: null, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-2'] - } - ] - }) + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1' }) - test('property used and cancelled', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue( - Promise.resolve({ - propertyLocal: { - [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 1 - }, - propertyGlobal: { - [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 10 - } - }) - ) - - await controller.load() - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-1' - }) + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleRemove() + + expect(common.context.getState()).toMatchObject({ + removePropertyDialogOpen: true, + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) - controller.handleRemove() - - expect(context.getState()).toMatchObject({ - removePropertyDialogOpen: true, - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] - }) + common.controller.handleRemoveConfirm() - controller.handleRemoveCancel() - - expect(context.getState()).toMatchObject({ - removePropertyDialogOpen: false, - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-1' - } - }, - properties: [ - { - id: 'property-0', - code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } - }, - { - id: 'property-1', - code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, - usagesLocal: 1, - usagesGlobal: 10 - }, - { - id: 'property-2', - code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } - } - ], - sections: [ - { - id: 'section-0', - name: { value: 'TEST_SECTION_1' }, - properties: ['property-0'] - }, - { - id: 'section-1', - name: { value: 'TEST_SECTION_2' }, - properties: ['property-1', 'property-2'] - } - ] + expect(common.context.getState()).toMatchObject({ + removePropertyDialogOpen: false, + selection: null, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-2'] + } + ] + }) +} + +async function testRemovePropertyUsedAndCancelled() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue( + Promise.resolve({ + propertyLocal: { + [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 1 + }, + propertyGlobal: { + [fixture.TEST_PROPERTY_TYPE_2_DTO.getCode()]: 10 + } }) + ) + + await common.controller.load() + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-1' }) -}) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + common.controller.handleRemove() + + expect(common.context.getState()).toMatchObject({ + removePropertyDialogOpen: true, + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) + + common.controller.handleRemoveCancel() + + expect(common.context.getState()).toMatchObject({ + removePropertyDialogOpen: false, + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-1' + } + }, + properties: [ + { + id: 'property-0', + code: { value: fixture.TEST_PROPERTY_TYPE_1_DTO.getCode() } + }, + { + id: 'property-1', + code: { value: fixture.TEST_PROPERTY_TYPE_2_DTO.getCode() }, + usagesLocal: 1, + usagesGlobal: 10 + }, + { + id: 'property-2', + code: { value: fixture.TEST_PROPERTY_TYPE_3_DTO.getCode() } + } + ], + sections: [ + { + id: 'section-0', + name: { value: 'TEST_SECTION_1' }, + properties: ['property-0'] + }, + { + id: 'section-1', + name: { value: 'TEST_SECTION_2' }, + properties: ['property-1', 'property-2'] + } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSave.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSave.test.js index 9b442c6b76b..602803bfdb5 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSave.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSave.test.js @@ -1,440 +1,389 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import openbis from '@srcTest/js/services/openbis.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -const LOCAL_PROPERTY_TYPE = new openbis.PropertyType() -LOCAL_PROPERTY_TYPE.setCode('TEST_TYPE.TEST_PROPERTY_TYPE') -LOCAL_PROPERTY_TYPE.setLabel('TEST_LABEL') -LOCAL_PROPERTY_TYPE.setDescription('TEST_DESCRIPTION') -LOCAL_PROPERTY_TYPE.setDataType(openbis.DataType.INTEGER) - -const LOCAL_PROPERTY_ASSIGNMENT = new openbis.PropertyAssignment() -LOCAL_PROPERTY_ASSIGNMENT.setPropertyType(LOCAL_PROPERTY_TYPE) - -const SAMPLE_TYPE_WITH_LOCAL_PROPERTY = new openbis.SampleType() -SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setCode('TEST_TYPE') -SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setGeneratedCodePrefix('TEST_PREFIX') -SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setPropertyAssignments([ - LOCAL_PROPERTY_ASSIGNMENT -]) - -const GLOBAL_PROPERTY_TYPE = new openbis.PropertyType() -GLOBAL_PROPERTY_TYPE.setCode('TEST_PROPERTY_TYPE') -GLOBAL_PROPERTY_TYPE.setLabel('TEST_LABEL') -GLOBAL_PROPERTY_TYPE.setDescription('TEST_DESCRIPTION') -GLOBAL_PROPERTY_TYPE.setDataType(openbis.DataType.INTEGER) - -const GLOBAL_PROPERTY_ASSIGNMENT = new openbis.PropertyAssignment() -GLOBAL_PROPERTY_ASSIGNMENT.setPropertyType(GLOBAL_PROPERTY_TYPE) - -const SAMPLE_TYPE_WITH_GLOBAL_PROPERTY = new openbis.SampleType() -SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setCode('TEST_TYPE') -SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setGeneratedCodePrefix('TEST_PREFIX') -SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setPropertyAssignments([ - GLOBAL_PROPERTY_ASSIGNMENT -]) - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() }) -describe('TypeFormController.handleSave', () => { - test('validation', async () => { - const SAMPLE_TYPE = new openbis.SampleType() - - facade.loadType.mockReturnValue(Promise.resolve(SAMPLE_TYPE)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - controller.handleAddSection() - controller.handleAddProperty() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-0' - } - }, - type: { - errors: 0 - }, - properties: [ - { - id: 'property-0', - code: { value: null }, - dataType: { value: null }, - label: { value: null }, - description: { value: null }, - errors: 0 - } - ] - }) +describe(TypeFormControllerTest.SUITE, () => { + test('save add local property', testSaveAddLocalProperty) + test('save add global property', testSaveAddGlobalProperty) + test( + 'save update local property assignment', + testSaveUpdateLocalPropertyAssignment + ) + test( + 'save update global property assignment', + testSaveUpdateGlobalPropertyAssignment + ) + test( + 'save update local property type if possible', + testSaveUpdateLocalPropertyTypeIfPossible + ) + test( + 'save update global property type if possible', + testSaveUpdateGlobalPropertyTypeIfPossible + ) + test('save delete local property', testSaveDeleteLocalProperty) + test('save delete global property', testSaveDeleteGlobalProperty) + test( + 'save delete local property last assignment', + testSaveDeleteLocalPropertyLastAssignment + ) + test( + 'save delete global property last assignment', + testSaveDeleteGlobalPropertyLastAssignment + ) +}) - await controller.handleSave() - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.TYPE, - params: { - part: 'code' - } - }, - type: { - code: { - error: 'Code cannot be empty' - }, - generatedCodePrefix: { - error: 'Generated code prefix cannot be empty' - }, - errors: 2 - }, - properties: [ - { - id: 'property-0', - code: { value: null, error: 'Code cannot be empty' }, - dataType: { value: null, error: 'Data Type cannot be empty' }, - label: { value: null, error: 'Label cannot be empty' }, - description: { value: null, error: 'Description cannot be empty' }, - errors: 4 - } - ] - }) +async function testSaveAddLocalProperty() { + await doTestAddProperty('local') +} + +async function testSaveAddGlobalProperty() { + await doTestAddProperty('global') +} + +async function testSaveUpdateLocalPropertyAssignment() { + await doTestUpdatePropertyAssignment( + SAMPLE_TYPE_WITH_LOCAL_PROPERTY, + LOCAL_PROPERTY_TYPE + ) +} + +async function testSaveUpdateGlobalPropertyAssignment() { + await doTestUpdatePropertyAssignment( + SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, + GLOBAL_PROPERTY_TYPE + ) +} + +async function testSaveUpdateLocalPropertyTypeIfPossible() { + await doTestUpdatePropertyTypeIfPossible( + SAMPLE_TYPE_WITH_LOCAL_PROPERTY, + LOCAL_PROPERTY_TYPE, + LOCAL_PROPERTY_ASSIGNMENT + ) +} + +async function testSaveUpdateGlobalPropertyTypeIfPossible() { + await doTestUpdatePropertyTypeIfPossible( + SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, + GLOBAL_PROPERTY_TYPE, + GLOBAL_PROPERTY_ASSIGNMENT + ) +} + +async function testSaveDeleteLocalProperty() { + await doTestDeleteProperty( + SAMPLE_TYPE_WITH_LOCAL_PROPERTY, + LOCAL_PROPERTY_TYPE + ) +} + +async function testSaveDeleteGlobalProperty() { + await doTestDeleteProperty( + SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, + GLOBAL_PROPERTY_TYPE + ) +} + +async function testSaveDeleteLocalPropertyLastAssignment() { + await doTestDeletePropertyLastAssignment( + SAMPLE_TYPE_WITH_LOCAL_PROPERTY, + LOCAL_PROPERTY_TYPE + ) +} + +async function testSaveDeleteGlobalPropertyLastAssignment() { + await doTestDeletePropertyLastAssignment( + SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, + GLOBAL_PROPERTY_TYPE + ) +} + +async function doTestAddProperty(scope) { + const SAMPLE_TYPE = new openbis.SampleType() + SAMPLE_TYPE.setCode('TEST_TYPE') + SAMPLE_TYPE.setGeneratedCodePrefix('TEST_PREFIX') + + common.facade.loadType.mockReturnValue(Promise.resolve(SAMPLE_TYPE)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + common.facade.loadGlobalPropertyTypes.mockReturnValue(Promise.resolve([])) + common.facade.executeOperations.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + common.controller.handleAddSection() + common.controller.handleAddProperty() + + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'scope', + value: scope }) - - test('add local property', async () => { - await testAddProperty('local') + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'code', + value: 'NEW_CODE' }) - - test('add global property', async () => { - await testAddProperty('global') + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'dataType', + value: 'VARCHAR' }) - - test('update local property assignment', async () => { - await testUpdatePropertyAssignment( - SAMPLE_TYPE_WITH_LOCAL_PROPERTY, - LOCAL_PROPERTY_TYPE - ) + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'label', + value: 'NEW_LABEL' }) - - test('update global property assignment', async () => { - await testUpdatePropertyAssignment( - SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, - GLOBAL_PROPERTY_TYPE - ) + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'description', + value: 'NEW_DESCRIPTION' }) - test('update local property type if possible', async () => { - await testUpdatePropertyTypeIfPossible( - SAMPLE_TYPE_WITH_LOCAL_PROPERTY, - LOCAL_PROPERTY_TYPE, - LOCAL_PROPERTY_ASSIGNMENT - ) - }) + await common.controller.handleSave() - test('update global property type if possible', async () => { - await testUpdatePropertyTypeIfPossible( - SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, - GLOBAL_PROPERTY_TYPE, - GLOBAL_PROPERTY_ASSIGNMENT - ) - }) + const propertyTypeCode = scope === 'local' ? 'TEST_TYPE.NEW_CODE' : 'NEW_CODE' - test('delete local property', async () => { - await testDeleteProperty( - SAMPLE_TYPE_WITH_LOCAL_PROPERTY, - LOCAL_PROPERTY_TYPE + expectExecuteOperations([ + createPropertyTypeOperation({ + code: propertyTypeCode, + dataType: openbis.DataType.VARCHAR, + label: 'NEW_LABEL' + }), + setPropertyAssignmentOperation( + SAMPLE_TYPE.getCode(), + propertyTypeCode, + false ) - }) + ]) +} - test('delete global property', async () => { - await testDeleteProperty( - SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, - GLOBAL_PROPERTY_TYPE - ) - }) +async function doTestUpdatePropertyAssignment(type, propertyType) { + common.facade.loadType.mockReturnValue(Promise.resolve(type)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + common.facade.executeOperations.mockReturnValue(Promise.resolve({})) - test('delete local property last assignment', async () => { - await testDeletePropertyLastAssignment( - SAMPLE_TYPE_WITH_LOCAL_PROPERTY, - LOCAL_PROPERTY_TYPE - ) - }) + await common.controller.load() - test('delete global property last assignment', async () => { - await testDeletePropertyLastAssignment( - SAMPLE_TYPE_WITH_GLOBAL_PROPERTY, - GLOBAL_PROPERTY_TYPE - ) + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'mandatory', + value: true }) - async function testAddProperty(scope) { - const SAMPLE_TYPE = new openbis.SampleType() - SAMPLE_TYPE.setCode('TEST_TYPE') - SAMPLE_TYPE.setGeneratedCodePrefix('TEST_PREFIX') - - facade.loadType.mockReturnValue(Promise.resolve(SAMPLE_TYPE)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - facade.loadGlobalPropertyTypes.mockReturnValue(Promise.resolve([])) - facade.executeOperations.mockReturnValue(Promise.resolve({})) + await common.controller.handleSave() - await controller.load() + expectExecuteOperations([ + setPropertyAssignmentOperation(type.getCode(), propertyType.getCode(), true) + ]) +} - controller.handleAddSection() - controller.handleAddProperty() +async function doTestUpdatePropertyTypeIfPossible( + type, + propertyType, + propertyAssignment +) { + common.facade.loadType.mockReturnValue(Promise.resolve(type)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + common.facade.executeOperations.mockReturnValue(Promise.resolve({})) - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'scope', - value: scope - }) - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'code', - value: 'NEW_CODE' - }) - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'dataType', - value: 'VARCHAR' - }) - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'label', - value: 'NEW_LABEL' - }) - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'description', - value: 'NEW_DESCRIPTION' - }) + await common.controller.load() - await controller.handleSave() - - const propertyTypeCode = - scope === 'local' ? 'TEST_TYPE.NEW_CODE' : 'NEW_CODE' - - expectExecuteOperations([ - createPropertyTypeOperation({ - code: propertyTypeCode, - dataType: openbis.DataType.VARCHAR, - label: 'NEW_LABEL' - }), - setPropertyAssignmentOperation( - SAMPLE_TYPE.getCode(), - propertyTypeCode, - false - ) - ]) - } - - async function testUpdatePropertyAssignment(type, propertyType) { - facade.loadType.mockReturnValue(Promise.resolve(type)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - facade.executeOperations.mockReturnValue(Promise.resolve({})) + common.controller.handleChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0', + field: 'label', + value: 'Updated label' + }) - await controller.load() + await common.controller.handleSave() - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'mandatory', - value: true - }) + expectExecuteOperations([ + updatePropertyTypeOperation(propertyType.getCode(), 'Updated label'), + setPropertyAssignmentOperation( + type.getCode(), + propertyType.getCode(), + propertyAssignment.isMandatory() + ) + ]) +} - await controller.handleSave() +async function doTestDeleteProperty(type, propertyType) { + common.facade.loadType.mockReturnValue(Promise.resolve(type)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + common.facade.executeOperations.mockReturnValue(Promise.resolve({})) - expectExecuteOperations([ - setPropertyAssignmentOperation( - type.getCode(), - propertyType.getCode(), - true - ) - ]) - } + await common.controller.load() - async function testUpdatePropertyTypeIfPossible( - type, - propertyType, - propertyAssignment - ) { - facade.loadType.mockReturnValue(Promise.resolve(type)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - facade.executeOperations.mockReturnValue(Promise.resolve({})) - - await controller.load() - - controller.handleChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0', - field: 'label', - value: 'Updated label' + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0' + }) + common.controller.handleRemove() + + await common.controller.handleSave() + + expectExecuteOperations([ + deletePropertyAssignmentOperation( + type.getCode(), + propertyType.getCode(), + false + ), + setPropertyAssignmentOperation(type.getCode()) + ]) +} + +async function doTestDeletePropertyLastAssignment(type, propertyType) { + common.facade.loadType.mockReturnValue(Promise.resolve(type)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + common.facade.loadAssignments.mockReturnValue( + Promise.resolve({ + [propertyType.getCode()]: 1 }) + ) + common.facade.executeOperations.mockReturnValue(Promise.resolve({})) - await controller.handleSave() + await common.controller.load() - expectExecuteOperations([ - updatePropertyTypeOperation(propertyType.getCode(), 'Updated label'), - setPropertyAssignmentOperation( - type.getCode(), - propertyType.getCode(), - propertyAssignment.isMandatory() - ) - ]) - } - - async function testDeleteProperty(type, propertyType) { - facade.loadType.mockReturnValue(Promise.resolve(type)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - facade.executeOperations.mockReturnValue(Promise.resolve({})) - - await controller.load() - - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0' - }) - controller.handleRemove() - - await controller.handleSave() - - expectExecuteOperations([ - deletePropertyAssignmentOperation( - type.getCode(), - propertyType.getCode(), - false - ), - setPropertyAssignmentOperation(type.getCode()) - ]) - } - - async function testDeletePropertyLastAssignment(type, propertyType) { - facade.loadType.mockReturnValue(Promise.resolve(type)) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - facade.loadAssignments.mockReturnValue( - Promise.resolve({ - [propertyType.getCode()]: 1 - }) + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0' + }) + common.controller.handleRemove() + + await common.controller.handleSave() + + expectExecuteOperations([ + deletePropertyAssignmentOperation( + type.getCode(), + propertyType.getCode(), + false + ), + deletePropertyTypeOperation(propertyType.getCode()), + setPropertyAssignmentOperation(type.getCode()) + ]) +} + +function createPropertyTypeOperation({ + code: propertyTypeCode, + dataType: propertyDataType, + vocabulary: propertyTypeVocabulary, + label: propertyTypeLabel +}) { + const creation = new openbis.PropertyTypeCreation() + creation.setCode(propertyTypeCode) + creation.setDataType(propertyDataType) + if (propertyTypeVocabulary) { + creation.setVocabularyId( + new openbis.VocabularyPermId(propertyTypeVocabulary) ) - facade.executeOperations.mockReturnValue(Promise.resolve({})) - - await controller.load() - - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0' - }) - controller.handleRemove() - - await controller.handleSave() - - expectExecuteOperations([ - deletePropertyAssignmentOperation( - type.getCode(), - propertyType.getCode(), - false - ), - deletePropertyTypeOperation(propertyType.getCode()), - setPropertyAssignmentOperation(type.getCode()) - ]) } - - function createPropertyTypeOperation({ - code: propertyTypeCode, - dataType: propertyDataType, - vocabulary: propertyTypeVocabulary, - label: propertyTypeLabel - }) { - const creation = new openbis.PropertyTypeCreation() - creation.setCode(propertyTypeCode) - creation.setDataType(propertyDataType) - if (propertyTypeVocabulary) { - creation.setVocabularyId( - new openbis.VocabularyPermId(propertyTypeVocabulary) - ) - } - creation.setLabel(propertyTypeLabel) - return new openbis.CreatePropertyTypesOperation([creation]) + creation.setLabel(propertyTypeLabel) + return new openbis.CreatePropertyTypesOperation([creation]) +} + +function updatePropertyTypeOperation(propertyTypeCode, propertyTypeLabel) { + const update = new openbis.PropertyTypeUpdate() + update.setTypeId(new openbis.PropertyTypePermId(propertyTypeCode)) + update.setLabel(propertyTypeLabel) + return new openbis.UpdatePropertyTypesOperation([update]) +} + +function deletePropertyTypeOperation(propertyTypeCode) { + const id = new openbis.PropertyTypePermId(propertyTypeCode) + const options = new openbis.PropertyTypeDeletionOptions() + options.setReason('deleted via ng_ui') + return new openbis.DeletePropertyTypesOperation([id], options) +} + +function setPropertyAssignmentOperation( + typeCode, + propertyCode, + propertyMandatory +) { + const assignments = [] + if (propertyCode) { + let assignment = new openbis.PropertyAssignmentCreation() + assignment.setPropertyTypeId(new openbis.PropertyTypePermId(propertyCode)) + assignment.setMandatory(propertyMandatory) + assignments.push(assignment) } - function updatePropertyTypeOperation(propertyTypeCode, propertyTypeLabel) { - const update = new openbis.PropertyTypeUpdate() - update.setTypeId(new openbis.PropertyTypePermId(propertyTypeCode)) - update.setLabel(propertyTypeLabel) - return new openbis.UpdatePropertyTypesOperation([update]) - } - - function deletePropertyTypeOperation(propertyTypeCode) { - const id = new openbis.PropertyTypePermId(propertyTypeCode) - const options = new openbis.PropertyTypeDeletionOptions() - options.setReason('deleted via ng_ui') - return new openbis.DeletePropertyTypesOperation([id], options) - } + const update = new openbis.SampleTypeUpdate() + update.setTypeId( + new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE) + ) + update.getPropertyAssignments().set(assignments) + + return new openbis.UpdateSampleTypesOperation([update]) +} + +function deletePropertyAssignmentOperation(typeCode, propertyCode, force) { + const assignmentId = new openbis.PropertyAssignmentPermId( + new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE), + new openbis.PropertyTypePermId(propertyCode) + ) + + const update = new openbis.SampleTypeUpdate() + update.setTypeId( + new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE) + ) + update.getPropertyAssignments().remove([assignmentId]) + update.getPropertyAssignments().setForceRemovingAssignments(force) + + return new openbis.UpdateSampleTypesOperation([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]) + }) +} - function setPropertyAssignmentOperation( - typeCode, - propertyCode, - propertyMandatory - ) { - const assignments = [] - if (propertyCode) { - let assignment = new openbis.PropertyAssignmentCreation() - assignment.setPropertyTypeId(new openbis.PropertyTypePermId(propertyCode)) - assignment.setMandatory(propertyMandatory) - assignments.push(assignment) - } - - const update = new openbis.SampleTypeUpdate() - update.setTypeId( - new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE) - ) - update.getPropertyAssignments().set(assignments) +const LOCAL_PROPERTY_TYPE = new openbis.PropertyType() +LOCAL_PROPERTY_TYPE.setCode('TEST_TYPE.TEST_PROPERTY_TYPE') +LOCAL_PROPERTY_TYPE.setLabel('TEST_LABEL') +LOCAL_PROPERTY_TYPE.setDescription('TEST_DESCRIPTION') +LOCAL_PROPERTY_TYPE.setDataType(openbis.DataType.INTEGER) - return new openbis.UpdateSampleTypesOperation([update]) - } +const LOCAL_PROPERTY_ASSIGNMENT = new openbis.PropertyAssignment() +LOCAL_PROPERTY_ASSIGNMENT.setPropertyType(LOCAL_PROPERTY_TYPE) - function deletePropertyAssignmentOperation(typeCode, propertyCode, force) { - const assignmentId = new openbis.PropertyAssignmentPermId( - new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE), - new openbis.PropertyTypePermId(propertyCode) - ) +const SAMPLE_TYPE_WITH_LOCAL_PROPERTY = new openbis.SampleType() +SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setCode('TEST_TYPE') +SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setGeneratedCodePrefix('TEST_PREFIX') +SAMPLE_TYPE_WITH_LOCAL_PROPERTY.setPropertyAssignments([ + LOCAL_PROPERTY_ASSIGNMENT +]) - const update = new openbis.SampleTypeUpdate() - update.setTypeId( - new openbis.EntityTypePermId(typeCode, openbis.EntityKind.SAMPLE) - ) - update.getPropertyAssignments().remove([assignmentId]) - update.getPropertyAssignments().setForceRemovingAssignments(force) +const GLOBAL_PROPERTY_TYPE = new openbis.PropertyType() +GLOBAL_PROPERTY_TYPE.setCode('TEST_PROPERTY_TYPE') +GLOBAL_PROPERTY_TYPE.setLabel('TEST_LABEL') +GLOBAL_PROPERTY_TYPE.setDescription('TEST_DESCRIPTION') +GLOBAL_PROPERTY_TYPE.setDataType(openbis.DataType.INTEGER) - return new openbis.UpdateSampleTypesOperation([update]) - } +const GLOBAL_PROPERTY_ASSIGNMENT = new openbis.PropertyAssignment() +GLOBAL_PROPERTY_ASSIGNMENT.setPropertyType(GLOBAL_PROPERTY_TYPE) - function expectExecuteOperations(expectedOperations) { - expect(facade.executeOperations).toHaveBeenCalledTimes(1) - const actualOperations = facade.executeOperations.mock.calls[0][0] - expect(actualOperations.length).toEqual(expectedOperations.length) - actualOperations.forEach((actualOperation, index) => { - expect(actualOperation).toMatchObject(expectedOperations[index]) - }) - } -}) +const SAMPLE_TYPE_WITH_GLOBAL_PROPERTY = new openbis.SampleType() +SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setCode('TEST_TYPE') +SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setGeneratedCodePrefix('TEST_PREFIX') +SAMPLE_TYPE_WITH_GLOBAL_PROPERTY.setPropertyAssignments([ + GLOBAL_PROPERTY_ASSIGNMENT +]) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSelectionChange.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSelectionChange.test.js index 54f3c0ee0f3..a9064239bb7 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSelectionChange.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerSelectionChange.test.js @@ -1,97 +1,88 @@ -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' -import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' import objectTypes from '@src/js/common/consts/objectType.js' import fixture from '@srcTest/js/common/fixture.js' -jest.mock('@src/js/components/types/form/TypeFormFacade') - -let context = null -let facade = null -let controller = null +let common = null beforeEach(() => { - jest.resetAllMocks() - context = new ComponentContext() - context.setProps({ - object: { - id: 'TEST_OBJECT_ID', - type: objectTypes.OBJECT_TYPE - } + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE }) - facade = new TypeFormFacade() - controller = new TypeFormControler(facade) - controller.init(context) }) afterEach(() => { - expect(facade.loadType).toHaveBeenCalledWith(context.getProps().object) - expect(facade.loadUsages).toHaveBeenCalledWith(context.getProps().object) + common.afterEach() }) -describe('TypeFormController.handleSelectionChange', () => { - test('section', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) - - await controller.load() - - expect(context.getState()).toMatchObject({ - selection: null - }) - - controller.handleSelectionChange(TypeFormSelectionType.SECTION, { - id: 'section-0' - }) - - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.SECTION, - params: { - id: 'section-0' - } +describe(TypeFormControllerTest.SUITE, () => { + test('select a section', testSelectSection) + test('select a property', testSelectProperty) +}) + +async function testSelectSection() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + + expect(common.context.getState()).toMatchObject({ + selection: null + }) + + common.controller.handleSelectionChange(TypeFormSelectionType.SECTION, { + id: 'section-0' + }) + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.SECTION, + params: { + id: 'section-0' } - }) + } + }) - controller.handleSelectionChange() + common.controller.handleSelectionChange() - expect(context.getState()).toMatchObject({ - selection: null - }) + expect(common.context.getState()).toMatchObject({ + selection: null }) +} - test('property', async () => { - facade.loadType.mockReturnValue( - Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) - ) - facade.loadUsages.mockReturnValue(Promise.resolve({})) +async function testSelectProperty() { + common.facade.loadType.mockReturnValue( + Promise.resolve(fixture.TEST_SAMPLE_TYPE_DTO) + ) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) - await controller.load() + await common.controller.load() - expect(context.getState()).toMatchObject({ - selection: null - }) + expect(common.context.getState()).toMatchObject({ + selection: null + }) - controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { - id: 'property-0' - }) + common.controller.handleSelectionChange(TypeFormSelectionType.PROPERTY, { + id: 'property-0' + }) - expect(context.getState()).toMatchObject({ - selection: { - type: TypeFormSelectionType.PROPERTY, - params: { - id: 'property-0' - } + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-0' } - }) + } + }) - controller.handleSelectionChange() + common.controller.handleSelectionChange() - expect(context.getState()).toMatchObject({ - selection: null - }) + expect(common.context.getState()).toMatchObject({ + selection: null }) -}) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerTest.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerTest.js new file mode 100644 index 00000000000..d2feec9a538 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerTest.js @@ -0,0 +1,32 @@ +import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' +import TypeFormControler from '@src/js/components/types/form/TypeFormController.js' +import TypeFormFacade from '@src/js/components/types/form/TypeFormFacade' + +jest.mock('@src/js/components/types/form/TypeFormFacade') + +export default class TypeFormControllerTest { + static SUITE = 'TypeFormController' + + beforeEach() { + jest.resetAllMocks() + } + + init(object) { + this.context = new ComponentContext() + this.context.setProps({ + object + }) + this.facade = new TypeFormFacade() + this.controller = new TypeFormControler(this.facade) + this.controller.init(this.context) + } + + afterEach() { + expect(this.facade.loadType).toHaveBeenCalledWith( + this.context.getProps().object + ) + expect(this.facade.loadUsages).toHaveBeenCalledWith( + this.context.getProps().object + ) + } +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerValidate.test.js b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerValidate.test.js new file mode 100644 index 00000000000..11f6f386751 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/types/form/TypeFormControllerValidate.test.js @@ -0,0 +1,86 @@ +import TypeFormControllerTest from '@srcTest/js/components/types/form/TypeFormControllerTest.js' +import TypeFormSelectionType from '@src/js/components/types/form/TypeFormSelectionType.js' +import objectTypes from '@src/js/common/consts/objectType.js' +import openbis from '@srcTest/js/services/openbis.js' + +let common = null + +beforeEach(() => { + common = new TypeFormControllerTest() + common.beforeEach() + common.init({ + id: 'TEST_OBJECT_ID', + type: objectTypes.OBJECT_TYPE + }) +}) + +afterEach(() => { + common.afterEach() +}) + +describe(TypeFormControllerTest.SUITE, () => { + test('validate', testValidate) +}) + +async function testValidate() { + const SAMPLE_TYPE = new openbis.SampleType() + + common.facade.loadType.mockReturnValue(Promise.resolve(SAMPLE_TYPE)) + common.facade.loadUsages.mockReturnValue(Promise.resolve({})) + + await common.controller.load() + common.controller.handleAddSection() + common.controller.handleAddProperty() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.PROPERTY, + params: { + id: 'property-0' + } + }, + type: { + errors: 0 + }, + properties: [ + { + id: 'property-0', + code: { value: null }, + dataType: { value: null }, + label: { value: null }, + description: { value: null }, + errors: 0 + } + ] + }) + + await common.controller.handleSave() + + expect(common.context.getState()).toMatchObject({ + selection: { + type: TypeFormSelectionType.TYPE, + params: { + part: 'code' + } + }, + type: { + code: { + error: 'Code cannot be empty' + }, + generatedCodePrefix: { + error: 'Generated code prefix cannot be empty' + }, + errors: 2 + }, + properties: [ + { + id: 'property-0', + code: { value: null, error: 'Code cannot be empty' }, + dataType: { value: null, error: 'Data Type cannot be empty' }, + label: { value: null, error: 'Label cannot be empty' }, + description: { value: null, error: 'Description cannot be empty' }, + errors: 4 + } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentAddTerm.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentAddTerm.test.js index 3724edd6f8e..7f663672d57 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentAddTerm.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentAddTerm.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentAddTerm', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('add term', testAddTerm) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeTerm.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeTerm.test.js index a09437f00d0..7f2d0bac3aa 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeTerm.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeTerm.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentChangeTerm', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('change term', testChangeTerm) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeVocabulary.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeVocabulary.test.js index b8254682d37..be88fcd6ef2 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeVocabulary.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentChangeVocabulary.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentChangeVocabulary', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('change vocabulary', testChangeVocabulary) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentFilter.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentFilter.test.js index 8cf9e9b59df..271d434b0d5 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentFilter.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentFilter.test.js @@ -7,7 +7,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentFilter', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('filter', testFilter) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentInternal.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentInternal.test.js index c842de37699..682b7c5f0e7 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentInternal.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentInternal.test.js @@ -10,7 +10,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentInternal', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('internal', testInternal) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentLoad.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentLoad.test.js index bda26882f98..e83b3957ac7 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentLoad.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentLoad.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentLoad', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('load new', testLoadNew) test('load existing', testLoadExisting) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentPage.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentPage.test.js index 9eb61ed4ffa..6d02ecead0a 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentPage.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentPage.test.js @@ -7,7 +7,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentPage', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('page', testPage) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentRemoveTerm.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentRemoveTerm.test.js index e78d1bc0f52..20bed8d71e6 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentRemoveTerm.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentRemoveTerm.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentRemoveTerm', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('remove term', testRemoveTerm) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSelectTerm.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSelectTerm.test.js index 45bdf31bd80..148d4b4c3cc 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSelectTerm.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSelectTerm.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentSelectTerm', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('select term', testSelectTerm) test('follow selected term', testFollowSelectedTerm) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSort.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSort.test.js index cfd128177d5..43c178d60f6 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSort.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentSort.test.js @@ -7,7 +7,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentSort', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('sort', testSort) }) diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentTest.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentTest.js index 774cc479607..0f97784748b 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentTest.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentTest.js @@ -9,6 +9,8 @@ import objectTypes from '@src/js/common/consts/objectType.js' jest.mock('@src/js/components/types/form/VocabularyFormFacade') export default class VocabularyFormComponentTest extends ComponentTest { + static SUITE = 'VocabularyFormComponent' + constructor() { super( object => <VocabularyForm object={object} controller={this.controller} />, diff --git a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentValidate.test.js b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentValidate.test.js index e7c263dec94..845255df284 100644 --- a/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentValidate.test.js +++ b/openbis_ng_ui/srcTest/js/components/types/form/VocabularyFormComponentValidate.test.js @@ -8,7 +8,7 @@ beforeEach(() => { common.beforeEach() }) -describe('VocabularyFormComponentValidate', () => { +describe(VocabularyFormComponentTest.SUITE, () => { test('validate term', testValidateTerm) test('validate vocabulary', testValidateVocabulary) }) diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponent.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponent.test.js deleted file mode 100644 index 107efc4836e..00000000000 --- a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponent.test.js +++ /dev/null @@ -1,144 +0,0 @@ -import React from 'react' -import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' -import BrowserWrapper from '@srcTest/js/components/common/browser/wrapper/BrowserWrapper.js' -import UserBrowser from '@src/js/components/users/browser/UserBrowser.jsx' -import openbis from '@srcTest/js/services/openbis.js' -import fixture from '@srcTest/js/common/fixture.js' - -let common = null - -beforeEach(() => { - common = new ComponentTest( - () => <UserBrowser />, - wrapper => new BrowserWrapper(wrapper) - ) - common.beforeEach() - - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([ - fixture.TEST_USER_GROUP_DTO, - fixture.ANOTHER_USER_GROUP_DTO, - fixture.ALL_USERS_GROUP_DTO - ]) -}) - -describe('browser', () => { - test('load', testLoad) - test('open/close', testOpenClose) - test('filter', testFilter) -}) - -async function testLoad() { - const browser = await common.mount() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 0, text: 'Groups' } - ] - }) -} - -async function testOpenClose() { - const browser = await common.mount() - - browser.getNodes()[0].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, - { level: 1, text: fixture.TEST_USER_DTO.userId }, - { level: 0, text: 'Groups' } - ] - }) - - browser.getNodes()[3].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, - { level: 1, text: fixture.TEST_USER_DTO.userId }, - { level: 0, text: 'Groups' }, - { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, - { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, - { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } - ] - }) - - browser.getNodes()[0].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 0, text: 'Groups' }, - { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, - { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, - { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } - ] - }) - - browser.getNodes()[1].getIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 0, text: 'Groups' } - ] - }) -} - -async function testFilter() { - const browser = await common.mount() - - browser.getFilter().change(fixture.ANOTHER_USER_GROUP_DTO.code.toUpperCase()) - await browser.update() - - browser.expectJSON({ - filter: { - value: fixture.ANOTHER_USER_GROUP_DTO.code.toUpperCase() - }, - nodes: [ - { level: 0, text: 'Groups' }, - { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code } - ] - }) - - browser.getFilter().getClearIcon().click() - await browser.update() - - browser.expectJSON({ - filter: { - value: null - }, - nodes: [ - { level: 0, text: 'Users' }, - { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, - { level: 1, text: fixture.TEST_USER_DTO.userId }, - { level: 0, text: 'Groups' }, - { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, - { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, - { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } - ] - }) -} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentFilter.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentFilter.test.js new file mode 100644 index 00000000000..04f1956e8d8 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentFilter.test.js @@ -0,0 +1,48 @@ +import UserBrowserComponentTest from '@srcTest/js/components/users/browser/UserBrowserComponentTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserComponentTest() + common.beforeEach() +}) + +describe(UserBrowserComponentTest.SUITE, () => { + test('filter', testFilter) +}) + +async function testFilter() { + const browser = await common.mount() + + browser.getFilter().change(fixture.ANOTHER_USER_GROUP_DTO.code.toUpperCase()) + await browser.update() + + browser.expectJSON({ + filter: { + value: fixture.ANOTHER_USER_GROUP_DTO.code.toUpperCase() + }, + nodes: [ + { level: 0, text: 'Groups' }, + { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code } + ] + }) + + browser.getFilter().getClearIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, + { level: 1, text: fixture.TEST_USER_DTO.userId }, + { level: 0, text: 'Groups' }, + { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, + { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, + { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentLoad.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentLoad.test.js new file mode 100644 index 00000000000..01313c11f6e --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentLoad.test.js @@ -0,0 +1,26 @@ +import UserBrowserComponentTest from '@srcTest/js/components/users/browser/UserBrowserComponentTest.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserComponentTest() + common.beforeEach() +}) + +describe(UserBrowserComponentTest.SUITE, () => { + test('load', testLoad) +}) + +async function testLoad() { + const browser = await common.mount() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 0, text: 'Groups' } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentOpenClose.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentOpenClose.test.js new file mode 100644 index 00000000000..6b1b76af2bc --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentOpenClose.test.js @@ -0,0 +1,79 @@ +import UserBrowserComponentTest from '@srcTest/js/components/users/browser/UserBrowserComponentTest.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserComponentTest() + common.beforeEach() +}) + +describe(UserBrowserComponentTest.SUITE, () => { + test('open/close', testOpenClose) +}) + +async function testOpenClose() { + const browser = await common.mount() + + browser.getNodes()[0].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, + { level: 1, text: fixture.TEST_USER_DTO.userId }, + { level: 0, text: 'Groups' } + ] + }) + + browser.getNodes()[3].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 1, text: fixture.ANOTHER_USER_DTO.userId }, + { level: 1, text: fixture.TEST_USER_DTO.userId }, + { level: 0, text: 'Groups' }, + { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, + { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, + { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } + ] + }) + + browser.getNodes()[0].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 0, text: 'Groups' }, + { level: 1, text: fixture.ALL_USERS_GROUP_DTO.code }, + { level: 1, text: fixture.ANOTHER_USER_GROUP_DTO.code }, + { level: 1, text: fixture.TEST_USER_GROUP_DTO.code } + ] + }) + + browser.getNodes()[1].getIcon().click() + await browser.update() + + browser.expectJSON({ + filter: { + value: null + }, + nodes: [ + { level: 0, text: 'Users' }, + { level: 0, text: 'Groups' } + ] + }) +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentTest.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentTest.js new file mode 100644 index 00000000000..8e023fc037e --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserComponentTest.js @@ -0,0 +1,28 @@ +import React from 'react' +import ComponentTest from '@srcTest/js/components/common/ComponentTest.js' +import BrowserWrapper from '@srcTest/js/components/common/browser/wrapper/BrowserWrapper.js' +import UserBrowser from '@src/js/components/users/browser/UserBrowser.jsx' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +export default class UserBrowserComponentTest extends ComponentTest { + static SUITE = 'UserBrowserComponent' + + constructor() { + super( + () => <UserBrowser />, + wrapper => new BrowserWrapper(wrapper) + ) + } + + async beforeEach() { + super.beforeEach() + + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([ + fixture.TEST_USER_GROUP_DTO, + fixture.ANOTHER_USER_GROUP_DTO, + fixture.ALL_USERS_GROUP_DTO + ]) + } +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserController.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserController.test.js deleted file mode 100644 index b34feb5bcc3..00000000000 --- a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserController.test.js +++ /dev/null @@ -1,305 +0,0 @@ -import UserBrowserController from '@src/js/components/users/browser/UserBrowserController.js' -import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' -import openbis from '@srcTest/js/services/openbis.js' -import pages from '@src/js/common/consts/pages.js' -import objectType from '@src/js/common/consts/objectType.js' -import actions from '@src/js/store/actions/actions.js' -import fixture from '@srcTest/js/common/fixture.js' - -let context = null -let controller = null - -beforeEach(() => { - jest.resetAllMocks() - - context = new ComponentContext() - controller = new UserBrowserController() - controller.init(context) -}) - -describe('browser', () => { - test('load', testLoad) - test('filter', testFilter) - test('select node', testSelectNode) - test('select another node', testSelectAnotherNode) - test('select virtual node', testSelectVirtualNode) - test('expand and collapse node', testExpandAndCollapseNode) -}) - -async function testLoad() { - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([ - fixture.TEST_USER_GROUP_DTO, - fixture.ANOTHER_USER_GROUP_DTO, - fixture.ALL_USERS_GROUP_DTO - ]) - - await controller.load() - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false - }, - { - text: 'Groups', - expanded: false, - selected: false - } - ]) - - context.expectNoActions() -} - -async function testFilter() { - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([ - fixture.TEST_USER_GROUP_DTO, - fixture.ANOTHER_USER_GROUP_DTO, - fixture.ALL_USERS_GROUP_DTO - ]) - - await controller.load() - controller.filterChange('ANOTHER') - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: true, - selected: false, - children: [ - { - text: fixture.ANOTHER_USER_DTO.userId, - expanded: false, - selected: false - } - ] - }, - { - text: 'Groups', - expanded: true, - selected: false, - children: [ - { - text: fixture.ANOTHER_USER_GROUP_DTO.code, - expanded: false, - selected: false - } - ] - } - ]) - - context.expectNoActions() -} - -async function testSelectNode() { - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([ - fixture.TEST_USER_GROUP_DTO, - fixture.ANOTHER_USER_GROUP_DTO, - fixture.ALL_USERS_GROUP_DTO - ]) - - await controller.load() - - controller.nodeSelect('users/' + fixture.TEST_USER_DTO.userId) - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false, - children: [ - { - text: fixture.ANOTHER_USER_DTO.userId, - expanded: false, - selected: false - }, - { - text: fixture.TEST_USER_DTO.userId, - expanded: false, - selected: true - } - ] - }, - { - text: 'Groups', - expanded: false, - selected: false, - children: [ - { - text: fixture.ALL_USERS_GROUP_DTO.code, - expanded: false, - selected: false - }, - { - text: fixture.ANOTHER_USER_GROUP_DTO.code, - expanded: false, - selected: false - }, - { - text: fixture.TEST_USER_GROUP_DTO.code, - expanded: false, - selected: false - } - ] - } - ]) - expectOpenUserAction(fixture.TEST_USER_DTO.userId) - - controller.nodeSelect('groups/' + fixture.ANOTHER_USER_GROUP_DTO.code) - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false, - children: [ - { - text: fixture.ANOTHER_USER_DTO.userId, - expanded: false, - selected: false - }, - { - text: fixture.TEST_USER_DTO.userId, - expanded: false, - selected: false - } - ] - }, - { - text: 'Groups', - expanded: false, - selected: false, - children: [ - { - text: fixture.ALL_USERS_GROUP_DTO.code, - expanded: false, - selected: false - }, - { - text: fixture.ANOTHER_USER_GROUP_DTO.code, - expanded: false, - selected: true - }, - { - text: fixture.TEST_USER_GROUP_DTO.code, - expanded: false, - selected: false - } - ] - } - ]) - expectOpenGroupAction(fixture.ANOTHER_USER_GROUP_DTO.code) -} - -async function testSelectAnotherNode() { - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([]) - - await controller.load() - controller.nodeSelect('users/' + fixture.TEST_USER_DTO.userId) - controller.nodeSelect('users/' + fixture.ANOTHER_USER_DTO.userId) - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false, - children: [ - { - text: fixture.ANOTHER_USER_DTO.userId, - expanded: false, - selected: true - }, - { - text: fixture.TEST_USER_DTO.userId, - expanded: false, - selected: false - } - ] - }, - { - text: 'Groups', - expanded: false, - selected: false, - children: [] - } - ]) - - expectOpenUserAction(fixture.TEST_USER_DTO.userId) - expectOpenUserAction(fixture.ANOTHER_USER_DTO.userId) -} - -async function testSelectVirtualNode() { - openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) - openbis.mockSearchGroups([]) - - await controller.load() - controller.nodeSelect('users') - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: true - }, - { - text: 'Groups', - expanded: false, - selected: false - } - ]) - - context.expectNoActions() -} - -async function testExpandAndCollapseNode() { - openbis.mockSearchPersons([]) - openbis.mockSearchGroups([fixture.TEST_USER_GROUP_DTO]) - - await controller.load() - controller.nodeExpand('groups') - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false - }, - { - text: 'Groups', - expanded: true, - selected: false - } - ]) - - context.expectNoActions() - controller.nodeCollapse('groups') - - expect(controller.getNodes()).toMatchObject([ - { - text: 'Users', - expanded: false, - selected: false - }, - { - text: 'Groups', - expanded: false, - selected: false - } - ]) - - context.expectNoActions() -} - -function expectOpenUserAction(userId) { - context.expectAction(actions.objectOpen(pages.USERS, objectType.USER, userId)) -} - -function expectOpenGroupAction(groupId) { - context.expectAction( - actions.objectOpen(pages.USERS, objectType.USER_GROUP, groupId) - ) -} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerExpandCollapseNode.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerExpandCollapseNode.test.js new file mode 100644 index 00000000000..87068ca8bca --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerExpandCollapseNode.test.js @@ -0,0 +1,53 @@ +import UserBrowserControllerTest from '@srcTest/js/components/users/browser/UserBrowserControllerTest.js' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserControllerTest() + common.beforeEach() +}) + +describe(UserBrowserControllerTest.SUITE, () => { + test('expand and collapse node', testExpandAndCollapseNode) +}) + +async function testExpandAndCollapseNode() { + openbis.mockSearchPersons([]) + openbis.mockSearchGroups([fixture.TEST_USER_GROUP_DTO]) + + await common.controller.load() + common.controller.nodeExpand('groups') + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false + }, + { + text: 'Groups', + expanded: true, + selected: false + } + ]) + + common.context.expectNoActions() + common.controller.nodeCollapse('groups') + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false + }, + { + text: 'Groups', + expanded: false, + selected: false + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerFilter.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerFilter.test.js new file mode 100644 index 00000000000..264a18f1164 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerFilter.test.js @@ -0,0 +1,55 @@ +import UserBrowserControllerTest from '@srcTest/js/components/users/browser/UserBrowserControllerTest.js' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserControllerTest() + common.beforeEach() +}) + +describe(UserBrowserControllerTest.SUITE, () => { + test('filter', testFilter) +}) + +async function testFilter() { + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([ + fixture.TEST_USER_GROUP_DTO, + fixture.ANOTHER_USER_GROUP_DTO, + fixture.ALL_USERS_GROUP_DTO + ]) + + await common.controller.load() + common.controller.filterChange('ANOTHER') + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: true, + selected: false, + children: [ + { + text: fixture.ANOTHER_USER_DTO.userId, + expanded: false, + selected: false + } + ] + }, + { + text: 'Groups', + expanded: true, + selected: false, + children: [ + { + text: fixture.ANOTHER_USER_GROUP_DTO.code, + expanded: false, + selected: false + } + ] + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerLoad.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerLoad.test.js new file mode 100644 index 00000000000..c219f4255f0 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerLoad.test.js @@ -0,0 +1,40 @@ +import UserBrowserControllerTest from '@srcTest/js/components/users/browser/UserBrowserControllerTest.js' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserControllerTest() + common.beforeEach() +}) + +describe(UserBrowserControllerTest.SUITE, () => { + test('load', testLoad) +}) + +async function testLoad() { + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([ + fixture.TEST_USER_GROUP_DTO, + fixture.ANOTHER_USER_GROUP_DTO, + fixture.ALL_USERS_GROUP_DTO + ]) + + await common.controller.load() + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false + }, + { + text: 'Groups', + expanded: false, + selected: false + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerSelectNode.test.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerSelectNode.test.js new file mode 100644 index 00000000000..9d6e88713b3 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerSelectNode.test.js @@ -0,0 +1,178 @@ +import UserBrowserControllerTest from '@srcTest/js/components/users/browser/UserBrowserControllerTest.js' +import openbis from '@srcTest/js/services/openbis.js' +import fixture from '@srcTest/js/common/fixture.js' + +let common = null + +beforeEach(() => { + common = new UserBrowserControllerTest() + common.beforeEach() +}) + +describe(UserBrowserControllerTest.SUITE, () => { + test('select node', testSelectNode) + test('select another node', testSelectAnotherNode) + test('select virtual node', testSelectVirtualNode) +}) + +async function testSelectNode() { + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([ + fixture.TEST_USER_GROUP_DTO, + fixture.ANOTHER_USER_GROUP_DTO, + fixture.ALL_USERS_GROUP_DTO + ]) + + await common.controller.load() + + common.controller.nodeSelect('users/' + fixture.TEST_USER_DTO.userId) + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false, + children: [ + { + text: fixture.ANOTHER_USER_DTO.userId, + expanded: false, + selected: false + }, + { + text: fixture.TEST_USER_DTO.userId, + expanded: false, + selected: true + } + ] + }, + { + text: 'Groups', + expanded: false, + selected: false, + children: [ + { + text: fixture.ALL_USERS_GROUP_DTO.code, + expanded: false, + selected: false + }, + { + text: fixture.ANOTHER_USER_GROUP_DTO.code, + expanded: false, + selected: false + }, + { + text: fixture.TEST_USER_GROUP_DTO.code, + expanded: false, + selected: false + } + ] + } + ]) + common.expectOpenUserAction(fixture.TEST_USER_DTO.userId) + + common.controller.nodeSelect('groups/' + fixture.ANOTHER_USER_GROUP_DTO.code) + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false, + children: [ + { + text: fixture.ANOTHER_USER_DTO.userId, + expanded: false, + selected: false + }, + { + text: fixture.TEST_USER_DTO.userId, + expanded: false, + selected: false + } + ] + }, + { + text: 'Groups', + expanded: false, + selected: false, + children: [ + { + text: fixture.ALL_USERS_GROUP_DTO.code, + expanded: false, + selected: false + }, + { + text: fixture.ANOTHER_USER_GROUP_DTO.code, + expanded: false, + selected: true + }, + { + text: fixture.TEST_USER_GROUP_DTO.code, + expanded: false, + selected: false + } + ] + } + ]) + common.expectOpenGroupAction(fixture.ANOTHER_USER_GROUP_DTO.code) +} + +async function testSelectAnotherNode() { + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([]) + + await common.controller.load() + common.controller.nodeSelect('users/' + fixture.TEST_USER_DTO.userId) + common.controller.nodeSelect('users/' + fixture.ANOTHER_USER_DTO.userId) + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: false, + children: [ + { + text: fixture.ANOTHER_USER_DTO.userId, + expanded: false, + selected: true + }, + { + text: fixture.TEST_USER_DTO.userId, + expanded: false, + selected: false + } + ] + }, + { + text: 'Groups', + expanded: false, + selected: false, + children: [] + } + ]) + + common.expectOpenUserAction(fixture.TEST_USER_DTO.userId) + common.expectOpenUserAction(fixture.ANOTHER_USER_DTO.userId) +} + +async function testSelectVirtualNode() { + openbis.mockSearchPersons([fixture.TEST_USER_DTO, fixture.ANOTHER_USER_DTO]) + openbis.mockSearchGroups([]) + + await common.controller.load() + common.controller.nodeSelect('users') + + expect(common.controller.getNodes()).toMatchObject([ + { + text: 'Users', + expanded: false, + selected: true + }, + { + text: 'Groups', + expanded: false, + selected: false + } + ]) + + common.context.expectNoActions() +} diff --git a/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerTest.js b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerTest.js new file mode 100644 index 00000000000..9bde4e3bd65 --- /dev/null +++ b/openbis_ng_ui/srcTest/js/components/users/browser/UserBrowserControllerTest.js @@ -0,0 +1,29 @@ +import UserBrowserController from '@src/js/components/users/browser/UserBrowserController.js' +import ComponentContext from '@srcTest/js/components/common/ComponentContext.js' +import pages from '@src/js/common/consts/pages.js' +import objectType from '@src/js/common/consts/objectType.js' +import actions from '@src/js/store/actions/actions.js' + +export default class UserBrowserControllerTest { + static SUITE = 'UserBrowserController' + + beforeEach() { + jest.resetAllMocks() + + this.context = new ComponentContext() + this.controller = new UserBrowserController() + this.controller.init(this.context) + } + + expectOpenUserAction(userId) { + this.context.expectAction( + actions.objectOpen(pages.USERS, objectType.USER, userId) + ) + } + + expectOpenGroupAction(groupId) { + this.context.expectAction( + actions.objectOpen(pages.USERS, objectType.USER_GROUP, groupId) + ) + } +} -- GitLab