From 161da9e8e47c7cd230ca7b1d1ed2ceeab1ce6174 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Wed, 3 Jan 2024 17:16:37 +0100 Subject: [PATCH] feat: cleanup front-end tests (#355) (#363) --- docs/dev_frontend.rst | 15 ++ frontend/src/api/intervar.ts | 33 +++ .../SeqvarDetails/BeaconNetworkCard.vue | 11 +- .../components/VarDetails/ClinvarsubCard.vue | 13 +- .../__tests__/BookmarkListItem.spec.ts | 4 +- .../__tests__/CaseInformationCard.spec.ts | 2 +- .../__tests__/CriterionSwitch.spec.ts | 4 +- .../__tests__/FooterDefault.spec.ts | 2 +- .../AlternativeIdentifiers.spec.ts | 2 +- .../BasicInfoCard/ExternalResources.spec.ts | 2 +- .../BasicInfoCard/GeneRifs.spec.ts | 2 +- .../BasicInfoCard/LocusDatabase.spec.ts | 2 +- .../BasicInfoCard/SupplementaryList.spec.ts | 2 +- .../ClinvarCard/ClinvarFreqPlot.spec.ts | 2 +- .../ClinvarCard/ClinvarImpact.spec.ts | 2 +- .../ClinvarCard/VariationLandscape.spec.ts | 2 +- .../GeneDetails/ConditionsCard.spec.ts | 8 +- .../ConditionsCard/CadaRanking.spec.ts | 2 +- .../GeneDetails/ExpressionCard.spec.ts | 2 +- .../GeneDetails/OverviewCard.spec.ts | 4 +- .../GeneDetails/PathogenicityCard.spec.ts | 2 +- .../__tests__/GenomeBrowser.spec.ts | 4 +- .../components/__tests__/PageHeader.spec.ts | 6 +- .../__tests__/Profile/BookmarksCard.spec.ts | 2 +- .../__tests__/Profile/CaseCard.spec.ts | 6 +- .../ClinvarsubSubmittingOrgsCard.spec.ts | 3 +- .../Profile/ProfileInformationCard.spec.ts | 4 +- .../__tests__/Profile/SeqVarsACMGCard.spec.ts | 4 +- .../components/__tests__/SearchBar.spec.ts | 6 +- .../SeqvarDetails/BeaconNetworkCard.spec.ts | 30 ++- .../SeqvarDetails/ClinsigCard.spec.ts | 80 ++++--- .../ClinsigCard/CriterionSwitch.spec.ts | 2 +- .../ClinsigCard/SummarySheet.spec.ts | 2 +- .../SeqvarDetails/ClinvarCard.spec.ts | 21 +- .../__tests__/SeqvarDetails/FreqsCard.spec.ts | 4 +- .../FreqsCard/AutosomalFreqs.spec.ts | 9 +- .../FreqsCard/MitochondrialFreqs.spec.ts | 8 +- .../__tests__/SeqvarDetails/TxCsq.spec.ts | 2 +- .../SeqvarDetails/VariantScoresCard.spec.ts | 4 +- .../VariantScoresCard/ScoreDisplay.spec.ts | 2 +- .../UcscConservation.spec.ts | 2 +- .../SeqvarDetails/VariantToolsCard.spec.ts | 4 +- .../VariantValidatorCard.spec.ts | 13 +- .../__tests__/StaticViews/AboutView.spec.ts | 2 +- .../__tests__/StaticViews/ContactView.spec.ts | 2 +- .../__tests__/StaticViews/PrivacyView.spec.ts | 4 +- .../__tests__/StaticViews/TermsView.spec.ts | 2 +- .../AcmgRatingCard/CnGain.spec.ts | 2 +- .../AcmgRatingCard/CnLoss.spec.ts | 2 +- .../AcmgRatingCard/SummarySheet.spec.ts | 2 +- .../StrucvarDetails/ClinsigCard.spec.ts | 8 +- .../StrucvarDetails/ClinvarCard.spec.ts | 2 +- .../StrucvarDetails/GeneListCard.spec.ts | 4 +- .../GeneListCard/GeneDosage.spec.ts | 6 +- .../GeneListCard/GeneListEntry.spec.ts | 2 +- .../GeneListCard/ScoreChip.spec.ts | 4 +- .../StrucvarDetails/VariantToolsCard.spec.ts | 5 +- .../__tests__/UserProfileButton.spec.ts | 6 +- .../src/components/__tests__/VegaPlot.spec.ts | 2 +- frontend/src/lib/__tests__/test-utils.spec.ts | 10 +- frontend/src/lib/test-utils.ts | 38 ++- frontend/src/lib/utils.ts | 5 - .../__tests__/strucVarAcmgRating.spec.ts | 15 +- .../src/stores/__tests__/strucVarInfo.spec.ts | 7 +- .../__tests__/variantAcmgRating.spec.ts | 15 +- .../src/stores/__tests__/variantInfo.spec.ts | 17 +- frontend/src/stores/case.ts | 6 +- frontend/src/stores/seqVarAcmgRating.ts | 17 +- .../views/__tests__/ACMGCriteriaDoc.spec.ts | 4 +- .../src/views/__tests__/ACMGSVDocs.spec.ts | 4 +- .../views/__tests__/GeneDetailView.spec.ts | 224 ++++-------------- frontend/src/views/__tests__/HomeView.spec.ts | 10 +- .../src/views/__tests__/LoginView.spec.ts | 6 +- .../src/views/__tests__/PathNotFound.spec.ts | 2 +- .../src/views/__tests__/ProfileView.spec.ts | 6 +- .../views/__tests__/SeqvarDetailsView.spec.ts | 20 +- .../src/views/__tests__/StaticView.spec.ts | 4 +- .../__tests__/StrucvarDetailsView.spec.ts | 2 +- .../views/__tests__/VerifyEmailView.spec.ts | 4 +- 79 files changed, 385 insertions(+), 422 deletions(-) create mode 100644 frontend/src/api/intervar.ts diff --git a/docs/dev_frontend.rst b/docs/dev_frontend.rst index 5e780081..2b943613 100644 --- a/docs/dev_frontend.rst +++ b/docs/dev_frontend.rst @@ -18,6 +18,13 @@ Import order should be (and is also enforced by prettier): Overall, restrict relative include order for tests to include code to be tested with ``../``. +----- +Types +----- + +- For the Vue reactive stores, explicitely specify the type in the creating function, e.g., `ref` or `ref`. +- In many places in the UI, using `undefined` is more appropriate than `null` as this is the value before the data is loaded from the backend. + -------------- Test Structure -------------- @@ -29,6 +36,7 @@ Consider the following structure, an example is given below. - put larger fixture data into ``.json`` files within the ``__tests__`` folders (will go to LFS by our ``.gitattributes`` configuration) - define the tests - use assemble, act, assert structure e.g., `as described here `__ + - guard assertions are OK - use ``describe.concurrent`` to describe the tests, usually one block per ``.spec.ts`` file - use ``it`` to define the tests - use ``async () => { ... }`` only when necessary, e.g., for ``await nextTick()`` @@ -37,3 +45,10 @@ Consider the following structure, an example is given below. .. literalinclude:: ../frontend/src/components/__tests__/UserProfileButton.spec.ts :language: typescript +Note that there is a separation between views and components (cf. https://stackoverflow.com/a/50866150/84349) that is also reflected in the tests. + +- The main purpose of views is to handle the routing. +- The actual work happens in components. + +In tests, we thus use stubbed out of nested components in views but not components. +This keeps the load time acceptable while testing the components in isolation. diff --git a/frontend/src/api/intervar.ts b/frontend/src/api/intervar.ts new file mode 100644 index 00000000..bcdd726b --- /dev/null +++ b/frontend/src/api/intervar.ts @@ -0,0 +1,33 @@ +import { API_INTERNAL_BASE_PREFIX } from '@/api/common' +import type { Seqvar } from '@/lib/genomicVars' +import type { AcmgRatingBackend } from '@/stores/seqVarAcmgRating' + +const API_BASE_URL = `${API_INTERNAL_BASE_PREFIX}/` + +export class InterVarClient { + private apiBaseUrl: string + private csrfToken: string | null + + constructor(apiBaseUrl?: string, csrfToken?: string) { + this.apiBaseUrl = apiBaseUrl ?? API_BASE_URL + this.csrfToken = csrfToken ?? null + } + + /** + * Fetch ACMG rating from InterVar via proxy. + */ + async fetchAcmgRating(seqvar: Seqvar): Promise { + const { genomeBuild, chrom, pos, del, ins } = seqvar + const release = genomeBuild === 'grch37' ? 'hg19' : 'hg38' + const url = + `${API_BASE_URL}remote/acmg/?release=${release}&chromosome=${chrom}` + + `&position=${pos}&reference=${del}&alternative=${ins}` + const response = await fetch(url, { method: 'GET' }) + + if (!response.ok) { + throw new Error(`Failed to fetch ACMG rating for ${seqvar.userRepr}`) + } + + return await response.json() + } +} diff --git a/frontend/src/components/SeqvarDetails/BeaconNetworkCard.vue b/frontend/src/components/SeqvarDetails/BeaconNetworkCard.vue index 28730e37..9267705e 100644 --- a/frontend/src/components/SeqvarDetails/BeaconNetworkCard.vue +++ b/frontend/src/components/SeqvarDetails/BeaconNetworkCard.vue @@ -1,17 +1,26 @@ +