Skip to content

Commit

Permalink
Modify coocurrence table to only render on v2 data
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed Aug 1, 2023
1 parent 506a4b2 commit a56aea2
Show file tree
Hide file tree
Showing 6 changed files with 3,485 additions and 2 deletions.
12 changes: 10 additions & 2 deletions browser/src/GenePage/GenePage.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import renderer from 'react-test-renderer'
import { jest, describe, expect, test } from '@jest/globals'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { DatasetId, ReferenceGenome } from '@gnomad/dataset-metadata/metadata'
import {
DatasetId,
hasVariantCoocurrence,
ReferenceGenome,
} from '@gnomad/dataset-metadata/metadata'
import { mockQueries } from '../../../tests/__helpers__/queries'
import Query, { BaseQuery } from '../Query'

Expand Down Expand Up @@ -89,7 +93,11 @@ forDatasetsNotMatching(svRegexp, 'GenePage with non-SV dataset "%s"', (datasetId

await userEvent.click(cooccurrenceButton)
expect(screen.queryByText(constraintModeMatcher)).toBeNull()
expect(screen.queryAllByText(cooccurrenceModeMatcher)).not.toEqual([])
if (hasVariantCoocurrence(datasetId)) {
expect(screen.queryAllByText(cooccurrenceModeMatcher)).not.toEqual([])
} else {
expect(screen.queryAllByText(cooccurrenceModeMatcher)).toEqual([])
}

await userEvent.click(constraintButton)
expect(screen.queryByText(constraintModeMatcher)).not.toBeNull()
Expand Down
1 change: 1 addition & 0 deletions browser/src/GenePage/GenePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ const GenePage = ({ datasetId, gene, geneId }: Props) => {
<ConstraintTable datasetId={datasetId} geneOrTranscript={gene} />
) : (
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={
gene.heterozygous_variant_cooccurrence_counts!
}
Expand Down
46 changes: 46 additions & 0 deletions browser/src/GenePage/VariantCooccurrenceCountsTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,58 @@ import {
} from '../__factories__/VariantCooccurrenceCountsPerSeverityAndAf'

import VariantCooccurrenceCountsTable from './VariantCooccurrenceCountsTable'
import { forDatasetsMatching, forDatasetsNotMatching } from '../../../tests/__helpers__/datasets'

const v2Regexp = /_r2/

forDatasetsNotMatching(
v2Regexp,
'VariantCoocurrenceCountsTable with non v2 dataset "%s"',
(datasetId) => {
test('has no unexpected changes and renders as placeholder text', () => {
const heterozygousCounts =
HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
)
const normalContentFragment = tableContent.asFragment()
expect(normalContentFragment.querySelectorAll('p').length).toEqual(1)
expect(normalContentFragment.querySelectorAll('table').length).toEqual(0)
expect(normalContentFragment).toMatchSnapshot()
})
}
)

forDatasetsMatching(v2Regexp, 'VariantCoocurrenceCountsTable with v2 dataset "%s"', (datasetId) => {
test('has no unexpected changes and renders as a table', () => {
const heterozygousCounts = HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId={datasetId}
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
)
const normalContentFragment = tableContent.asFragment()
expect(normalContentFragment.querySelectorAll('p').length).toEqual(0)
expect(normalContentFragment.querySelectorAll('table').length).toEqual(2)
expect(normalContentFragment).toMatchSnapshot()
})
})

describe('VariantCooccurrenceCountsTable', () => {
test('renders correct data into correct table cells in both regular and extended mode', () => {
const heterozygousCounts = HeterozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const homozygousCounts = HomozygousVariantCooccurrenceCountsPerSeverityAndAfFactory.build()
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId="gnomad_r2_1"
heterozygous_variant_cooccurrence_counts={heterozygousCounts}
homozygous_variant_cooccurrence_counts={homozygousCounts}
/>
Expand Down Expand Up @@ -42,6 +87,7 @@ describe('VariantCooccurrenceCountsTable', () => {
test('fills in missing data with zeroes', () => {
const tableContent = render(
<VariantCooccurrenceCountsTable
datasetId="gnomad_r2_1"
heterozygous_variant_cooccurrence_counts={{}}
homozygous_variant_cooccurrence_counts={{}}
/>
Expand Down
7 changes: 7 additions & 0 deletions browser/src/GenePage/VariantCooccurrenceCountsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, Dispatch, SetStateAction, ReactNode } from 'react'
import styled from 'styled-components'

import { BaseTable, TooltipAnchor, TooltipHint, Button } from '@gnomad/ui'
import { DatasetId, hasVariantCoocurrence } from '@gnomad/dataset-metadata/metadata'

export const heterozygousVariantCooccurrenceSeverities = [
'lof_lof',
Expand Down Expand Up @@ -505,14 +506,20 @@ const HomozygousCaption = () => (
)

const VariantCooccurrenceCountsTable = ({
datasetId,
heterozygous_variant_cooccurrence_counts,
homozygous_variant_cooccurrence_counts,
}: {
datasetId: DatasetId
heterozygous_variant_cooccurrence_counts: HeterozygousVariantCooccurrenceCountsPerSeverityAndAf
homozygous_variant_cooccurrence_counts: HomozygousVariantCooccurrenceCountsPerSeverityAndAf
}) => {
const [tableMode, setTableMode] = useState<TableMode>('normal')

if (!hasVariantCoocurrence(datasetId)) {
return <p>Variant co-occurrence is only available for gnomAD v2.</p>
}

const buttonLabel = tableMode === 'normal' ? 'expand' : 'collapse'
const clickCallback = () => toggleTableMode(tableMode, setTableMode)
const toggleButton = <ModeToggle onClick={clickCallback}>{buttonLabel}</ModeToggle>
Expand Down
Loading

0 comments on commit a56aea2

Please sign in to comment.