From d1360a85ea0ce2733e840989caa76dccea194b7b Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Fri, 8 Apr 2022 15:06:56 +0200 Subject: [PATCH] Tests. --- src/components/objectinspector.js | 2 +- src/components/propertylist.js | 3 +- src/schema/schemadefinitioninspector.js | 4 +- tests/inspector/ckeditorinspectorui.js | 14 ++++++ tests/inspector/components/objectinspector.js | 48 +++++++++++++++++++ tests/inspector/components/propertylist.js | 41 ++++++++++++++++ tests/inspector/data/reducer.js | 1 + tests/inspector/model/nodeinspector.js | 17 ++++++- 8 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/components/objectinspector.js b/src/components/objectinspector.js index 77e29ce..053ae0b 100644 --- a/src/components/objectinspector.js +++ b/src/components/objectinspector.js @@ -30,7 +30,7 @@ export default class ObjectInspector extends PureComponent { name={list.name} itemDefinitions={list.itemDefinitions} presentation={list.presentation} - onLabelClick={list.onLabelClick} + onPropertyTitleClick={list.onPropertyTitleClick} /> ); } diff --git a/src/components/propertylist.js b/src/components/propertylist.js index d959099..0e37e31 100644 --- a/src/components/propertylist.js +++ b/src/components/propertylist.js @@ -28,9 +28,8 @@ export default class PropertyList extends Component { listUid={this.props.name} canCollapse={hasSubProperties} colorBox={presentation.colorBox} - isClickable={presentation.isClickable} expandCollapsibles={expandCollapsibles} - onClick={this.props.onLabelClick} + onClick={this.props.onPropertyTitleClick} />,
{ + onPropertyTitleClick: name => { this.props.setSchemaCurrentDefinitionName( name ); } }, @@ -54,7 +54,7 @@ class SchemaDefinitionInspector extends Component { name: 'Allowed in', url: definition.urls.allowIn, itemDefinitions: definition.allowIn, - onLabelClick: name => { + onPropertyTitleClick: name => { this.props.setSchemaCurrentDefinitionName( name ); } } diff --git a/tests/inspector/ckeditorinspectorui.js b/tests/inspector/ckeditorinspectorui.js index 5c0c1c4..8251f3c 100644 --- a/tests/inspector/ckeditorinspectorui.js +++ b/tests/inspector/ckeditorinspectorui.js @@ -435,6 +435,20 @@ describe( '', () => { expect( getPanes().find( 'CommandsPane' ) ).to.have.length( 1 ); } ); + + it( 'should have a schema pane', () => { + store.dispatch( { + type: 'testAction', + state: { + ui: { + activeTab: 'Schema' + }, + schema: {} + } + } ); + + expect( getPanes().find( 'SchemaPane' ) ).to.have.length( 1 ); + } ); } ); } ); } ); diff --git a/tests/inspector/components/objectinspector.js b/tests/inspector/components/objectinspector.js index 410af8f..ad89900 100644 --- a/tests/inspector/components/objectinspector.js +++ b/tests/inspector/components/objectinspector.js @@ -70,5 +70,53 @@ describe( '', () => { qux: { value: 'baz' } } ); } ); + + it( 'passes a "onPropertyTitleClick" handler to ', () => { + const onClickMock = sinon.spy(); + + wrapper = mount( ); + + expect( wrapper.find( PropertyList ).props().onPropertyTitleClick ).to.equal( onClickMock ); + } ); + + it( 'passes a "presentation" data to ', () => { + const presentationMock = {}; + + wrapper = mount( ); + + expect( wrapper.find( PropertyList ).props().presentation ).to.equal( presentationMock ); + } ); } ); } ); diff --git a/tests/inspector/components/propertylist.js b/tests/inspector/components/propertylist.js index 0564377..403a667 100644 --- a/tests/inspector/components/propertylist.js +++ b/tests/inspector/components/propertylist.js @@ -122,4 +122,45 @@ describe( '', () => { expect( dd3.find( 'input' ).props().value ).to.have.lengthOf.below( 2100 ); expect( dd3.find( 'input' ).props().value ).to.match( /characters left]$/ ); } ); + + describe( 'property title click handling', () => { + it( 'does nothing if props.onPropertyTitleClick was not specified', () => { + const definitions = { + foo: { + value: 'bar' + } + }; + + wrapper = mount( ); + + const dt = wrapper.children().childAt( 0 ); + const label = dt.find( 'label' ); + + expect( dt ).to.not.have.className( 'ck-inspector-property-list__title_clickable' ); + + expect( () => { + label.simulate( 'click' ); + } ).to.not.throw(); + } ); + + it( 'uses props.onPropertyTitleClick when a property title was clicked and passes property name to the callback', () => { + const onClickSpy = sinon.spy(); + + const definitions = { + foo: { + value: 'bar' + } + }; + + wrapper = mount( ); + + const dt = wrapper.children().childAt( 0 ); + const label = dt.find( 'label' ); + + label.simulate( 'click' ); + sinon.assert.calledOnceWithExactly( onClickSpy, 'foo' ); + + expect( dt ).to.have.className( 'ck-inspector-property-list__title_clickable' ); + } ); + } ); } ); diff --git a/tests/inspector/data/reducer.js b/tests/inspector/data/reducer.js index 8734cd5..93bfaff 100644 --- a/tests/inspector/data/reducer.js +++ b/tests/inspector/data/reducer.js @@ -68,6 +68,7 @@ describe( 'global data store reducer', () => { expect( state ).to.have.property( 'model' ); expect( state ).to.have.property( 'view' ); expect( state ).to.have.property( 'commands' ); + expect( state ).to.have.property( 'schema' ); expect( state ).to.have.property( 'currentEditorGlobals' ); expect( state ).to.have.property( 'ui' ); } ); diff --git a/tests/inspector/model/nodeinspector.js b/tests/inspector/model/nodeinspector.js index 69d6294..e112acd 100644 --- a/tests/inspector/model/nodeinspector.js +++ b/tests/inspector/model/nodeinspector.js @@ -10,6 +10,7 @@ import TestEditor from '../../utils/testeditor'; import { createStore } from 'redux'; import { Provider } from 'react-redux'; +import { reducer } from '../../../src/data/reducer'; import { getEditorModelNodeDefinition } from '../../../src/model/data/utils'; import Button from '../../../src/components/button'; @@ -35,7 +36,12 @@ describe( '', () => { root = editor.model.document.getRoot(); - store = createStore( state => state, { + store = createStore( reducer, { + editors: new Map( [ [ 'test-editor', editor ] ] ), + currentEditorName: 'test-editor', + ui: { + activeTab: 'Model' + }, model: { currentNodeDefinition: getEditorModelNodeDefinition( editor, root.getChild( 0 ) ) } @@ -80,6 +86,15 @@ describe( '', () => { sinon.assert.calledOnce( logSpy ); } ); + it( 'should render the show in schema button in the header', () => { + const showInSchema = wrapper.find( Button ).last(); + + showInSchema.simulate( 'click' ); + + expect( store.getState().ui.activeTab ).to.equal( 'Schema' ); + expect( store.getState().schema.currentSchemaDefinitionName ).to.equal( 'paragraph' ); + } ); + it( 'should render for a ', () => { const store = createStore( state => state, { model: {