Skip to content
Snippets Groups Projects
Commit fe9b43fe authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '294-validation-of-bioentity-response' into 'development'

Resolve "validation of bioEntity response"

Closes #294

See merge request !248
parents 1310be6a 1fd11fa3
No related branches found
No related tags found
1 merge request!248Resolve "validation of bioEntity response"
Pipeline #95502 passed
Showing
with 64 additions and 20 deletions
......@@ -17,6 +17,7 @@ import { getReduxStoreWithActionsListener } from '@/utils/testing/getReduxStoreA
import { InitialStoreState } from '@/utils/testing/getReduxWrapperWithStore';
import { act, render, screen } from '@testing-library/react';
import { MockStoreEnhanced } from 'redux-mock-store';
import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
import { BioEntityDrawer } from './BioEntityDrawer.component';
const renderComponent = (
......@@ -91,7 +92,9 @@ describe('BioEntityDrawer - component', () => {
},
});
expect(screen.getByText(bioEntity.stringType, { exact: false })).toBeInTheDocument();
const bioEntityType = getTypeBySBOTerm(bioEntity.sboTerm);
expect(screen.getByText(bioEntityType, { exact: false })).toBeInTheDocument();
expect(screen.getByText(bioEntity.name, { exact: false })).toBeInTheDocument();
});
......
......@@ -13,6 +13,7 @@ import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { DrawerHeading } from '@/shared/DrawerHeading';
import { ElementSearchResultType } from '@/types/models';
import { CommentItem } from '@/components/Map/Drawer/BioEntityDrawer/Comments/CommentItem.component';
import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
import { CollapsibleSection } from '../ExportDrawer/CollapsibleSection';
import { AnnotationItem } from './AnnotationItem';
import { AssociatedSubmap } from './AssociatedSubmap';
......@@ -43,12 +44,14 @@ export const BioEntityDrawer = (): React.ReactNode => {
const isReferenceAvailable = bioEntityData.references.length > ZERO;
const isCommentAvailable = commentsData.length > ZERO;
const type = getTypeBySBOTerm(bioEntityData.sboTerm);
return (
<div className="h-calc-drawer" data-testid="bioentity-drawer">
<DrawerHeading
title={
<>
<span className="font-normal">{bioEntityData.stringType}:</span>&nbsp;
<span className="font-normal">{type}:</span>&nbsp;
{bioEntityData.name}
</>
}
......
......@@ -13,6 +13,7 @@ import {
import { render, screen } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import { MockStoreEnhanced } from 'redux-mock-store';
import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
import { BioEntitiesPinsListItem } from './BioEntitiesPinsListItem.component';
import { PinListBioEntity } from './BioEntitiesPinsListItem.types';
......@@ -97,9 +98,9 @@ describe('BioEntitiesPinsListItem - component ', () => {
it('should display string type of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY, INITIAL_STORE_WITH_ENTITY_NUMBER);
const bioEntityStringType = BIO_ENTITY.stringType;
const bioEntityType = getTypeBySBOTerm(BIO_ENTITY.sboTerm);
expect(screen.getByText(bioEntityStringType, { exact: false })).toBeInTheDocument();
expect(screen.getByText(bioEntityType, { exact: false })).toBeInTheDocument();
});
it('should display synonyms of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY, INITIAL_STORE_WITH_ENTITY_NUMBER);
......
......@@ -16,6 +16,7 @@ import { setMapPosition } from '@/redux/map/map.slice';
import { resetReactionsData } from '@/redux/reactions/reactions.slice';
import { getSearchData } from '@/redux/search/search.thunks';
import { twMerge } from 'tailwind-merge';
import { getTypeBySBOTerm } from '@/utils/bioEntity/getTypeBySBOTerm';
import { PinListBioEntity } from './BioEntitiesPinsListItem.types';
import { isPinWithCoordinates } from './BioEntitiesPinsListItem.utils';
......@@ -59,6 +60,8 @@ export const BioEntitiesPinsListItem = ({
dispatch(openSearchDrawerWithSelectedTab(getDefaultSearchTab(searchValues)));
};
const type = getTypeBySBOTerm(pin.sboTerm);
return (
<div className="mb-4 flex w-full flex-col gap-3 rounded-lg border-[1px] border-solid border-greyscale-500 p-4">
<div className="flex w-full flex-row items-center gap-2">
......@@ -71,7 +74,7 @@ export const BioEntitiesPinsListItem = ({
<img src={pinIconCanvas.toDataURL()} alt="pin icon" />
</button>
<p>
{pin.stringType ? `${pin.stringType}: ` : ''}
{type ? `${type}: ` : ''}
<span
className="w-full cursor-pointer font-bold underline"
onClick={handleSearchMapForPin}
......
......@@ -2,11 +2,11 @@ import { BioEntity } from '@/types/models';
export type PinListBioEntity = Pick<BioEntity, 'synonyms' | 'references'> & {
symbol?: BioEntity['symbol'];
stringType?: BioEntity['stringType'];
fullName?: BioEntity['fullName'];
x?: BioEntity['x'];
y?: BioEntity['y'];
elementId?: BioEntity['elementId'];
sboTerm?: BioEntity['sboTerm'];
};
export type PinListBioEntityWithCoords = PinListBioEntity & {
......
......@@ -96,9 +96,9 @@ describe('BioEntitiesAccordion - component', () => {
});
expect(screen.getByText('Content (10)')).toBeInTheDocument();
expect(screen.getByText('Core PD map (3)')).toBeInTheDocument();
expect(screen.getByText('Core PD map (4)')).toBeInTheDocument();
expect(screen.getByText('Histamine signaling (4)')).toBeInTheDocument();
expect(screen.getByText('PRKN substrates (3)')).toBeInTheDocument();
expect(screen.getByText('PRKN substrates (2)')).toBeInTheDocument();
});
it('should fire toggleIsContentTabOpened on accordion item button click', () => {
......
......@@ -144,7 +144,7 @@ describe('PinsListItem - component ', () => {
expect(screen.queryByText('Available in submaps:')).toBeNull();
});
it('should call setMapPosition if coordinates exist in bioentity element', () => {
it('should call setMapPosition if coordinates exist in bioEntity element', () => {
const { store } = renderComponent(
DRUGS_PIN.name,
DRUGS_PIN.pin,
......@@ -159,7 +159,7 @@ describe('PinsListItem - component ', () => {
map: {
data: {
...initialMapDataFixture,
modelId: 5053,
modelId: BIO_ENTITY.model,
},
loading: 'succeeded',
error: { message: '', name: '' },
......@@ -192,7 +192,7 @@ describe('PinsListItem - component ', () => {
map: {
data: {
...initialMapDataFixture,
modelId: 5053,
modelId: BIO_ENTITY.model,
},
loading: 'succeeded',
error: { message: '', name: '' },
......
......@@ -91,15 +91,14 @@ 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">
<li
key={`${participant.id}-${participant.type}-${participant.resource}`}
className="my-2 px-2"
>
<a
href={participant.link}
href={participant.link ? participant.link : undefined}
target="_blank"
className="cursor-pointer text-primary-500 underline"
>
......
......@@ -12,7 +12,6 @@ import { submodelSchema } from './submodelSchema';
export const bioEntitySchema = z.object({
id: z.union([z.number().int().positive(), z.string()]),
stringType: z.string(),
name: z.string(),
elementId: z.string(),
model: z.number(),
......@@ -91,4 +90,5 @@ export const bioEntitySchema = z.object({
processCoordinates: z.optional(z.null()),
line: z.optional(lineSchema),
operators: z.optional(z.array(operatorSchema)),
sboTerm: z.string(),
});
......@@ -46,7 +46,7 @@ export const overlayLeftBioEntitySchema = z.object({
boundaryCondition: z.boolean().optional(),
constant: z.boolean().nullable().optional(),
modificationResidues: z.unknown(),
stringType: z.string(),
substanceUnits: z.boolean().nullable().optional(),
references: z.array(referenceSchema),
sboTerm: z.string(),
});
......@@ -24,11 +24,11 @@ export const overlayLeftReactionSchema = z.object({
kinetics: z.null(),
line: lineSchema,
processCoordinates: z.null(),
stringType: z.string(),
modifiers: z.array(reactionProduct),
reactants: z.array(reactionProduct),
products: z.array(reactionProduct),
elementId: z.string(),
operators: z.array(z.unknown()),
references: z.array(referenceSchema),
sboTerm: z.string(),
});
export const getTypeBySBOTerm = (sbo: string | undefined): string => {
switch (sbo) {
case 'SBO:0000334':
return 'Antisense RNA';
case 'SBO:0000253':
case 'SBO:0000297':
return 'Complex';
case 'SBO:0000289':
return 'Hypothetical Complex';
case 'SBO:0000291':
return 'Degraded';
case 'SBO:0000298':
return 'Drug';
case 'SBO:0000243':
return 'Gene';
case 'SBO:0000252':
case 'SBO:0000421':
case 'SBO:0000284':
case 'SBO:0000244':
return 'Protein';
case 'SBO:0000327':
return 'Ion';
case 'SBO:0000358':
return 'Phenotype';
case 'SBO:0000278':
return 'RNA';
case 'SBO:0000247':
case 'SBO:0000299':
return 'Simple molecule';
case 'SBO:0000285':
return 'Unknown';
default:
return '---';
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment