Skip to content
Snippets Groups Projects

test(search): added missing tests for search flow

Merged Mateusz Bolewski requested to merge fix/search-bioentites-tests into development
8 unresolved threads
Files
18
/* eslint-disable no-magic-numbers */
import { render, screen } from '@testing-library/react';
import {
InitialStoreState,
getReduxWrapperWithStore,
} from '@/utils/testing/getReduxWrapperWithStore';
import { bioEntitiesContentFixture } from '@/models/fixtures/bioEntityContentsFixture';
import { StoreType } from '@/redux/store';
import { BioEntity } from '@/types/models';
import { BioEntitiesPinsListItem } from './BioEntitiesPinsListItem.component';
const BIO_ENTITY = bioEntitiesContentFixture[2].bioEntity;
const renderComponent = (
name: string,
pin: BioEntity,
initialStoreState: InitialStoreState = {},
): { store: StoreType } => {
const { Wrapper, store } = getReduxWrapperWithStore(initialStoreState);
return (
render(
<Wrapper>
<BioEntitiesPinsListItem name={name} pin={pin} />
</Wrapper>,
),
{
store,
}
);
};
describe('BioEntitiesPinsList - component ', () => {
it('should display name of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY);
const bioEntityName = bioEntitiesContentFixture[2].bioEntity.fullName || '';
expect(screen.getByText(bioEntityName, { exact: false })).toBeInTheDocument();
});
it('should display symbol of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY);
const bioEntitySymbol = BIO_ENTITY.symbol || '';
expect(screen.getByText(bioEntitySymbol, { exact: false })).toBeInTheDocument();
});
it('should display empty string when symbol does not exist', () => {
renderComponent(
bioEntitiesContentFixture[1].bioEntity.name,
bioEntitiesContentFixture[1].bioEntity,
);
expect(screen.getAllByTestId('bio-entity-symbol')[0].textContent).toHaveLength(0);
});
it('should display string type of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY);
const bioEntityStringType = bioEntitiesContentFixture[2].bioEntity.stringType;
expect(screen.getByText(bioEntityStringType, { exact: false })).toBeInTheDocument();
});
it('should display synonyms of bio entity element', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY);
const firstBioEntitySynonym = bioEntitiesContentFixture[2].bioEntity.synonyms[0];
const secondBioEntitySynonym = bioEntitiesContentFixture[2].bioEntity.synonyms[1];
expect(screen.getByText(firstBioEntitySynonym, { exact: false })).toBeInTheDocument();
expect(screen.getByText(secondBioEntitySynonym, { exact: false })).toBeInTheDocument();
});
it('should display list of references for pin', () => {
renderComponent(BIO_ENTITY.name, BIO_ENTITY);
const firstPinReferenceType = bioEntitiesContentFixture[2].bioEntity.references[0].type;
const firstPinReferenceResource = bioEntitiesContentFixture[2].bioEntity.references[0].resource;
const secondPinReferenceType = bioEntitiesContentFixture[2].bioEntity.references[1].type;
const secondPinReferenceResource =
bioEntitiesContentFixture[2].bioEntity.references[1].resource;
expect(screen.getByText(firstPinReferenceType, { exact: false })).toBeInTheDocument();
expect(screen.getByText(firstPinReferenceResource, { exact: false })).toBeInTheDocument();
expect(screen.getByText(secondPinReferenceType, { exact: false })).toBeInTheDocument();
expect(screen.getByText(secondPinReferenceResource, { exact: false })).toBeInTheDocument();
});
});
Loading