From 7ee1d759ab4f0157c0bf430c7c82f7484f24806d Mon Sep 17 00:00:00 2001 From: Riley Grant Date: Wed, 23 Oct 2024 13:27:18 -0500 Subject: [PATCH] test(browser): add TissueExpressionTrack tests --- .../GenePage/TissueExpressionTrack.spec.tsx | 64 ++++ .../TissueExpressionTrack.spec.tsx.snap | 284 ++++++++++++++++++ browser/src/__factories__/Gene.ts | 4 + .../src/__factories__/TissueExpression.tsx | 57 ++++ 4 files changed, 409 insertions(+) create mode 100644 browser/src/GenePage/TissueExpressionTrack.spec.tsx create mode 100644 browser/src/GenePage/__snapshots__/TissueExpressionTrack.spec.tsx.snap diff --git a/browser/src/GenePage/TissueExpressionTrack.spec.tsx b/browser/src/GenePage/TissueExpressionTrack.spec.tsx new file mode 100644 index 000000000..c80507c2a --- /dev/null +++ b/browser/src/GenePage/TissueExpressionTrack.spec.tsx @@ -0,0 +1,64 @@ +import React from 'react' +import renderer from 'react-test-renderer' +import { describe, expect, test } from '@jest/globals' + +import TissueExpressionTrack, { TranscriptWithTissueExpression } from './TissueExpressionTrack' + +// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module '@gno... Remove this comment to see the full error message +import { RegionViewerContext } from '@gnomad/region-viewer' + +import geneFactory from '../__factories__/Gene' + +describe('TissueExpressionTrack', () => { + test('snapshot has no unexpected changes', () => { + const regionViewerProps = { + centerPanelWidth: 500, + isPositionDefined: true, + leftPanelWidth: 100, + regions: [ + { + start: 0, + stop: 100, + }, + ], + rightPanelWidth: 100, + scalePosition: (i: number) => i, + } + + const testTranscriptId = 'transcript-1337' + const gene = geneFactory.build({ canonical_transcript_id: testTranscriptId }) + + const testExons = [ + { + feature_type: 'CDS', + start: 10, + stop: 20, + }, + { + feature_type: 'CDS', + start: 20, + stop: 30, + }, + { + feature_type: 'CDS', + start: 40, + stop: 60, + }, + ] + + const tree = renderer.create( + + + + ) + + expect(tree).toMatchSnapshot() + }) +}) diff --git a/browser/src/GenePage/__snapshots__/TissueExpressionTrack.spec.tsx.snap b/browser/src/GenePage/__snapshots__/TissueExpressionTrack.spec.tsx.snap new file mode 100644 index 000000000..ac482e4af --- /dev/null +++ b/browser/src/GenePage/__snapshots__/TissueExpressionTrack.spec.tsx.snap @@ -0,0 +1,284 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TissueExpressionTrack snapshot has no unexpected changes 1`] = ` +
+
+
+
+
+
+ + + Mean pext + + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + 1 + + + + + + 0 + + + +
+
+
+
+
+`; diff --git a/browser/src/__factories__/Gene.ts b/browser/src/__factories__/Gene.ts index 857ec6a49..5dc208164 100644 --- a/browser/src/__factories__/Gene.ts +++ b/browser/src/__factories__/Gene.ts @@ -6,6 +6,7 @@ import { HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory, HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory, } from './VariantCooccurrenceCountsPerSeverityAndAf' +import { pextFactory } from './TissueExpression' const geneFactory = Factory.define(({ params, associations }) => { const { @@ -50,6 +51,8 @@ const geneFactory = Factory.define(({ params, associations }) => { ] : [] + const pext = pextFactory.build() + return { gene_id, gene_version, @@ -69,6 +72,7 @@ const geneFactory = Factory.define(({ params, associations }) => { structural_variants, clinvar_variants, copy_number_variants, + pext, } }) diff --git a/browser/src/__factories__/TissueExpression.tsx b/browser/src/__factories__/TissueExpression.tsx index ea6eecaa0..69d5a66c3 100644 --- a/browser/src/__factories__/TissueExpression.tsx +++ b/browser/src/__factories__/TissueExpression.tsx @@ -1,5 +1,62 @@ import { Factory } from 'fishery' import { GtexTissueExpression } from '../GenePage/TranscriptsTissueExpression' +import { Pext } from '../GenePage/GenePage' + +type PextParams = { + tissues?: string[] + regions?: { + start: number + stop: number + }[] +} + +export const pextFactory = Factory.define(({ params }) => { + const defaultTissues = ['adipose_subcutaneous', 'adipose_visceral_omentum', 'adrenal_gland'] + + const { tissues: paramTissues, regions: paramRegions } = params as PextParams + + const tissues = [...defaultTissues, ...(paramTissues ?? [])] + + const defaultRegions = [ + { + start: 10, + stop: 20, + }, + { + start: 20, + stop: 30, + }, + { + start: 40, + stop: 60, + }, + ] + + const regions = [...defaultRegions, ...(paramRegions ?? [])] + + const pextObject: Pext = { + regions: regions.map((region, i) => { + const dummyValue = i / Object.keys(tissues).length + + const tissueObjects = tissues.map((tissue) => { + return { + tissue, + value: dummyValue, + } + }) + + return { + start: region.start, + stop: region.stop, + mean: dummyValue, + tissues: tissueObjects, + } + }), + flags: [], + } + + return pextObject +}) export const gtexTissueExpressionFactory = Factory.define(({ params }) => { const defaultTissues = {