From 396064a463b711ff7b39bce409a2449820242e80 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 1 Sep 2022 12:21:56 +0300 Subject: [PATCH] Updated tests --- .../components/ConnectionsGroups.js | 11 +- .../components/LibraryViewRelationships.tsx | 115 ++++++++++++++++++ .../specs/ConnectionsGroups.spec.js | 1 + .../specs/DocumentSidePanel.spec.js | 7 +- .../__snapshots__/libraryActions.spec.js.snap | 4 + .../actions/specs/libraryActions.spec.js | 1 + .../Viewer/components/ViewerComponent.js | 5 +- 7 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 app/react/ConnectionsList/components/LibraryViewRelationships.tsx diff --git a/app/react/ConnectionsList/components/ConnectionsGroups.js b/app/react/ConnectionsList/components/ConnectionsGroups.js index 3d17155993..b267bbd4ed 100644 --- a/app/react/ConnectionsList/components/ConnectionsGroups.js +++ b/app/react/ConnectionsList/components/ConnectionsGroups.js @@ -6,6 +6,7 @@ import { connect } from 'react-redux'; import { t } from 'app/I18N'; import ConnectionsGroup from './ConnectionsGroup'; +import { LibraryViewRelationships } from './LibraryViewRelationships'; class ConnectionsGroupsComponent extends Component { render() { @@ -21,15 +22,7 @@ class ConnectionsGroupsComponent extends Component { if (connectionsGroups.size) { if (this.props.sidePanelTrigger === 'library') { - Results = ( -
-
- {connectionsGroups.map(group => ( -
{group.get('connectionLabel')}
- ))} -
-
- ); + Results = ; } else { Results = (
diff --git a/app/react/ConnectionsList/components/LibraryViewRelationships.tsx b/app/react/ConnectionsList/components/LibraryViewRelationships.tsx new file mode 100644 index 0000000000..c858f5c8d4 --- /dev/null +++ b/app/react/ConnectionsList/components/LibraryViewRelationships.tsx @@ -0,0 +1,115 @@ +import React, { useEffect } from 'react'; +import { connect, ConnectedProps } from 'react-redux'; +import PropTypes from 'prop-types'; +import { Map, List } from 'immutable'; +import { bindActionCreators } from 'redux'; +import { Icon } from 'app/UI'; +import * as actions from '../../Relationships/actions/actions'; +import HubRelationshipMetadata from '../../Relationships/components/HubRelationshipMetadata'; + +function mapStateToProps(state: any) { + const { relationships, library } = state; + return { + parentEntity: library.ui.getIn(['selectedDocuments', 0]), + searchResults: relationships.list.searchResults, + search: relationships.list.sort, + hubs: relationships.hubs, + relationTypes: actions.selectRelationTypes(state), + }; +} + +function mapDispatchToProps(dispatch: any) { + return bindActionCreators( + { + parseResults: actions.parseResults, + }, + dispatch + ); +} + +const connector = connect(mapStateToProps, mapDispatchToProps); + +type ComponentProps = ConnectedProps; + +const createRightRelationshipGroups = (rightRelationships: any, relationTypes: any[]) => ( +
+ {rightRelationships.map((relationship: any, index: number) => ( + <> +
+ + {' '} + {(() => { + const relationshipTemplateId = relationship.get('template'); + const relationType = relationTypes.find(r => r._id === relationshipTemplateId); + if (relationType) { + return relationshipTemplateId ? ( + relationTypes.find(r => r._id === relationshipTemplateId).name + ) : ( + + ); + } + return null; + })()} + +
+ {(() => { + return relationship.get('relationships').map((rel: any, indexI: number) => ( +
+
+
+
+ {rel.getIn(['entityData', 'title'])} +
+
+ +
+
+ )); + })()} + + ))} +
+); + +const createLabelGroups = (hub: any, relationTypes: any[]) => { + const template = hub.getIn(['leftRelationship', 'template']); + return ( +
+ + {template &&
{relationTypes.find(r => r._id === template).name}
} +
+ {createRightRelationshipGroups(hub.get('rightRelationships'), relationTypes)} +
+ ); +}; + +const LibraryViewRelationshipsComp = ({ + hubs, + searchResults, + parentEntity, + parseResults, + relationTypes, +}: ComponentProps) => { + useEffect(() => { + if (parentEntity) { + parseResults(searchResults, parentEntity, false); + } + }, [searchResults, parentEntity]); + return ( +
+ {hubs.map((hub: any) => createLabelGroups(hub, relationTypes))} +
+ ); +}; + +LibraryViewRelationshipsComp.propTypes = { + parentEntity: PropTypes.instanceOf(Map), + hubs: PropTypes.instanceOf(List).isRequired, + searchResults: PropTypes.instanceOf(Map).isRequired, + parseResults: PropTypes.func.isRequired, + relationTypes: PropTypes.instanceOf(Array).isRequired, +}; + +const LibraryViewRelationships = connector(LibraryViewRelationshipsComp); + +export { LibraryViewRelationshipsComp, LibraryViewRelationships }; diff --git a/app/react/ConnectionsList/components/specs/ConnectionsGroups.spec.js b/app/react/ConnectionsList/components/specs/ConnectionsGroups.spec.js index 3469c4ee12..b771b2ab09 100644 --- a/app/react/ConnectionsList/components/specs/ConnectionsGroups.spec.js +++ b/app/react/ConnectionsList/components/specs/ConnectionsGroups.spec.js @@ -21,6 +21,7 @@ describe('ConnectionsGroups', () => { ], }, ]), + sidePanelTrigger: 'entityView', }; }); diff --git a/app/react/Documents/components/specs/DocumentSidePanel.spec.js b/app/react/Documents/components/specs/DocumentSidePanel.spec.js index bbda780244..2b8c604270 100644 --- a/app/react/Documents/components/specs/DocumentSidePanel.spec.js +++ b/app/react/Documents/components/specs/DocumentSidePanel.spec.js @@ -213,7 +213,7 @@ describe('DocumentSidePanel', () => { beforeEach(() => { state = { documentViewer: { targetDoc: Immutable.fromJS({ _id: null }) }, - relationships: { list: { connectionsGroups: 'connectionsGroups' } }, + relationships: { list: { connectionsGroups: ['connectionsGroups'] } }, relationTypes: Immutable.fromJS(['a', 'b']), settings: { collection: Immutable.fromJS({ languages }) }, library: { sidepanel: { metadata: {} } }, @@ -241,12 +241,13 @@ describe('DocumentSidePanel', () => { expect(mapStateToProps(state, ownProps).references).toBe( 'References selector used correctly' ); - expect(mapStateToProps(state, ownProps).excludeConnectionsTab).toBe(false); + expect(mapStateToProps(state, ownProps).excludeConnectionsTab).toBe(true); }); it('should map selected target references from viewer when no ownProps and targetDoc', () => { const ownProps = { storeKey: 'library' }; state.documentViewer.targetDoc = Immutable.fromJS({ _id: 'targetDocId' }); + state.relationships.list.connectionsGroups = []; expect(mapStateToProps(state, ownProps).references).toBe( 'Target references selector used correctly' ); @@ -255,7 +256,7 @@ describe('DocumentSidePanel', () => { it('should map connectionsGroups', () => { const ownProps = { storeKey: 'library' }; - expect(mapStateToProps(state, ownProps).connectionsGroups).toBe('connectionsGroups'); + expect(mapStateToProps(state, ownProps).connectionsGroups).toEqual(['connectionsGroups']); }); it('should map default language', () => { diff --git a/app/react/Library/actions/specs/__snapshots__/libraryActions.spec.js.snap b/app/react/Library/actions/specs/__snapshots__/libraryActions.spec.js.snap index c7e44fc732..fe0cae06db 100644 --- a/app/react/Library/actions/specs/__snapshots__/libraryActions.spec.js.snap +++ b/app/react/Library/actions/specs/__snapshots__/libraryActions.spec.js.snap @@ -6,6 +6,10 @@ Array [ "type": "library.sidepanel.tab/SET", "value": "", }, + Object { + "type": "library.sidepanel.trigger/SET", + "value": "library", + }, Object { "doc": Object { "sharedId": "doc", diff --git a/app/react/Library/actions/specs/libraryActions.spec.js b/app/react/Library/actions/specs/libraryActions.spec.js index c5139c9299..935975334a 100644 --- a/app/react/Library/actions/specs/libraryActions.spec.js +++ b/app/react/Library/actions/specs/libraryActions.spec.js @@ -463,6 +463,7 @@ describe('libraryActions', () => { const expectedActions = [ { type: 'library.sidepanel.references/SET', value: 'referencesResponse' }, + { type: 'relationships/list/sharedId/SET', value: 'id' }, ]; const store = mockStore({ locale: 'es' }); diff --git a/app/react/Viewer/components/ViewerComponent.js b/app/react/Viewer/components/ViewerComponent.js index 77371d4201..9aeab6e923 100644 --- a/app/react/Viewer/components/ViewerComponent.js +++ b/app/react/Viewer/components/ViewerComponent.js @@ -12,7 +12,7 @@ import PDFView from '../PDFView'; export class ViewerComponent extends Component { constructor(props, context) { super(props, context); - props.setSidepanelTrigger('entityViewer'); + props.setSidepanelTrigger(); } render() { @@ -31,8 +31,7 @@ ViewerComponent.propTypes = { setSidepanelTrigger: PropTypes.func.isRequired, }; -const setSidepanelTrigger = name => dispatch => - dispatch(actions.set('library.sidepanel.trigger', name)); +const setSidepanelTrigger = () => actions.set('library.sidepanel.trigger', 'entityViewer'); const mapStateToProps = state => { const entity = state.documentViewer.doc.get('_id')