Skip to content
Snippets Groups Projects
Commit b656c7b0 authored by mateusz-winiarczyk's avatar mateusz-winiarczyk
Browse files

fix(reaction): clicking on reaction connected components (MIN-277)

parent 9041ce8b
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!164fix(reaction): clicking on reaction connected components (MIN-277)
/* eslint-disable no-magic-numbers */
import { getReduxWrapperWithStore } from '@/utils/testing/getReduxWrapperWithStore';
import { InitialStoreState } from '@/utils/testing/getReduxStoreActionsListener';
import { StoreType } from '@/redux/store';
import { render, screen } from '@testing-library/react';
import { bioEntitiesContentFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { BIOENTITY_INITIAL_STATE_MOCK } from '@/redux/bioEntity/bioEntity.mock';
import { ConnectedBioEntitiesList } from './ConnectedBioEntitiesList.component';
const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState);
return (
render(
<Wrapper>
<ConnectedBioEntitiesList />
</Wrapper>,
),
{
store,
}
);
};
describe('ConnectedBioEntitiesList', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('renders loading indicator when bioEntityLoading is pending', () => {
renderComponent({
bioEntity: {
...BIOENTITY_INITIAL_STATE_MOCK,
loading: 'pending',
},
});
const loadingIndicator = screen.getByTestId('loading-indicator');
expect(loadingIndicator).toBeVisible();
});
it('renders list of bio entities when bioEntityData is available', () => {
const bioEntityData = [bioEntitiesContentFixture[0]];
renderComponent({
bioEntity: {
...BIOENTITY_INITIAL_STATE_MOCK,
data: [
{
searchQueryElement: '',
loading: 'succeeded',
error: { name: '', message: '' },
data: bioEntityData,
},
],
},
});
expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
expect(screen.queryByText(bioEntitiesContentFixture[0].bioEntity.name)).toBeVisible();
});
});
import {
bioEntityDataListSelector,
bioEntityLoadingSelector,
} from '@/redux/bioEntity/bioEntity.selectors';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { LoadingIndicator } from '@/shared/LoadingIndicator';
import { BioEntitiesPinsListItem } from '../../SearchDrawerWrapper/BioEntitiesResultsList/BioEntitiesPinsList/BioEntitiesPinsListItem';
export const ConnectedBioEntitiesList = (): React.ReactNode => {
const bioEntityLoading = useAppSelector(bioEntityLoadingSelector);
const bioEntityData = useAppSelector(bioEntityDataListSelector);
const isPending = bioEntityLoading === 'pending';
if (isPending) {
return <LoadingIndicator />;
}
return (
<div>
{bioEntityData &&
bioEntityData.map(item => (
<BioEntitiesPinsListItem
name={item.bioEntity.name}
pin={item.bioEntity}
key={item.bioEntity.name}
/>
))}
</div>
);
};
export { ConnectedBioEntitiesList } from './ConnectedBioEntitiesList.component';
......@@ -5,6 +5,7 @@ import {
import { DrawerHeading } from '@/shared/DrawerHeading';
import { useSelector } from 'react-redux';
import { ReferenceGroup } from './ReferenceGroup';
import { ConnectedBioEntitiesList } from './ConnectedBioEntitiesList';
export const ReactionDrawer = (): React.ReactNode => {
const reaction = useSelector(currentDrawerReactionSelector);
......@@ -23,7 +24,7 @@ export const ReactionDrawer = (): React.ReactNode => {
</>
}
/>
<div className="flex flex-col gap-6 p-6">
<div className="flex h-[calc(100%-93px)] max-h-[calc(100%-93px)] flex-col gap-6 overflow-y-auto p-6">
<div className="text-sm font-normal">
Type: <b className="font-semibold">{reaction.type}</b>
</div>
......@@ -32,6 +33,7 @@ export const ReactionDrawer = (): React.ReactNode => {
{referencesGrouped.map(group => (
<ReferenceGroup key={group.source} group={group} />
))}
<ConnectedBioEntitiesList />
</div>
</div>
);
......
......@@ -22,6 +22,11 @@ export const bioEntitySelector = createSelector(rootSelector, state => state.bio
export const bioEntityDataSelector = createSelector(bioEntitySelector, bioEntity => bioEntity.data);
export const bioEntityLoadingSelector = createSelector(
bioEntitySelector,
bioEntity => bioEntity.loading,
);
export const bioEntityDataListSelector = createSelector(bioEntityDataSelector, bioEntityData =>
bioEntityData.map(b => b.data || []).flat(),
);
......
......@@ -19,5 +19,6 @@ export const LoadingIndicator = ({
height={height}
width={width}
className="animate-spin"
data-testid="loading-indicator"
/>
);
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