-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
187 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<script setup lang="ts"> | ||
/** The component for the Acmg Criteria Card. */ | ||
import { | ||
Presence, | ||
StateSource, | ||
AcmgCriteria, | ||
type CriteriaState, | ||
AcmgEvidenceLevel, | ||
ACMG_CRITERIA_DEFS, | ||
ACMG_EVIDENCE_LEVELS_PATHOGENIC, | ||
ACMG_EVIDENCE_LEVELS_BENIGN | ||
} from '@/lib/acmgSeqVar' | ||
interface Props { | ||
/** The acmg rating. */ | ||
acmgRating: any | ||
/** The acmg criteria. */ | ||
criteria: AcmgCriteria | ||
/** The acmg criteria state. */ | ||
criteriaState: CriteriaState | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
acmgRating: undefined, | ||
criteria: undefined, | ||
criteriaState: undefined | ||
}) | ||
const findSwitchColor = (): string => { | ||
const evidence = props.criteriaState.evidenceLevel | ||
if (evidence === AcmgEvidenceLevel.PathogenicVeryStrong) { | ||
return 'red-accent-4' | ||
} else if (evidence === AcmgEvidenceLevel.PathogenicStrong) { | ||
return 'orange-darken-4' | ||
} else if (evidence === AcmgEvidenceLevel.PathogenicModerate) { | ||
return 'amber-darken-4' | ||
} else if (evidence === AcmgEvidenceLevel.PathogenicSupporting) { | ||
return 'yellow-darken-3' | ||
} else if (evidence === AcmgEvidenceLevel.BenignStandalone) { | ||
return 'green-darken-4' | ||
} else if (evidence === AcmgEvidenceLevel.BenignStrong) { | ||
return 'light-green' | ||
} else if (evidence === AcmgEvidenceLevel.BenignSupporting) { | ||
return 'lime' | ||
} else { | ||
return 'primary' | ||
} | ||
} | ||
const switchCriteria = (criteria: AcmgCriteria, presence: Presence) => { | ||
if (presence === Presence.Present) { | ||
props.acmgRating.setPresence(StateSource.User, criteria, Presence.Absent) | ||
} else { | ||
props.acmgRating.setPresence(StateSource.User, criteria, Presence.Present) | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<v-card class="mx-auto compact-form" width="150" style="margin: 10px"> | ||
<div class="d-flex justify-content-between"> | ||
<v-switch | ||
:color="findSwitchColor()" | ||
:label="props.criteria" | ||
:model-value="props.criteriaState.presence === Presence.Present" | ||
@update:model-value="switchCriteria(props.criteria, props.criteriaState.presence)" | ||
hide-details="auto" | ||
density="compact" | ||
class="switch" | ||
/> | ||
<v-tooltip :text="ACMG_CRITERIA_DEFS.get(props.criteria)?.hint"> | ||
<template v-slot:activator="{ props }"> | ||
<v-icon style="margin: 10px" v-bind="props">mdi-information</v-icon> | ||
</template> | ||
</v-tooltip> | ||
</div> | ||
<v-select | ||
:model-value="props.criteriaState.evidenceLevel" | ||
@update:model-value="props.acmgRating.setEvidenceLevel(StateSource.User, criteria, $event)" | ||
:items=" | ||
ACMG_EVIDENCE_LEVELS_PATHOGENIC.includes(props.criteriaState.evidenceLevel) | ||
? ACMG_EVIDENCE_LEVELS_PATHOGENIC | ||
: ACMG_EVIDENCE_LEVELS_BENIGN | ||
" | ||
hide-details="auto" | ||
density="compact" | ||
class="select" | ||
/> | ||
</v-card> | ||
</template> | ||
|
||
<style scoped> | ||
.switch { | ||
margin-left: 10px; | ||
padding: 0px; | ||
} | ||
.select { | ||
margin: 0px; | ||
} | ||
.compact-form { | ||
transform: scale(0.9); | ||
transform-origin: left; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
frontend/src/components/__tests__/AcmgCriteriaCard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { createRouter, createWebHistory } from 'vue-router' | ||
import { routes } from '@/router' | ||
|
||
import { createVuetify } from 'vuetify' | ||
import * as components from 'vuetify/components' | ||
import * as directives from 'vuetify/directives' | ||
|
||
import { MultiSourceAcmgCriteriaState, StateSource, AcmgCriteria, Presence } from '@/lib/acmgSeqVar' | ||
import AcmgCriteriaCard from '@/components/AcmgCriteriaCard.vue' | ||
|
||
const vuetify = createVuetify({ | ||
components, | ||
directives | ||
}) | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(import.meta.env.BASE_URL), | ||
routes: routes | ||
}) | ||
// Mock router push | ||
router.push = vi.fn() | ||
|
||
const makeWrapper = () => { | ||
const acmgRating = new MultiSourceAcmgCriteriaState() | ||
acmgRating.setPresence(StateSource.InterVar, AcmgCriteria.Pvs1, Presence.Present) | ||
const criteria = AcmgCriteria.Pvs1 | ||
const criteriaState = acmgRating.getCriteriaState(criteria) | ||
|
||
return mount(AcmgCriteriaCard, { | ||
props: { | ||
acmgRating: acmgRating, | ||
criteria: criteria, | ||
criteriaState: criteriaState | ||
}, | ||
global: { | ||
plugins: [vuetify, router], | ||
components: { | ||
AcmgCriteriaCard | ||
} | ||
} | ||
}) | ||
} | ||
|
||
describe.concurrent('AcmgCriteriaCard', async () => { | ||
it('renders the AcmgRating info', async () => { | ||
const wrapper = makeWrapper() | ||
expect(wrapper.text()).toContain('Pathogenic') | ||
expect(wrapper.text()).toContain('Pvs1') | ||
|
||
const switcher = wrapper.find('.v-switch') | ||
expect(switcher.text()).toContain('Pvs1') | ||
|
||
const selection = wrapper.find('.v-select') | ||
expect(selection.text()).toContain('Pathogenic') | ||
}) | ||
|
||
it('should correctly update the AcmgCriteriaCard info', async () => { | ||
const wrapper = makeWrapper() | ||
const switcher = wrapper.find('.v-switch') | ||
await switcher.trigger('click') | ||
|
||
const selection = wrapper.find('.v-select') | ||
await selection.trigger('click') | ||
}) | ||
}) |