Skip to content

Commit

Permalink
feat(browser): add snapshot test for GnomadPopulationsTable
Browse files Browse the repository at this point in the history
  • Loading branch information
rileyhgrant committed Jun 26, 2024
1 parent 863dbf4 commit 5031a3d
Show file tree
Hide file tree
Showing 4 changed files with 21,102 additions and 29 deletions.
30 changes: 1 addition & 29 deletions browser/src/VariantList/mergeExomeAndGenomeData.spec.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
import { describe, it, expect } from '@jest/globals'

import { populationFactory, variantFactory } from '../__factories__/Variant'
import { createAncestryGroupObjects, variantFactory } from '../__factories__/Variant'
import { Population } from '../VariantPage/VariantPage'

import {
mergeExomeGenomeAndJointPopulationData,
mergeExomeAndGenomeData,
} from './mergeExomeAndGenomeData'

type AncestryGroupShorthand = {
id: string
value: number
}

const createAncestryGroupObjects = (
shorthands: AncestryGroupShorthand[],
includeJointFields: boolean
) => {
const geneticAncestryGroupObjects: Population[] = shorthands.map((shorthand) => {
const populationFields: any = {
id: shorthand.id,
ac: shorthand.value,
an: shorthand.value * 10,
ac_hemi: shorthand.value + 1,
ac_hom: shorthand.value + 2,
}

if (includeJointFields) {
populationFields.hemizygote_count = shorthand.value + 1
populationFields.homozygote_count = shorthand.value + 2
}
return populationFactory.build(populationFields)
})

return geneticAncestryGroupObjects
}

describe('mergeExomeGenomeAndJointPopulationData', () => {
it('returns expected values when exomes and genomes have the same populations', () => {
const geneticAncestryGroupObjects = createAncestryGroupObjects(
Expand Down
71 changes: 71 additions & 0 deletions browser/src/VariantPage/GnomadPopulationsTable.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react'
import { describe, expect, test } from '@jest/globals'
import renderer from 'react-test-renderer'

import { GnomadPopulationsTable } from './GnomadPopulationsTable'
import { allDatasetIds } from '@gnomad/dataset-metadata/metadata'
import { createAncestryGroupObjects } from '../__factories__/Variant'

describe('GnomadPopulationsTable', () => {
describe.each(allDatasetIds)('with a dataset of %s', (dataset: any) => {
test('has no unexpected changes', () => {
const exomeGeneticAncestryGroupObjexts = createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
false
)

const genomeGeneticAncestryGroupObjexts = createAncestryGroupObjects(
[
{ id: 'afr', value: 32 },
{ id: 'remaining', value: 64 },
{ id: 'eur', value: 128 },
{ id: 'XX', value: 256 },
{ id: 'XY', value: 512 },
],
false
)

const tree = renderer.create(
<GnomadPopulationsTable
datasetId={dataset}
exomePopulations={exomeGeneticAncestryGroupObjexts}
genomePopulations={genomeGeneticAncestryGroupObjexts}
jointPopulations={null}
showHemizygotes={false}
/>
)

expect(tree).toMatchSnapshot()
})
test('has no unexpected changes when missing genetic ancestry groups are filled in', () => {
const jointGeneticAncestryGroupObjects = createAncestryGroupObjects(
[
{ id: 'afr', value: 1 },
{ id: 'remaining', value: 2 },
{ id: 'eur', value: 4 },
{ id: 'XX', value: 8 },
{ id: 'XY', value: 16 },
],
true
)

const tree = renderer.create(
<GnomadPopulationsTable
datasetId={dataset}
exomePopulations={[]}
genomePopulations={[]}
jointPopulations={jointGeneticAncestryGroupObjects}
showHemizygotes={false}
/>
)

expect(tree).toMatchSnapshot()
})
})
})
Loading

0 comments on commit 5031a3d

Please sign in to comment.