Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Dec 9, 2023
1 parent 9805850 commit 7b5f131
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 37 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/SeqvarDetails/FreqsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const props = defineProps<{
<v-card-title class="mb-0">Population Frequencies</v-card-title>
<v-card-text>
<VariantDetailsFreqsMitochondrial
v-if="isVariantMt(seqvar)"
v-if="isVariantMt(seqvar as Seqvar)"
:seqvar="seqvar"
:var-annos="varAnnos"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const gnomadMtDna = computed(() => {
</script>

<template>
<template v-if="seqVar">
<template v-if="!seqVar">
<v-skeleton-loader type="table" />
</template>
<template v-else>
<div>
<div v-if="!isVariantMtHomopolymer(seqVar)">
<div v-if="!isVariantMtHomopolymer(seqVar as Seqvar)">
<small>
<v-icon>mdi-alert-circle-outline</v-icon>
Variant in homopolymeric region
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest'

import CriterionSwitch from '@/components/SeqvarDetails/ClinsigCard/CriterionSwitch.vue'
import {
AcmgCriteria,
AcmgEvidenceLevel,
MultiSourceAcmgCriteriaState,
Presence,
StateSource
} from '@/lib/acmgSeqVar'
import { setupMountedComponents } from '@/lib/test-utils'

describe.concurrent('CriterionSwitch', async () => {
it('renders the CriterionSwitch', async () => {
const acmgRating = new MultiSourceAcmgCriteriaState()
acmgRating.setPresence(StateSource.User, AcmgCriteria.Pm1, Presence.Present)
const { wrapper } = await setupMountedComponents(
{ component: CriterionSwitch, template: false },
{
props: {
acmgRating: acmgRating,
criteria: AcmgCriteria.Pm1,
criteriaState: {
criteria: AcmgCriteria.Pm1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.PathogenicModerate
}
}
}
)

expect(wrapper.text()).contains('Pm1')
expect(wrapper.text()).contains('Pathogenic Moderate')
const vSwitch = wrapper.findComponent({ name: 'VSwitch' })
const vTooltip = wrapper.findComponent({ name: 'VTooltip' })
const vSelect = wrapper.findComponent({ name: 'VSelect' })
expect(vSwitch.exists()).toBe(true)
expect(vTooltip.exists()).toBe(true)
expect(vSelect.exists()).toBe(true)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'

import SummarySheet from '@/components/SeqvarDetails/ClinsigCard/SummarySheet.vue'
import { setupMountedComponents } from '@/lib/test-utils'

describe.concurrent('SummarySheet', async () => {
it('renders the SummarySheet', async () => {
const { wrapper } = await setupMountedComponents(
{ component: SummarySheet, template: false },
{
props: {
calculatedAcmgClass: 'Pathogenic'
}
}
)

expect(wrapper.text()).contains('Semi-Automated ACMG Pathogenicity Prediction')
expect(wrapper.text()).contains('Pathogenic')
})
})
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { describe, expect, it } from 'vitest'

import FreqsMitochondrial from '@/components/SeqvarDetails/FreqsCard/MitochondrialFreqs.vue'
import { type Seqvar } from '@/lib/genomicVars'
import { setupMountedComponents } from '@/lib/test-utils'

const smallVariantInfo = {
release: 'grch37',
chromosome: 'chrM',
start: '70',
end: '70',
reference: 'G',
alternative: 'A',
hgnc_id: 'HGNC:1100'
const seqvarInfo: Seqvar = {
genomeBuild: 'grch37',
chrom: '17',
pos: 43044295,
del: 'G',
ins: 'A',
userRepr: 'grch37-17-43044295-G-A'
}

const variantInfo = {
Expand All @@ -37,7 +37,7 @@ describe.concurrent('FreqsMitochondrial', async () => {
{ component: FreqsMitochondrial, template: false },
{
props: {
smallVar: smallVariantInfo,
seqVar: seqvarInfo,
varAnnos: variantInfo
}
}
Expand All @@ -55,7 +55,7 @@ describe.concurrent('FreqsMitochondrial', async () => {
{ component: FreqsMitochondrial, template: false },
{
props: {
smallVar: smallVariantInfo,
seqVar: seqvarInfo,
varAnnos: variantInfoNoHelixmtdb
}
}
Expand All @@ -73,7 +73,7 @@ describe.concurrent('FreqsMitochondrial', async () => {
{ component: FreqsMitochondrial, template: false },
{
props: {
smallVar: smallVariantInfo,
seqVar: seqvarInfo,
varAnnos: variantInfoNoGnomad
}
}
Expand All @@ -89,7 +89,7 @@ describe.concurrent('FreqsMitochondrial', async () => {
{ component: FreqsMitochondrial, template: false },
{
props: {
smallVar: smallVariantInfo,
seqVar: seqvarInfo,
varAnnos: {}
}
}
Expand Down
45 changes: 32 additions & 13 deletions frontend/src/lib/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { describe, expect, it } from 'vitest'

import { type GenomeBuild } from '@/lib/genomeBuilds'
import { type Seqvar } from '@/lib/genomicVars'

import {
copy,
infoFromQuery,
Expand All @@ -10,6 +13,16 @@ import {
separateIt
} from '../utils'

/** Example Sequence variant. */
const seqVar: Seqvar = {
genomeBuild: 'grch37' as GenomeBuild,
chrom: '1',
pos: 12345,
del: 'A',
ins: 'G',
userRepr: 'chr1:12345:A:G'
}

describe.concurrent('roundIt method', () => {
it('should round a positive value with default digits', () => {
const result = roundIt(3.14159)
Expand Down Expand Up @@ -71,40 +84,46 @@ describe.concurrent('separateIt method', () => {

describe.concurrent('isVariantMt method', () => {
it('should return true if mitochondrial chromosome', () => {
const result_MT = isVariantMt({ chromosome: 'MT' })
const result_M = isVariantMt({ chromosome: 'M' })
const result_chrMT = isVariantMt({ chromosome: 'chrMT' })
const result_chrM = isVariantMt({ chromosome: 'chrM' })
seqVar.chrom = 'MT'
const result_MT = isVariantMt(seqVar)
seqVar.chrom = 'M'
const result_M = isVariantMt(seqVar)
seqVar.chrom = 'chrMT'
const result_chrMT = isVariantMt(seqVar)
seqVar.chrom = 'chrM'
const result_chrM = isVariantMt(seqVar)
expect(result_MT).toBe(true)
expect(result_M).toBe(true)
expect(result_chrMT).toBe(true)
expect(result_chrM).toBe(true)
})

it('should return false if not mitochondrial chromosome', () => {
const result = isVariantMt({ chromosome: '1' })
seqVar.chrom = '1'
const result = isVariantMt(seqVar)
expect(result).toBe(false)
})
})

describe.concurrent('isVariantMtHomopolymer method', () => {
it('should return true if mitochondrial homopolymer', () => {
const result = isVariantMtHomopolymer({ chromosome: 'MT', start: 70 })
seqVar.chrom = 'MT'
seqVar.pos = 70
const result = isVariantMtHomopolymer(seqVar)
expect(result).toBe(true)
})

it('should return false if not mitochondrial homopolymer (chromosome)', () => {
const result = isVariantMtHomopolymer({ chromosome: '1', start: 70 })
seqVar.chrom = '1'
seqVar.pos = 70
const result = isVariantMtHomopolymer(seqVar)
expect(result).toBe(false)
})

it('should return false if not mitochondrial homopolymer (position)', () => {
const result = isVariantMtHomopolymer({ chromosome: 'MT', start: 1 })
expect(result).toBe(false)
})

it('should return false for NaN', () => {
const result = isVariantMtHomopolymer(NaN)
seqVar.chrom = 'MT'
seqVar.pos = 1
const result = isVariantMtHomopolymer(seqVar)
expect(result).toBe(false)
})
})
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type RouteLocationNormalizedLoaded, type RouteLocationRaw, type Router } from 'vue-router'

import { type GenomeBuild } from '@/lib/genomeBuilds'
import { type Seqvar } from '@/lib/genomicVars'
import { type BookmarkData } from '@/stores/bookmarks'

/**
Expand Down Expand Up @@ -50,24 +51,24 @@ export const separateIt = (value: number, separator: string = ' '): string => {
/**
* Returns whether the given variant looks mitochondrial.
*
* @param smallVar Small variant to check.
* @param seqvar Small variant to check.
* @returns whether the position is on the mitochondrial genome
*/
export const isVariantMt = (smallVar: any): boolean => {
return ['MT', 'M', 'chrMT', 'chrM'].includes(smallVar?.chrom)
export const isVariantMt = (seqvar: Seqvar): boolean => {
return ['MT', 'M', 'chrMT', 'chrM'].includes(seqvar?.chrom)
}

/**
* Returns whether the given position is in a homopolymer on the mitochondrial chromosome.
*
* @param smallVar Small variant to check.
* @param seqvar Small variant to check.
* @returns whether the position is in a mitochondrial homopolymer
*/
export const isVariantMtHomopolymer = (smallVar: any): boolean => {
if (!smallVar) {
export const isVariantMtHomopolymer = (seqvar: Seqvar): boolean => {
if (!seqvar) {
return false
}
const { start, end } = smallVar
const { pos } = seqvar
const positionCheck = (pos: number) => {
return (
(pos >= 66 && pos <= 71) ||
Expand All @@ -78,8 +79,8 @@ export const isVariantMtHomopolymer = (smallVar: any): boolean => {
(pos >= 16182 && pos <= 16194)
)
}
if (isVariantMt(smallVar)) {
return positionCheck(start) || positionCheck(end)
if (isVariantMt(seqvar)) {
return positionCheck(pos)
} else {
return false
}
Expand Down

0 comments on commit 7b5f131

Please sign in to comment.