Skip to content
Snippets Groups Projects
Commit c13a4728 authored by Adrian Orłów's avatar Adrian Orłów
Browse files

test: add tests for reaction drawer utils

parent c292b40d
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...,!65feat: Add reaction drawer (MIN-140)
Pipeline #82126 passed
import {
REFERENCES_MOCK_ALL_INVALID,
REFERENCES_MOCK_ALL_VALID,
} from '@/models/mocks/referencesMock';
import { Reaction } from '@/types/models';
import { ReferenceFiltered } from '../ReactionDrawer.types';
import { getFilteredReferences } from './getFilteredReferences';
describe('getFilteredReferences - subUtil', () => {
const cases: [Pick<Reaction, 'references'>, ReferenceFiltered[]][] = [
[
{
references: REFERENCES_MOCK_ALL_VALID,
},
REFERENCES_MOCK_ALL_VALID as ReferenceFiltered[],
],
[
{
references: REFERENCES_MOCK_ALL_INVALID,
},
[],
],
[
{
references: [...REFERENCES_MOCK_ALL_VALID, ...REFERENCES_MOCK_ALL_INVALID],
},
REFERENCES_MOCK_ALL_VALID as ReferenceFiltered[],
],
];
it.each(cases)('should return valid filtered references', (reaction, result) => {
expect(getFilteredReferences(reaction)).toStrictEqual(result);
});
});
import { Reaction } from '@/types/models'; import { Reaction } from '@/types/models';
import { ReferenceFiltered } from '../ReactionDrawer.types'; import { ReferenceFiltered } from '../ReactionDrawer.types';
export const getFilteredReferences = (reaction: Reaction | undefined): ReferenceFiltered[] => type InputReaction = Pick<Reaction, 'references'>;
export const getFilteredReferences = (reaction: InputReaction | undefined): ReferenceFiltered[] =>
(reaction?.references || []).filter( (reaction?.references || []).filter(
(ref): ref is ReferenceFiltered => ref.link !== null && ref.link !== undefined, (ref): ref is ReferenceFiltered => ref.link !== null && ref.link !== undefined,
); );
import { ReferenceFiltered } from '../ReactionDrawer.types';
import { getGroupedReferences } from './getGroupedReferences';
describe('getGroupedReferences - util', () => {
const singleReference = {
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
article: {
title:
'The nutrient-responsive transcription factor TFE3 promotes autophagy, lysosomal biogenesis, and clearance of cellular debris.',
authors: [
'Martina JA',
' Diab HI',
' Lishu L',
' Jeong-A L',
' Patange S',
' Raben N',
' Puertollano R.',
],
journal: 'Science signaling',
year: 2014,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
pubmedId: '24448649',
citationCount: 321,
},
type: 'PUBMED',
resource: '24448649',
id: 154973,
annotatorClassName: '',
};
const cases = [
[[], []],
[
[singleReference],
[
{
source: '',
references: [singleReference],
},
],
],
[
[
{
...singleReference,
annotatorClassName: 'source1',
},
{
...singleReference,
annotatorClassName: 'source1',
},
{
...singleReference,
annotatorClassName: 'source2',
},
],
[
{
source: 'source1',
references: [
{
...singleReference,
annotatorClassName: 'source1',
},
{
...singleReference,
annotatorClassName: 'source1',
},
],
},
{
source: 'source2',
references: [
{
...singleReference,
annotatorClassName: 'source2',
},
],
},
],
],
];
it.each(cases)('should return correct grouped references', (references, referencesGrouped) =>
expect(getGroupedReferences(references as ReferenceFiltered[])).toMatchObject(
referencesGrouped,
),
);
});
import { FIRST } from '@/constants/common';
import { Reference } from '@/types/models';
export const REFERENCES_MOCK_ALL_VALID: Reference[] = [
{
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
article: {
title:
'The nutrient-responsive transcription factor TFE3 promotes autophagy, lysosomal biogenesis, and clearance of cellular debris.',
authors: [
'Martina JA',
' Diab HI',
' Lishu L',
' Jeong-A L',
' Patange S',
' Raben N',
' Puertollano R.',
],
journal: 'Science signaling',
year: 2014,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
pubmedId: '24448649',
citationCount: 321,
},
type: 'PUBMED',
resource: '24448649',
id: 154973,
annotatorClassName: '',
},
{
link: 'https://www.ncbi.nlm.nih.gov/pubmed/27299292',
article: {
title:
'Transcription factor EB: from master coordinator of lysosomal pathways to candidate therapeutic target in degenerative storage diseases.',
authors: ['Sardiello M.'],
journal: 'Annals of the New York Academy of Sciences',
year: 2016,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/27299292',
pubmedId: '27299292',
citationCount: 66,
},
type: 'PUBMED',
resource: '27299292',
id: 154974,
annotatorClassName: '',
},
{
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
article: {
title:
'The nutrient-responsive transcription factor TFE3 promotes autophagy, lysosomal biogenesis, and clearance of cellular debris.',
authors: [
'Martina JA',
' Diab HI',
' Lishu L',
' Jeong-A L',
' Patange S',
' Raben N',
' Puertollano R.',
],
journal: 'Science signaling',
year: 2014,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
pubmedId: '24448649',
citationCount: 321,
},
type: 'PUBMED',
resource: '24448649',
id: 154973,
annotatorClassName: 'source1',
},
{
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
article: {
title:
'Transcription factor EB: from master coordinator of lysosomal pathways to candidate therapeutic target in degenerative storage diseases.',
authors: ['Sardiello M.'],
journal: 'Annals of the New York Academy of Sciences',
year: 2016,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/27299292',
pubmedId: '27299292',
citationCount: 66,
},
type: 'PUBMED',
resource: '27299292',
id: 154974,
annotatorClassName: 'source2',
},
];
export const REFERENCES_MOCK_ALL_INVALID: Reference[] = [
{
link: null,
article: {
title:
'The nutrient-responsive transcription factor TFE3 promotes autophagy, lysosomal biogenesis, and clearance of cellular debris.',
authors: [
'Martina JA',
' Diab HI',
' Lishu L',
' Jeong-A L',
' Patange S',
' Raben N',
' Puertollano R.',
],
journal: 'Science signaling',
year: 2014,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
pubmedId: '24448649',
citationCount: 321,
},
type: 'PUBMED',
resource: '24448649',
id: 154973,
annotatorClassName: '',
},
{
link: null,
article: {
title:
'Transcription factor EB: from master coordinator of lysosomal pathways to candidate therapeutic target in degenerative storage diseases.',
authors: ['Sardiello M.'],
journal: 'Annals of the New York Academy of Sciences',
year: 2016,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/27299292',
pubmedId: '27299292',
citationCount: 66,
},
type: 'PUBMED',
resource: '27299292',
id: 154974,
annotatorClassName: '',
},
{
link: null,
article: {
title:
'The nutrient-responsive transcription factor TFE3 promotes autophagy, lysosomal biogenesis, and clearance of cellular debris.',
authors: [
'Martina JA',
' Diab HI',
' Lishu L',
' Jeong-A L',
' Patange S',
' Raben N',
' Puertollano R.',
],
journal: 'Science signaling',
year: 2014,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/24448649',
pubmedId: '24448649',
citationCount: 321,
},
type: 'PUBMED',
resource: '24448649',
id: 154973,
annotatorClassName: 'source1',
},
{
link: null,
article: {
title:
'Transcription factor EB: from master coordinator of lysosomal pathways to candidate therapeutic target in degenerative storage diseases.',
authors: ['Sardiello M.'],
journal: 'Annals of the New York Academy of Sciences',
year: 2016,
link: 'https://www.ncbi.nlm.nih.gov/pubmed/27299292',
pubmedId: '27299292',
citationCount: 66,
},
type: 'PUBMED',
resource: '27299292',
id: 154974,
annotatorClassName: 'source2',
},
];
export const SINGLE_VALID_REFERENCE = REFERENCES_MOCK_ALL_VALID[FIRST];
/* eslint-disable @typescript-eslint/no-explicit-any */
import { groupBy } from './groupBy';
interface InputObject {
title: string;
value: number;
}
describe('groupBy - util', () => {
const cases: [InputObject[], (value: InputObject) => string, { [key: string]: InputObject[] }][] =
[
[
[
{
title: 'GROUP_1',
value: 1,
},
{
title: 'GROUP_1',
value: 2,
},
{
title: 'GROUP_1',
value: 3,
},
{
title: 'GROUP_2',
value: 1,
},
{
title: 'GROUP_3',
value: 1,
},
],
(obj): string => obj.title,
{
GROUP_1: [
{ title: 'GROUP_1', value: 1 },
{ title: 'GROUP_1', value: 2 },
{ title: 'GROUP_1', value: 3 },
],
GROUP_2: [{ title: 'GROUP_2', value: 1 }],
GROUP_3: [{ title: 'GROUP_3', value: 1 }],
},
],
[
[
{
title: '1',
value: 1,
},
{
title: '1',
value: 2,
},
{
title: '1',
value: 3,
},
{
title: '2',
value: 1,
},
{
title: '3',
value: 1,
},
],
(obj): string => obj.value.toString(),
{
'1': [
{ title: '1', value: 1 },
{ title: '2', value: 1 },
{ title: '3', value: 1 },
],
'2': [{ title: '1', value: 2 }],
'3': [{ title: '1', value: 3 }],
},
],
];
it.each(cases)('should return valid data basing on predicate', (input, predicate, output) => {
expect(groupBy(input as any[], predicate)).toStrictEqual(output);
});
});
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