Skip to content
Snippets Groups Projects

Feature/search chemicals details

Merged Mateusz Bolewski requested to merge feature/search-chemicals-details into development
9 unresolved threads
Files
3
/* eslint-disable no-magic-numbers */
import { drugsFixture } from '@/models/fixtures/drugFixtures';
import { chemicalsFixture } from '@/models/fixtures/chemicalsFixture';
import { StoreType } from '@/redux/store';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { render, screen } from '@testing-library/react';
import { PinItem, PinType } from '../PinsList/PinsList.types';
import { AccordionsDetails } from './AccordionsDetails.component';
const PINS_LIST = drugsFixture.map(drug => ({
const DRUGS_PINS_LIST = drugsFixture.map(drug => ({
id: drug.id,
name: drug.name,
data: drug,
}));
const renderComponent = (initialStoreState: InitialStoreState = {}): { store: StoreType } => {
const CHEMICALS_PINS_LIST = chemicalsFixture.map(chemical => ({
id: chemical.id.id,
name: chemical.name,
data: chemical,
}));
const renderComponent = (
pinsList: PinItem[],
type: PinType,
initialStoreState: InitialStoreState = {},
): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState);
return (
render(
<Wrapper>
<AccordionsDetails pinsList={PINS_LIST} type="drugs" />
<AccordionsDetails pinsList={pinsList} type={type} />
</Wrapper>,
),
{
@@ -31,21 +43,21 @@ const renderComponent = (initialStoreState: InitialStoreState = {}): { store: St
describe('AccordionsDetails - component', () => {
it('should display name of drug', () => {
renderComponent();
renderComponent(DRUGS_PINS_LIST, 'drugs');
const drugName = drugsFixture[0].name;
expect(screen.getByText(drugName, { exact: false })).toBeInTheDocument();
});
it('should display description of drug', () => {
renderComponent();
renderComponent(DRUGS_PINS_LIST, 'drugs');
const drugDescription = drugsFixture[0].description;
expect(screen.getByText(drugDescription, { exact: false })).toBeInTheDocument();
});
it('should display synonyms of drug', () => {
renderComponent();
renderComponent(DRUGS_PINS_LIST, 'drugs');
const firstDrugSynonym = drugsFixture[0].synonyms[0];
const secondDrugSynonym = drugsFixture[0].synonyms[1];
@@ -53,11 +65,20 @@ describe('AccordionsDetails - component', () => {
expect(screen.getByText(firstDrugSynonym, { exact: false })).toBeInTheDocument();
expect(screen.getByText(secondDrugSynonym, { exact: false })).toBeInTheDocument();
});
it('should display additional info about drug', () => {
renderComponent();
it('should display blood brain barrier for drug', () => {
renderComponent(DRUGS_PINS_LIST, 'drugs');
const drugAdditionalInfo = drugsFixture[0].bloodBrainBarrier;
expect(screen.getByText(drugAdditionalInfo, { exact: false })).toBeInTheDocument();
});
it('should display direct evidence publications for chemicals', () => {
renderComponent(CHEMICALS_PINS_LIST, 'chemicals');
const chemicalsAdditionalInfo = chemicalsFixture[0].directEvidence
? chemicalsFixture[0].directEvidence
: '';
expect(screen.getAllByText(chemicalsAdditionalInfo, { exact: false })[0]).toBeInTheDocument();
});
});
Loading