Skip to content

Commit

Permalink
Closes #431
Browse files Browse the repository at this point in the history
  • Loading branch information
dweemx committed Jul 1, 2021
1 parent 4d1da68 commit 54955aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
28 changes: 24 additions & 4 deletions src/components/Search/Search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ const results = [

describe('Model.findResult', () => {
it('Makes a selection from valid results', () => {
expect(Model.findResult({ title: 'c' }, 'red', results)).toStrictEqual({
expect(
Model.findResult(
{ title: 'c', category: 'regulon' },
'red',
results
)
).toStrictEqual({
title: 'c',
category: 'regulon',
description: '',
Expand All @@ -61,7 +67,15 @@ describe('Model.findResult', () => {

it('Makes a selection from more valid results', () => {
expect(
Model.findResult({ title: 'All Clusters' }, 'green', results)
Model.findResult(
{
title: 'All Clusters',
category:
'Clustering: Leiden resolution 0.4 (default, 397)',
},
'green',
results
)
).toStrictEqual({
title: 'All Clusters',
category: 'Clustering: Leiden resolution 0.4 (default, 397)',
Expand All @@ -71,12 +85,18 @@ describe('Model.findResult', () => {
});

it('Makes a selection from empty results', () => {
expect(Model.findResult({ title: 'c' }, 'red', [])).toBe(undefined);
expect(
Model.findResult({ title: 'c', category: 'gene' }, 'red', [])
).toBe(undefined);
});

it('Makes a selection where no results match', () => {
expect(
Model.findResult({ title: 'does not exist' }, 'blue', results)
Model.findResult(
{ title: 'does not exist', category: 'gene' },
'blue',
results
)
).toBe(undefined);
});
});
Expand Down
14 changes: 13 additions & 1 deletion src/components/Search/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const makeSelection = (
}) => FeatureSearchSelection;

export const findResult = (
query: { title: string },
query: { title: string; category: string },
colour: string,
results: readonly Features[]
): FeatureSearchSelection | undefined => {
Expand All @@ -43,6 +43,17 @@ export const findResult = (
results
);

if (query.category.startsWith('Clustering:')) {
return R.head(
R.filter(
R.propEq<keyof FeatureSearchSelection>(
'category',
query.category
),
searchSpace
)
);
}
return R.head(
R.filter(
R.propEq<keyof FeatureSearchSelection>('title', query.title),
Expand Down Expand Up @@ -83,6 +94,7 @@ export const featuresToResults = (
results: features.results.map((result) => {
return {
...result,
category: features.category,
id: window.btoa(result.title + result.description),
};
}) as unknown as typeof SearchResult[],
Expand Down

0 comments on commit 54955aa

Please sign in to comment.