diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx index 2c62fa09c0e73a4074af78ff745fb7a745018f1d..691b1568b442a61bc54d910880ece0d7cd5a63cc 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem/BioEntitiesPinsListItem.component.test.tsx @@ -16,7 +16,13 @@ import { MockStoreEnhanced } from 'redux-mock-store'; import { BioEntitiesPinsListItem } from './BioEntitiesPinsListItem.component'; import { PinListBioEntity } from './BioEntitiesPinsListItem.types'; -const BIO_ENTITY = bioEntitiesContentFixture[0].bioEntity; +const BIO_ENTITY = { + ...bioEntitiesContentFixture[0].bioEntity, + fullName: 'fullName_', + name: 'name_', + symbol: 'symbol_', +}; + const INITIAL_STORE_WITH_ENTITY_NUMBER: InitialStoreState = { entityNumber: { data: { diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx index 2eb6f897def7a8412c5189963957f58e0115327b..685bfdbdd59f2948df45081a45e3eb95d35517a5 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/GroupedSearchResults/BioEntitiesAccordion/BioEntitiesAccordion.component.test.tsx @@ -73,8 +73,8 @@ describe('BioEntitiesAccordion - component', () => { }); expect(screen.getByText('Content (10)')).toBeInTheDocument(); - expect(screen.getByText('Core PD map (4)')).toBeInTheDocument(); + expect(screen.getByText('Core PD map (3)')).toBeInTheDocument(); expect(screen.getByText('Histamine signaling (4)')).toBeInTheDocument(); - expect(screen.getByText('PRKN substrates (2)')).toBeInTheDocument(); + expect(screen.getByText('PRKN substrates (3)')).toBeInTheDocument(); }); }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/AccordionsDetails/AccordionsDetails.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/AccordionsDetails/AccordionsDetails.component.test.tsx index 280246c664c61e8c7263fd08edb4f26a8a0887c1..4460c7c02c5866a7c86b753884814838da9cf3ec 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/AccordionsDetails/AccordionsDetails.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/AccordionsDetails/AccordionsDetails.component.test.tsx @@ -1,5 +1,4 @@ /* eslint-disable no-magic-numbers */ -import { chemicalsFixture } from '@/models/fixtures/chemicalsFixture'; import { drugsFixture } from '@/models/fixtures/drugFixtures'; import { StoreType } from '@/redux/store'; import { @@ -16,12 +15,6 @@ const DRUGS_PINS_LIST = drugsFixture.map(drug => ({ data: drug, })); -const CHEMICALS_PINS_LIST = chemicalsFixture.map(chemical => ({ - id: chemical.id.id, - name: chemical.name, - data: chemical, -})); - const renderComponent = ( pinsList: PinItem[], initialStoreState: InitialStoreState = {}, @@ -64,13 +57,4 @@ describe('AccordionsDetails - component', () => { expect(screen.getByText(firstDrugSynonym, { exact: false })).toBeInTheDocument(); expect(screen.getByText(secondDrugSynonym, { exact: false })).toBeInTheDocument(); }); - it('should display direct evidence publications for chemicals', () => { - renderComponent(CHEMICALS_PINS_LIST); - - const chemicalsAdditionalInfo = chemicalsFixture[0].directEvidence - ? chemicalsFixture[0].directEvidence - : ''; - - expect(screen.getAllByText(chemicalsAdditionalInfo, { exact: false })[0]).toBeInTheDocument(); - }); }); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx index c1ed276c8a3efaf6727c2b790cd33080a2e84680..b1d74b817a28845a1f3b4f7f48374e864a5b6517 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.test.tsx @@ -79,8 +79,11 @@ describe('PinsListItem - component ', () => { expect(screen.getByText(firstPinElementType, { exact: false })).toBeInTheDocument(); expect(screen.getByText(firstPinElementResource, { exact: false })).toBeInTheDocument(); - expect(screen.getByText(secondPinElementType, { exact: false })).toBeInTheDocument(); - expect(screen.getByText(secondPinElementResource, { exact: false })).toBeInTheDocument(); + + if (!secondPinElementType) { + expect(screen.queryByText(secondPinElementType, { exact: false })).toBeNull(); + expect(screen.queryByText(secondPinElementResource, { exact: false })).toBeNull(); + } }); it('should display list of references for pin', () => { renderComponent(DRUGS_PIN.name, DRUGS_PIN.pin, 'drugs', BIO_ENTITY, INITIAL_STORE_STATE); diff --git a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx index 254d0bc3197d2042db7280d7519517a8e0a70cc3..d51600d35d0412cb6bd2d794b7349bd54054deaf 100644 --- a/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx +++ b/src/components/Map/Drawer/SearchDrawerWrapper/ResultsList/PinsList/PinsListItem/PinsListItem.component.tsx @@ -91,6 +91,10 @@ export const PinsListItem = ({ <div className="font-bold">Elements:</div> {'targetParticipants' in pin && pin.targetParticipants.map(participant => { + if (!participant?.link) { + return null; + } + return ( // participant.id is almost always = 0 <li key={`${participant.id}-${participant.link}`} className="my-2 px-2"> diff --git a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts index 9cc723f41ad1365d5bca71da14326ac754651296..ea28c2543c3ca8e368b66490cf2b872f4e656d64 100644 --- a/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts +++ b/src/components/Map/MapViewer/utils/config/pinsLayer/getBioEntititesFeatures.test.ts @@ -27,15 +27,15 @@ describe('getBioEntitiesFeatures - subUtil', () => { map: initialMapStateFixture, }); const bioEntititesContent = bioEntitiesContentFixture; - const bioEntities = bioEntititesContent.map(({ bioEntity }) => bioEntity); + const bioEntities = bioEntititesContent.map(({ bioEntity }) => ({ + ...bioEntity, + type: 'bioEntity' as PinType, + })); const pointToProjection = getPointToProjection(Wrapper); - const pinTypes: PinType[] = ['bioEntity', 'drugs', 'chemicals']; - - it.each(pinTypes)('should return array of instances of Feature with Style type=%s', type => { + it('should return array of instances of Feature with Style type=%s', () => { const result = getBioEntitiesFeatures(bioEntities, { pointToProjection, - type, entityNumber: {}, activeIds: [bioEntities[FIRST_ARRAY_ELEMENT].id], }); diff --git a/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinSingleFeature.test.ts b/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinSingleFeature.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..10906ccf7ab8f950ad4ab1d773210424b1fec595 --- /dev/null +++ b/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinSingleFeature.test.ts @@ -0,0 +1,87 @@ +import { FIRST_ARRAY_ELEMENT } from '@/constants/common'; +import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixture'; +import { EntityNumber } from '@/redux/entityNumber/entityNumber.types'; +import { initialMapStateFixture } from '@/redux/map/map.fixtures'; +import { MultiPinBioEntity } from '@/types/bioEntity'; +import { PinType } from '@/types/pin'; +import { UsePointToProjectionResult, usePointToProjection } from '@/utils/map/usePointToProjection'; +import { + GetReduxWrapperUsingSliceReducer, + getReduxWrapperWithStore, +} from '@/utils/testing/getReduxWrapperWithStore'; +import { renderHook } from '@testing-library/react'; +import { Feature } from 'ol'; +import Style from 'ol/style/Style'; +import { getMultipinSingleFeature } from './getMultipinSingleFeature'; +import * as getMultipinStyle from './getMultipinStyle'; + +jest.mock('./getMultipinStyle', () => ({ + __esModule: true, + ...jest.requireActual('./getMultipinStyle'), +})); + +const ONE_MULTI_BIO_ENTITIES: MultiPinBioEntity = [ + { + ...bioEntityContentFixture.bioEntity, + type: 'bioEntity' as PinType, + x: 100, + y: 100, + }, + { + ...bioEntityContentFixture.bioEntity, + type: 'drugs' as PinType, + x: 100, + y: 100, + }, +]; + +const ENTITY_NUMBER: EntityNumber = { + [ONE_MULTI_BIO_ENTITIES[FIRST_ARRAY_ELEMENT].elementId]: 100, +}; + +const getMultipinStyleSpy = jest.spyOn(getMultipinStyle, 'getMultipinStyle'); + +const getPointToProjection = ( + wrapper: ReturnType<GetReduxWrapperUsingSliceReducer>['Wrapper'], +): UsePointToProjectionResult => { + const { result: usePointToProjectionHook } = renderHook(() => usePointToProjection(), { + wrapper, + }); + + return usePointToProjectionHook.current; +}; + +describe('getMultipinSingleFeature - subUtil', () => { + const { Wrapper } = getReduxWrapperWithStore({ + map: initialMapStateFixture, + }); + const pointToProjection = getPointToProjection(Wrapper); + + it('should return instance of Feature with Style type=%s', () => { + const result = getMultipinSingleFeature(ONE_MULTI_BIO_ENTITIES, { + pointToProjection, + entityNumber: ENTITY_NUMBER, + activeIds: [], + }); + + const style = result.getStyle() as Style; + + expect(result).toBeInstanceOf(Feature); + expect(style).toBeInstanceOf(Style); + }); + + it('should run getPinStyle with valid args for type=%s', () => { + getMultipinSingleFeature(ONE_MULTI_BIO_ENTITIES, { + pointToProjection, + entityNumber: ENTITY_NUMBER, + activeIds: [], + }); + + expect(getMultipinStyleSpy).toHaveBeenCalledWith({ + pins: [ + { color: '#0c4fa180', textColor: '#FFFFFF80', value: 100 }, + { color: '#F48C4180', textColor: '#FFFFFF80', value: undefined }, + ], + }); + }); +}); diff --git a/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinsBioEntities.test.ts b/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinsBioEntities.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c5778deb7d30cbad7c1f14e0d3f1f2c5b6185eb --- /dev/null +++ b/src/components/Map/MapViewer/utils/config/pinsLayer/getMultipinsBioEntities.test.ts @@ -0,0 +1,76 @@ +import { bioEntityContentFixture } from '@/models/fixtures/bioEntityContentsFixture'; +import { MultiPinBioEntity } from '@/types/bioEntity'; +import { PinType } from '@/types/pin'; +import { getMultipinsBioEntities } from './getMultipinsBioEntities'; + +const ZERO_MULTI_BIO_ENTITIES: MultiPinBioEntity = [ + { + ...bioEntityContentFixture.bioEntity, + type: 'bioEntity' as PinType, + }, + { + ...bioEntityContentFixture.bioEntity, + x: 1000, + type: 'bioEntity' as PinType, + }, +]; + +const ONE_MULTI_BIO_ENTITIES: MultiPinBioEntity = [ + { + ...bioEntityContentFixture.bioEntity, + type: 'bioEntity' as PinType, + x: 100, + y: 100, + }, + { + ...bioEntityContentFixture.bioEntity, + type: 'drugs' as PinType, + x: 100, + y: 100, + }, +]; + +const FEW_MULTI_BIO_ENTITIES_WITH_MULTIPLIED_TYPE: MultiPinBioEntity = [ + { + ...bioEntityContentFixture.bioEntity, + type: 'bioEntity' as PinType, + x: 100, + y: 100, + }, + { + ...bioEntityContentFixture.bioEntity, + type: 'drugs' as PinType, + x: 100, + y: 100, + }, + { + ...bioEntityContentFixture.bioEntity, + type: 'drugs' as PinType, + x: 100, + y: 100, + }, + { + ...bioEntityContentFixture.bioEntity, + type: 'drugs' as PinType, + x: 100, + y: 100, + }, +]; + +describe('getMultipinsBioEntities - util', () => { + it('should return empty array if theres no multi pins', () => { + expect(getMultipinsBioEntities({ bioEntities: ZERO_MULTI_BIO_ENTITIES })).toStrictEqual([]); + }); + + it('should return valid multi pins', () => { + expect(getMultipinsBioEntities({ bioEntities: ONE_MULTI_BIO_ENTITIES })).toStrictEqual([ + ONE_MULTI_BIO_ENTITIES, + ]); + }); + + it('should return valid multi pins if theres few types of pins', () => { + expect( + getMultipinsBioEntities({ bioEntities: FEW_MULTI_BIO_ENTITIES_WITH_MULTIPLIED_TYPE }), + ).toStrictEqual([ONE_MULTI_BIO_ENTITIES]); + }); +}); diff --git a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts index e36e92a7b655a1c1b20a77f41effe2707c51fab3..f3136895e438517686533a5925b974a840bc6349 100644 --- a/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts +++ b/src/components/Map/MapViewer/utils/listeners/mapSingleClick/handleAliasResults.test.ts @@ -29,12 +29,16 @@ describe('handleAliasResults - util', () => { beforeEach(() => { jest.clearAllMocks(); - const bioEntityWithIdReaction = bioEntityResponseFixture.content.find(c => - Boolean(c.bioEntity.idReaction), - )?.bioEntity || { id: ZERO }; + const bioEntityWithIdReaction = bioEntityResponseFixture.content + .filter(c => Boolean(c.bioEntity.idReaction)) + ?.map(b => b.bioEntity || { id: ZERO }); mockedAxiosOldClient - .onGet(apiPath.getReactionsWithIds([Number(`${bioEntityWithIdReaction.id}`)])) + .onGet( + apiPath.getReactionsWithIds( + bioEntityWithIdReaction.map(bioEntity => Number(`${bioEntity.id}`)), + ), + ) .reply(HttpStatusCode.Ok, []); }); describe('when matching bioEntity not found', () => { @@ -132,6 +136,7 @@ describe('handleAliasResults - util', () => { y: 700, width: 50, height: 50, + idReaction: undefined, }, }, ], @@ -156,8 +161,6 @@ describe('handleAliasResults - util', () => { 'project/getBioEntityContents/pending', 'project/getBioEntityContents/fulfilled', 'entityNumber/addNumbersToEntityNumberData', - 'reactions/getByIds/pending', - 'reactions/getByIds/fulfilled', 'project/getMultiBioEntity/fulfilled', 'drawer/selectTab', 'drawer/openBioEntityDrawerById',