diff --git a/frontend/src/api/__tests__/acmgSeqvar.spec.ts b/frontend/src/api/__tests__/acmgSeqvar.spec.ts
index 8a8b736c..8518e810 100644
--- a/frontend/src/api/__tests__/acmgSeqvar.spec.ts
+++ b/frontend/src/api/__tests__/acmgSeqvar.spec.ts
@@ -7,6 +7,7 @@ import { type AcmgRatingBackend } from '@/stores/seqvarAcmgRating'
const fetchMocker = createFetchMock(vi)
+// Test data
const seqVar = new SeqvarImpl('grch37', '1', 123, 'A', 'G')
const mockAcmgRating: AcmgRatingBackend = {
comment: 'exampleComment',
@@ -26,15 +27,19 @@ describe.concurrent('AcmgSeqVar Client', () => {
})
it('lists ACMG ratings correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify([mockAcmgRating]))
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.listAcmgRatings()
+ // assert:
expect(result).toEqual([mockAcmgRating])
})
it('fails to list ACMG ratings', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('acmgSeqvar/list')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -42,22 +47,28 @@ describe.concurrent('AcmgSeqVar Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.listAcmgRatings()
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('fetches ACMG rating correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockAcmgRating))
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.fetchAcmgRating(seqVar)
+ // assert:
expect(result).toEqual(mockAcmgRating)
})
it('fails to fetch ACMG rating', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('acmgSeqvar/get')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -65,22 +76,28 @@ describe.concurrent('AcmgSeqVar Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.fetchAcmgRating(seqVar)
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('saves ACMG rating correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockAcmgRating))
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.saveAcmgRating(seqVar, mockAcmgRating)
+ // assert:
expect(result).toEqual(mockAcmgRating)
})
it('fails to save ACMG rating', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('acmgSeqvar/create')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -88,22 +105,28 @@ describe.concurrent('AcmgSeqVar Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.saveAcmgRating(seqVar, mockAcmgRating)
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('updates ACMG rating correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockAcmgRating))
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.updateAcmgRating(seqVar, mockAcmgRating)
+ // assert:
expect(result).toEqual(mockAcmgRating)
})
it('fails to update ACMG rating', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('acmgSeqvar/update')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -111,22 +134,28 @@ describe.concurrent('AcmgSeqVar Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.updateAcmgRating(seqVar, mockAcmgRating)
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('deletes ACMG rating correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({}))
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.deleteAcmgRating(seqVar)
+ // assert:
expect(result).toEqual({})
})
it('fails to delete ACMG rating', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('acmgSeqvar/delete')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -134,9 +163,11 @@ describe.concurrent('AcmgSeqVar Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AcmgSeqVarClient()
const result = await client.deleteAcmgRating(seqVar)
+ // assert:
expect(result).toEqual({ status: 500 })
})
})
diff --git a/frontend/src/api/__tests__/annonars.spec.ts b/frontend/src/api/__tests__/annonars.spec.ts
index f6b8b3c8..a1f58bba 100644
--- a/frontend/src/api/__tests__/annonars.spec.ts
+++ b/frontend/src/api/__tests__/annonars.spec.ts
@@ -9,6 +9,7 @@ import { SeqvarImpl } from '@/lib/genomicVars'
const fetchMocker = createFetchMock(vi)
+// Test data
const seqVar = new SeqvarImpl('grch37', '1', 123, 'A', 'G')
describe.concurrent('Annonars Client', () => {
@@ -18,14 +19,19 @@ describe.concurrent('Annonars Client', () => {
})
it('fetches gene info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1geneInfo))
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneInfo('BRCA1')
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1geneInfo))
})
it('fails to fetch gene info with wrong HGNC id', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('hgnc_id=BRCA1')) {
return Promise.resolve(JSON.stringify(BRCA1geneInfo))
@@ -33,20 +39,28 @@ describe.concurrent('Annonars Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneInfo('123')
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
it('fetches variant info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1VariantInfo))
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchVariantInfo(seqVar)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1VariantInfo))
})
it('do removes chr prefix from chromosome if genome release is grch38', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('chr')) {
return Promise.resolve(JSON.stringify(BRCA1VariantInfo))
@@ -54,12 +68,16 @@ describe.concurrent('Annonars Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchVariantInfo(seqVar)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1VariantInfo))
})
it('fails to fetch variant info with wrong variant', async () => {
+ // arrange:
const seqVarInvalid = new SeqvarImpl('grch37', '1', 123, 'A', 'T')
fetchMocker.mockResponse((req) => {
if (req.url.includes('alternative=G')) {
@@ -68,20 +86,28 @@ describe.concurrent('Annonars Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchVariantInfo(seqVarInvalid)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
it('fetches gene clinvar info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1geneInfo))
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneClinvarInfo('BRCA1')
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1geneInfo))
})
it('fails to fetch gene clinvar info with wrong HGNC id', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('hgnc_id=BRCA1')) {
return Promise.resolve(JSON.stringify(BRCA1geneInfo))
@@ -89,22 +115,30 @@ describe.concurrent('Annonars Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneClinvarInfo('123')
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
it('fetches genes correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(EMPSearchInfo))
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGenes(
'q=BRCA1&fields=hgnc_id,ensembl_gene_id,ncbi_gene_id,symbol'
)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(EMPSearchInfo))
})
it('fails to fetch genes with wrong query', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('q=BRCA1')) {
return Promise.resolve(JSON.stringify(EMPSearchInfo))
@@ -112,28 +146,39 @@ describe.concurrent('Annonars Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGenes(
'q=BRCA2&fields=hgnc_id,ensembl_gene_id,ncbi_gene_id,symbol'
)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
it('fetches gene infos correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(BRCA1geneInfo))
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneInfos(['BRCA1', 'BRCA2'])
+
+ // assert:
expect(JSON.stringify(result)).toMatch(JSON.stringify(BRCA1geneInfo['genes']['HGNC:1100']))
})
it.fails('fails to fetch gene infos with wrong HGNC id', async () => {
+ // arrange:
fetchMocker.mockResponse(() => {
return Promise.resolve(JSON.stringify({ status: 500 }))
})
+ // act:
const client = new AnnonarsClient()
const result = await client.fetchGeneInfos(['123', 'BRCA2'])
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 500 }))
})
})
diff --git a/frontend/src/api/__tests__/auth.spec.ts b/frontend/src/api/__tests__/auth.spec.ts
index e3c57ddb..1385646c 100644
--- a/frontend/src/api/__tests__/auth.spec.ts
+++ b/frontend/src/api/__tests__/auth.spec.ts
@@ -12,38 +12,50 @@ describe.concurrent('AuthClient', () => {
})
it('should login successfully', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('', { status: 204 })
+ // act:
const client = new AuthClient()
const result = await client.login('testuser', 'password123')
+ // assert:
expect(result).toBe(true)
})
it('should fail to login with incorrect credentials', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('', { status: 401 })
+ // act:
const client = new AuthClient()
const result = await client.login('invaliduser', 'invalidpassword')
+ // assert:
expect(result).toBe(false)
})
it('should logout successfully', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('Logout Successful', { status: 200 })
+ // act:
const client = new AuthClient()
const result = await client.logout()
+ // assert:
expect(result).toBe('Logout Successful')
})
it('should handle logout failure', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('Logout Failed', { status: 500 })
+ // act:
const client = new AuthClient()
const result = await client.logout()
+ // assert:
expect(result).toBe('Logout Failed')
})
})
diff --git a/frontend/src/api/__tests__/bookmarks.spec.ts b/frontend/src/api/__tests__/bookmarks.spec.ts
index 450135c0..3ecda8d9 100644
--- a/frontend/src/api/__tests__/bookmarks.spec.ts
+++ b/frontend/src/api/__tests__/bookmarks.spec.ts
@@ -7,6 +7,7 @@ import { BookmarksClient } from '../bookmarks'
const fetchMocker = createFetchMock(vi)
+// Test data
const mockBookmarks: BookmarkData[] = [
{
user: '2c0a153e-5e8c-11ee-8c99-0242ac120002',
@@ -23,6 +24,7 @@ describe.concurrent('Bookmarks Client', () => {
})
it('fetches bookmarks correctly', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('users/me')) {
return Promise.resolve(JSON.stringify({ id: '2c0a153e-5e8c-11ee-8c99-0242ac120002' }))
@@ -31,13 +33,17 @@ describe.concurrent('Bookmarks Client', () => {
}
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+
+ // act:
const client = new BookmarksClient()
const result = await client.fetchBookmarks()
+ // assert:
expect(result).toEqual(mockBookmarks)
})
it('fails to fetch bookmarks', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('users/me')) {
return Promise.resolve(JSON.stringify({ id: '2c0a153e-5e8c-11ee-8c99-0242ac120002' }))
@@ -46,63 +52,84 @@ describe.concurrent('Bookmarks Client', () => {
}
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+
+ // act:
const client = new BookmarksClient()
const result = await client.fetchBookmarks()
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('fetches bookmark correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockBookmarks[0]))
+ // act:
const client = new BookmarksClient()
const result = await client.fetchBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual(mockBookmarks[0])
})
it('fails to fetch bookmark', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({ detail: 'Internal Server Error' }), { status: 500 })
+ // act:
const client = new BookmarksClient()
const result = await client.fetchBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual({ detail: 'Internal Server Error' })
})
it('creates bookmark correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({}))
+ // act:
const client = new BookmarksClient()
const result = await client.createBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual({})
})
it('fails to create bookmark', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({ detail: 'Internal Server Error' }), { status: 500 })
+ // act:
const client = new BookmarksClient()
const result = await client.createBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual({ detail: 'Internal Server Error' })
})
it('deletes bookmark correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({}))
+ // act:
const client = new BookmarksClient()
const result = await client.deleteBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual({})
})
it('fails to delete bookmark', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({ detail: 'Internal Server Error' }), { status: 500 })
+ // act:
const client = new BookmarksClient()
const result = await client.deleteBookmark('seqvar', 'HGNC:1100')
+ // assert:
expect(result).toEqual({ detail: 'Internal Server Error' })
})
})
diff --git a/frontend/src/api/__tests__/cadaPrio.spec.ts b/frontend/src/api/__tests__/cadaPrio.spec.ts
index bf5de3fe..fa7b6cda 100644
--- a/frontend/src/api/__tests__/cadaPrio.spec.ts
+++ b/frontend/src/api/__tests__/cadaPrio.spec.ts
@@ -12,22 +12,31 @@ describe.concurrent('Cada Prio Client', () => {
})
it('fetches gene impact correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({ result: 'pathogenic' }))
+ // act:
const client = new CadaPrioClient()
const result = await client.predictGeneImpact(['HP:0000001'])
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ result: 'pathogenic' }))
})
it('fetches gene impact correctly with gene symbols', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({ result: 'pathogenic' }))
+ // act:
const client = new CadaPrioClient()
const result = await client.predictGeneImpact(['HP:0000001'], ['BRCA1'])
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ result: 'pathogenic' }))
})
it('fails to fetch gene impact with wrong HPO terms', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('hpo_terms=HP:0000001')) {
return Promise.resolve(JSON.stringify({ result: 'pathogenic' }))
@@ -35,8 +44,11 @@ describe.concurrent('Cada Prio Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new CadaPrioClient()
const result = await client.predictGeneImpact(['123'])
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
})
diff --git a/frontend/src/api/__tests__/caseinfo.spec.ts b/frontend/src/api/__tests__/caseinfo.spec.ts
index 5472e6a4..85683648 100644
--- a/frontend/src/api/__tests__/caseinfo.spec.ts
+++ b/frontend/src/api/__tests__/caseinfo.spec.ts
@@ -6,6 +6,7 @@ import { type Case, Ethnicity, Inheritance, Sex, Zygosity } from '@/stores/case'
const fetchMocker = createFetchMock(vi)
+// Test data
const mockCaseInfo: Case = {
pseudonym: '',
diseases: [],
@@ -26,15 +27,19 @@ describe.concurrent('CaseInfo Client', () => {
})
it('fetches case info correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockCaseInfo))
+ // act:
const client = new CaseInfoClient()
const result = await client.fetchCaseInfo()
+ // assert:
expect(result).toEqual(mockCaseInfo)
})
it('fails to fetch case info', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('caseinfo/get')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -42,22 +47,28 @@ describe.concurrent('CaseInfo Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new CaseInfoClient()
const result = await client.fetchCaseInfo()
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('creates case info correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockCaseInfo))
+ // act:
const client = new CaseInfoClient()
const result = await client.createCaseInfo(mockCaseInfo)
+ // assert:
expect(result).toEqual(mockCaseInfo)
})
it('fails to create case info', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('caseinfo/create')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -65,22 +76,28 @@ describe.concurrent('CaseInfo Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new CaseInfoClient()
const result = await client.createCaseInfo(mockCaseInfo)
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('updates case info correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify(mockCaseInfo))
+ // act:
const client = new CaseInfoClient()
const result = await client.updateCaseInfo(mockCaseInfo)
+ // assert:
expect(result).toEqual(mockCaseInfo)
})
it('fails to update case info', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('caseinfo/update')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -88,22 +105,28 @@ describe.concurrent('CaseInfo Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new CaseInfoClient()
const result = await client.updateCaseInfo(mockCaseInfo)
+ // assert:
expect(result).toEqual({ status: 500 })
})
it('deletes case info correctly', async () => {
+ // arrange:
fetchMocker.mockResponse(JSON.stringify({}))
+ // act:
const client = new CaseInfoClient()
const result = await client.deleteCaseInfo()
+ // assert:
expect(result).toEqual({})
})
it('fails to delete case info', async () => {
+ // arrange:
fetchMocker.mockResponse((req) => {
if (req.url.includes('caseinfo/delete')) {
return Promise.resolve(JSON.stringify({ status: 500 }))
@@ -111,9 +134,11 @@ describe.concurrent('CaseInfo Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new CaseInfoClient()
const result = await client.deleteCaseInfo()
+ // assert:
expect(result).toEqual({ status: 500 })
})
})
diff --git a/frontend/src/api/__tests__/common.spec.ts b/frontend/src/api/__tests__/common.spec.ts
index 33af0d60..327b3848 100644
--- a/frontend/src/api/__tests__/common.spec.ts
+++ b/frontend/src/api/__tests__/common.spec.ts
@@ -10,31 +10,56 @@ import {
describe.concurrent('API_BASE_PREFIX constants', () => {
it('returns the correct API base prefix in production mode', () => {
+ // arrange:
const originalMode = import.meta.env.MODE
+
+ // act: nothing, only test check
+
+ // assert:
expect(API_INTERNAL_BASE_PREFIX).toBe('/internal/')
import.meta.env.MODE = originalMode
})
it('returns the correct API base prefix for annonars in production mode', () => {
+ // arrange:
const originalMode = import.meta.env.MODE
+
+ // act: nothing, only test check
+
+ // assert:
expect(API_INTERNAL_BASE_PREFIX_ANNONARS).toBe('/internal/proxy/annonars')
import.meta.env.MODE = originalMode
})
it('returns the correct API base prefix for mehari in production mode', () => {
+ // arrange:
const originalMode = import.meta.env.MODE
+
+ // act: nothing, only test check
+
+ // assert:
expect(API_INTERNAL_BASE_PREFIX_MEHARI).toBe('/internal/proxy/mehari')
import.meta.env.MODE = originalMode
})
it('returns the correct API base prefix for nginx in production mode', () => {
+ // arrange:
const originalMode = import.meta.env.MODE
+
+ // act: nothing, only test check
+
+ // assert:
expect(API_INTERNAL_BASE_PREFIX_NGINX).toBe('/internal/proxy/nginx')
import.meta.env.MODE = originalMode
})
it('returns the correct API base prefix for cada-prio in production mode', () => {
+ // arrange:
const originalMode = import.meta.env.MODE
+
+ // act: nothing, only test check
+
+ // assert:
expect(API_INTERNAL_BASE_PREFIX_CADA_PRIO).toBe('/internal/proxy/cada-prio')
import.meta.env.MODE = originalMode
})
diff --git a/frontend/src/api/__tests__/dotty.spec.ts b/frontend/src/api/__tests__/dotty.spec.ts
index c2692c12..670b300d 100644
--- a/frontend/src/api/__tests__/dotty.spec.ts
+++ b/frontend/src/api/__tests__/dotty.spec.ts
@@ -12,6 +12,7 @@ describe.concurrent('DottyClient', () => {
})
it('should resolve to SPDI successfully', async () => {
+ // arrange:
const mockData: DottyResponse = {
success: true,
value: {
@@ -24,13 +25,16 @@ describe.concurrent('DottyClient', () => {
}
fetchMocker.mockResponseOnce(JSON.stringify(mockData), { status: 200 })
+ // act:
const client = new DottyClient()
const result = await client.toSpdi('NM_000059.3:c.274G>A')
+ // assert:
expect(result).toEqual(mockData)
})
it('should load transcripts successfully', async () => {
+ // arrange:
const mockData = {
transcripts: {
'HGNC:1100': {
@@ -40,9 +44,11 @@ describe.concurrent('DottyClient', () => {
}
fetchMocker.mockResponseOnce(JSON.stringify(mockData), { status: 200 })
+ // act:
const client = new DottyClient()
const result = await client.fetchTranscripts('HGNC:1100', 'GRCh37')
+ // assert:
expect(result).toEqual(mockData)
})
})
diff --git a/frontend/src/api/__tests__/mehari.spec.ts b/frontend/src/api/__tests__/mehari.spec.ts
index 91a162fe..bc8b87c4 100644
--- a/frontend/src/api/__tests__/mehari.spec.ts
+++ b/frontend/src/api/__tests__/mehari.spec.ts
@@ -9,6 +9,7 @@ import { LinearStrucvarImpl } from '@/lib/genomicVars'
const fetchMocker = createFetchMock(vi)
+// Test data
const seqVar = new SeqvarImpl('grch37', '1', 123, 'A', 'G')
const strucVar = new LinearStrucvarImpl('DEL', 'grch37', 'chr17', 43044295, 43044297)
@@ -19,22 +20,31 @@ describe.concurrent('Mehari Client', () => {
})
it('fetches TxCsq info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1TxInfo))
+ // act:
const client = new MehariClient()
const result = await client.retrieveSeqvarsCsq(seqVar, 'HGNC:1100')
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1TxInfo))
})
it('fetches TxCsq info correctly without HGNC id', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(BRCA1TxInfo))
+ // act:
const client = new MehariClient()
const result = await client.retrieveSeqvarsCsq(seqVar)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(BRCA1TxInfo))
})
it('fails to fetch variant info with wrong variant', async () => {
+ // arrange:
const seqVarInvalid = new SeqvarImpl('grch37', '1', 123, 'A', 'T')
fetchMocker.mockResponse((req) => {
if (req.url.includes('alternative=G')) {
@@ -43,20 +53,28 @@ describe.concurrent('Mehari Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new MehariClient()
const result = await client.retrieveSeqvarsCsq(seqVarInvalid)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
it('fetches Structur Variant info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify(SVInfo))
+ // act:
const client = new MehariClient()
const result = await client.retrieveStrucvarsCsq(strucVar)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify(SVInfo))
})
it('fails to fetch variant info with wrong variant', async () => {
+ // arrange:
const strucVarInvalid = new LinearStrucvarImpl('DUP', 'grch37', 'chr17', 43044295, 43044297)
fetchMocker.mockResponse((req) => {
if (req.url.includes('DEL')) {
@@ -65,8 +83,11 @@ describe.concurrent('Mehari Client', () => {
return Promise.resolve(JSON.stringify({ status: 400 }))
})
+ // act:
const client = new MehariClient()
const result = await client.retrieveStrucvarsCsq(strucVarInvalid)
+
+ // assert:
expect(JSON.stringify(result)).toEqual(JSON.stringify({ status: 400 }))
})
})
diff --git a/frontend/src/api/__tests__/misc.spec.ts b/frontend/src/api/__tests__/misc.spec.ts
index 48c95517..45e97193 100644
--- a/frontend/src/api/__tests__/misc.spec.ts
+++ b/frontend/src/api/__tests__/misc.spec.ts
@@ -12,10 +12,14 @@ describe.concurrent('Misc Client', () => {
})
it('fetches version info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('v0.0.0')
+ // act:
const client = new MiscClient()
const result = await client.fetchVersion()
+
+ // assert:
expect(result).toEqual('v0.0.0')
})
})
diff --git a/frontend/src/api/__tests__/settings.spec.ts b/frontend/src/api/__tests__/settings.spec.ts
index 7af17775..bc58056f 100644
--- a/frontend/src/api/__tests__/settings.spec.ts
+++ b/frontend/src/api/__tests__/settings.spec.ts
@@ -12,52 +12,76 @@ describe.concurrent('Settings Client', () => {
})
it('fetches version info correctly', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(
JSON.stringify({ matomo_host: 'https://matomo.example.com/', matomo_site_id: '1' })
)
+ // act:
const client = new SettingsClient()
const result = await client.fetchFrontendSettings()
+
+ // assert:
expect(result).toEqual({ matomo_host: 'https://matomo.example.com/', matomo_site_id: '1' })
})
it('handles different settings data', async () => {
+ // arrange:
const alternativeSettings = { theme: 'dark', language: 'en' }
fetchMocker.mockResponseOnce(JSON.stringify(alternativeSettings))
+ // act:
const client = new SettingsClient()
const result = await client.fetchFrontendSettings()
+
+ // assert:
expect(result).toEqual(alternativeSettings)
})
it('handles empty settings response', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({}))
+ // act:
const client = new SettingsClient()
const result = await client.fetchFrontendSettings()
+
+ // assert:
expect(result).toEqual({})
})
it('handles null settings response', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('null')
+ // act:
const client = new SettingsClient()
const result = await client.fetchFrontendSettings()
+
+ // assert:
expect(result).toBeNull()
})
it('handles server error when fetching settings', async () => {
+ // arrange:
const errorMessage = 'Internal Server Error' // The statusText for a 500 error
fetchMocker.mockResponseOnce(JSON.stringify({ msg: 'Internal server error' }), { status: 500 })
+ // act:
const client = new SettingsClient()
+
+ // assert:
await expect(client.fetchFrontendSettings()).rejects.toThrow(errorMessage)
})
it('handles network error when fetching settings', async () => {
+ // arrange:
fetchMocker.mockReject(new Error('Network Error'))
+ // act:
const client = new SettingsClient()
+
+ // assert:
await expect(client.fetchFrontendSettings()).rejects.toThrow('Network Error')
})
})
diff --git a/frontend/src/api/__tests__/users.spec.ts b/frontend/src/api/__tests__/users.spec.ts
index 69e1607c..47491f40 100644
--- a/frontend/src/api/__tests__/users.spec.ts
+++ b/frontend/src/api/__tests__/users.spec.ts
@@ -12,6 +12,7 @@ describe.concurrent('Users Client', () => {
})
it('should fetch current user profile successfully', async () => {
+ // arrange:
const userData = {
id: '1',
email: 'test@example.com',
@@ -21,17 +22,22 @@ describe.concurrent('Users Client', () => {
}
fetchMocker.mockResponseOnce(JSON.stringify(userData), { status: 200 })
+ // act:
const client = new UsersClient()
const result = await client.fetchCurrentUserProfile()
+ // assert:
expect(result).toEqual(userData)
})
it('should throw UnauthenticatedError when not authenticated', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('', { status: 401 })
+ // act:
const client = new UsersClient()
+ // assert:
try {
await client.fetchCurrentUserProfile()
expect(true).toBe(false)
@@ -41,10 +47,13 @@ describe.concurrent('Users Client', () => {
})
it('should throw UnauthenticatedError on unexpected status', async () => {
+ // arrange:
fetchMocker.mockResponseOnce('', { status: 500 })
+ // act:
const client = new UsersClient()
+ // assert:
try {
await client.fetchCurrentUserProfile()
expect(true).toBe(false)
diff --git a/frontend/src/api/__tests__/utils.spec.ts b/frontend/src/api/__tests__/utils.spec.ts
index 85356deb..7e9c8c2d 100644
--- a/frontend/src/api/__tests__/utils.spec.ts
+++ b/frontend/src/api/__tests__/utils.spec.ts
@@ -14,50 +14,45 @@ describe.concurrent('Utils Client', () => {
})
it('sends a test email correctly', async () => {
- // Prepare the mock response
+ // arrange:
const mockResponse = { msg: 'Test email sent successfully' }
fetchMocker.mockResponseOnce(JSON.stringify(mockResponse))
- // Instantiate the client and perform the action
+ // act:
const client = new UtilsClient()
const email_to = 'test@example.com'
const result = await client.sendTestEmail(email_to)
- // Assert that the fetch was called correctly
+ // assert:
expect(fetchMocker).toHaveBeenCalledWith(
`${API_V1_BASE_PREFIX}utils/test-email/?email_to=${email_to}`,
{
method: 'POST'
}
)
-
- // Assert the response matches the expected result
expect(result).toEqual(mockResponse)
})
it('handles invalid email address error', async () => {
- // Prepare the mock response for an invalid email address
+ // arrange:
const mockErrorResponse = { msg: 'Invalid email address' }
fetchMocker.mockResponseOnce(JSON.stringify(mockErrorResponse), { status: 400 })
+ // act:
const client = new UtilsClient()
const invalidEmail = 'invalid-email'
- // Try-catch block to handle the expected error
+ // assert:
try {
await client.sendTestEmail(invalidEmail)
- // If no error is thrown, force the test to fail
expect(true).toBe(false)
} catch (error) {
- // Assert the fetch was called with the invalid email
expect(fetchMocker).toHaveBeenCalledWith(
expect.stringContaining(`email_to=${invalidEmail}`),
{
method: 'POST'
}
)
-
- // Assert the error message matches the expected result
expect(error).toEqual(
new AssertionError({ message: 'expected true to be false // Object.is equality' })
)
@@ -65,25 +60,22 @@ describe.concurrent('Utils Client', () => {
})
it('handles server error when sending an email', async () => {
- // Prepare the mock response for a server error
+ // arrange:
const mockServerErrorResponse = { msg: 'Internal server error' }
fetchMocker.mockResponseOnce(JSON.stringify(mockServerErrorResponse), { status: 500 })
+ // act:
const client = new UtilsClient()
const email_to = 'test@example.com'
- // Try-catch block to handle the expected error
+ // assert:
try {
await client.sendTestEmail(email_to)
- // If no error is thrown, force the test to fail
expect(true).toBe(false)
} catch (error) {
- // Assert the fetch was called correctly
expect(fetchMocker).toHaveBeenCalledWith(expect.stringContaining(`email_to=${email_to}`), {
method: 'POST'
})
-
- // Assert the error message matches the expected server error
expect(error).toEqual(
new AssertionError({ message: 'expected true to be false // Object.is equality' })
)
diff --git a/frontend/src/api/__tests__/viguno.spec.ts b/frontend/src/api/__tests__/viguno.spec.ts
index b8c9eaab..b023816f 100644
--- a/frontend/src/api/__tests__/viguno.spec.ts
+++ b/frontend/src/api/__tests__/viguno.spec.ts
@@ -12,136 +12,200 @@ describe.concurrent('Viguno Client', () => {
})
it('resolves OMIM term by ID correctly', async () => {
+ // arrange:
const mockOmimTerm = { id: 'OMIM:123456', name: 'Example Disease' }
fetchMocker.mockResponseOnce(JSON.stringify(mockOmimTerm))
+ // act:
const client = new VigunoClient()
const result = await client.resolveOmimTermById('123456')
+
+ // assert:
expect(result).toEqual(mockOmimTerm)
})
it('handles non-existent OMIM term ID', async () => {
+ // arrange:
const errorMessage = 'OMIM term not found'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 404 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveOmimTermById('999999')).rejects.toThrow(errorMessage)
})
it('handles server error when resolving OMIM term by ID', async () => {
+ // arrange:
const errorMessage = 'Internal Server Error'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 500 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveOmimTermById('123456')).rejects.toThrow(errorMessage)
})
it('handles network error when resolving OMIM term by ID', async () => {
+ // arrange:
fetchMocker.mockReject(new Error('Network Error'))
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveOmimTermById('123456')).rejects.toThrow('Network Error')
})
it('returns a list of OMIM terms for a valid query', async () => {
+ // arrange:
const mockResponse = [
{ id: 'OMIM:123456', name: 'Example Disease 1' },
{ id: 'OMIM:234567', name: 'Example Disease 2' }
]
fetchMocker.mockResponseOnce(JSON.stringify(mockResponse))
+ // act:
const client = new VigunoClient()
const result = await client.queryOmimTermsByName('Example')
+
+ // assert:
expect(result).toEqual(mockResponse)
})
it('returns an empty list for a query with no results', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify([]))
+ // act:
const client = new VigunoClient()
const result = await client.queryOmimTermsByName('NonExistentDisease')
+
+ // assert:
expect(result).toEqual([])
})
it('handles server error for a query', async () => {
+ // arrange:
const errorMessage = 'Internal Server Error'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 500 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.queryOmimTermsByName('Example')).rejects.toThrow(errorMessage)
})
it('handles network error during a query', async () => {
+ // arrange:
fetchMocker.mockReject(new Error('Network Error'))
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.queryOmimTermsByName('Example')).rejects.toThrow('Network Error')
})
it('resolves HPO term by ID correctly', async () => {
+ // arrange:
const mockHpoTerm = { id: 'HP:0000118', name: 'Phenotypic abnormality' }
fetchMocker.mockResponseOnce(JSON.stringify(mockHpoTerm))
+ // act:
const client = new VigunoClient()
const result = await client.resolveHpoTermById('0000118')
+
+ // assert:
expect(result).toEqual(mockHpoTerm)
})
it('handles non-existent HPO term ID', async () => {
+ // arrange:
const errorMessage = 'HPO term not found'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 404 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveHpoTermById('9999999')).rejects.toThrow(errorMessage)
})
it('handles server error when resolving HPO term by ID', async () => {
+ // arrange:
const errorMessage = 'Internal Server Error'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 500 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveHpoTermById('0000118')).rejects.toThrow(errorMessage)
})
it('handles network error when resolving HPO term by ID', async () => {
+ // arrange:
fetchMocker.mockReject(new Error('Network Error'))
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.resolveHpoTermById('0000118')).rejects.toThrow('Network Error')
})
it('queries HPO terms by name correctly', async () => {
+ // arrange:
const mockHpoTerms = [
{ id: 'HP:0000118', name: 'Phenotypic abnormality' },
{ id: 'HP:0000152', name: 'Abnormality of head or neck' }
]
fetchMocker.mockResponseOnce(JSON.stringify(mockHpoTerms))
+ // act:
const client = new VigunoClient()
const result = await client.queryHpoTermsByName('Phenotypic')
+
+ // assert:
expect(result).toEqual(mockHpoTerms)
})
it('returns an empty list for a name query with no results', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify([]))
+ // act:
const client = new VigunoClient()
const result = await client.queryHpoTermsByName('NonExistentTerm')
+
+ // assert:
expect(result).toEqual([])
})
it('handles server error during name query', async () => {
+ // arrange:
const errorMessage = 'Internal Server Error'
fetchMocker.mockResponseOnce(JSON.stringify({ msg: errorMessage }), { status: 500 })
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.queryHpoTermsByName('Phenotypic')).rejects.toThrow(errorMessage)
})
it('handles network error during name query', async () => {
+ // arrange:
fetchMocker.mockReject(new Error('Network Error'))
+ // act:
const client = new VigunoClient()
+
+ // assert:
await expect(client.queryHpoTermsByName('Phenotypic')).rejects.toThrow('Network Error')
})
})
diff --git a/frontend/src/lib/__tests__/acmgSeqvar.spec.ts b/frontend/src/lib/__tests__/acmgSeqvar.spec.ts
index b6694c50..c64c3acd 100644
--- a/frontend/src/lib/__tests__/acmgSeqvar.spec.ts
+++ b/frontend/src/lib/__tests__/acmgSeqvar.spec.ts
@@ -10,7 +10,12 @@ import {
describe.concurrent('MultiSourceAcmgCriteriaState', () => {
it('should have correct default values', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
// Check keys of AcmgCriteriaState.criteriaStates
expect(Object.keys(AcmgCriteriaState.criteriaStates).length).toEqual(4)
expect(AcmgCriteriaState.criteriaStates).toHaveProperty(StateSource.Default)
@@ -36,119 +41,174 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly get criteria state', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(AcmgCriteriaState.getCriteriaState(AcmgCriteria.PVS1)).toEqual(
AcmgCriteriaState.criteriaStates[StateSource.Default][AcmgCriteria.PVS1]
)
})
it('should correctly get criteria state from interVar', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.PathogenicVeryStrong
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(AcmgCriteriaState.getCriteriaState(AcmgCriteria.PVS1)).toStrictEqual(criteriaState)
})
it('should correctly get criteria state from server', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.PathogenicVeryStrong
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.Server, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(AcmgCriteriaState.getCriteriaState(AcmgCriteria.PVS1)).toStrictEqual(criteriaState)
})
it('should correctly get criteria state from server and InterVar', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Absent,
evidenceLevel: AcmgEvidenceLevel.PathogenicVeryStrong
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
AcmgCriteriaState.setPresence(StateSource.Server, AcmgCriteria.PVS1, Presence.Absent)
+
+ // assert:
expect(AcmgCriteriaState.getCriteriaState(AcmgCriteria.PVS1)).toStrictEqual(criteriaState)
})
it('should correctly get criteria state with invalid request', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: 'invalid' as AcmgCriteria,
presence: Presence.Unknown,
evidenceLevel: AcmgEvidenceLevel.NotSet
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(AcmgCriteriaState.getCriteriaState('invalid' as AcmgCriteria)).toStrictEqual(
criteriaState
)
})
it('should correctly get criteria state from default source', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Unknown,
evidenceLevel: AcmgEvidenceLevel.PathogenicVeryStrong
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(
AcmgCriteriaState.getCriteriaStateFromSource(AcmgCriteria.PVS1, StateSource.Default)
).toStrictEqual(criteriaState)
})
it('should correctly get criteria state from interVar source', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.NotSet
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(
AcmgCriteriaState.getCriteriaStateFromSource(AcmgCriteria.PVS1, StateSource.InterVar)
).toStrictEqual(criteriaState)
})
it('should correctly get criteria state from server source', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.NotSet
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.Server, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(
AcmgCriteriaState.getCriteriaStateFromSource(AcmgCriteria.PVS1, StateSource.Server)
).toStrictEqual(criteriaState)
})
it('should correctly get criteria state from user source', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange:
const criteriaState = {
criteria: AcmgCriteria.PVS1,
presence: Presence.Present,
evidenceLevel: AcmgEvidenceLevel.NotSet
}
+
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(
AcmgCriteriaState.getCriteriaStateFromSource(AcmgCriteria.PVS1, StateSource.User)
).toStrictEqual(criteriaState)
})
it('should throw error if getting invalid criteria from source', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(() =>
AcmgCriteriaState.getCriteriaStateFromSource('invalid' as AcmgCriteria, StateSource.User)
).toThrowError()
})
it('should correctly set presence for InterVar', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(
AcmgCriteriaState.criteriaStates[StateSource.InterVar][AcmgCriteria.PVS1].presence
).toEqual(Presence.Present)
@@ -162,8 +222,13 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly set presence for Server', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.Server, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(
AcmgCriteriaState.criteriaStates[StateSource.Server][AcmgCriteria.PVS1].presence
).toEqual(Presence.Present)
@@ -177,8 +242,13 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly set presence for User', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Present)
+
+ // assert:
expect(AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].presence).toEqual(
Presence.Present
)
@@ -192,13 +262,21 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should raise error for setting present for Default', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(() =>
AcmgCriteriaState.setPresence(StateSource.Default, AcmgCriteria.PVS1, Presence.Present)
).toThrowError()
})
it('should correctly set absent presence for User', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Absent)
expect(AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].presence).toEqual(
@@ -206,12 +284,17 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
)
// Set presence to absent
AcmgCriteriaState.setUserPresenceAbsent()
+
+ // assert:
expect(AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].presence).toEqual(
Presence.Absent
)
})
it('should correctly set interVar presence for User', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Absent)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
@@ -220,12 +303,17 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
)
// Set presence to unknown
AcmgCriteriaState.setUserPresenceInterVar()
+
+ // assert:
expect(AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].presence).toEqual(
Presence.Present
)
})
it('should correctly set server presence for User', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Absent)
AcmgCriteriaState.setPresence(StateSource.Server, AcmgCriteria.PVS1, Presence.Present)
@@ -234,18 +322,25 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
)
// Set presence to unknown
AcmgCriteriaState.setUserPresenceServer()
+
+ // assert:
expect(AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].presence).toEqual(
Presence.Present
)
})
it('should correctly set evidence level for user', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setEvidenceLevel(
StateSource.User,
AcmgCriteria.PVS1,
AcmgEvidenceLevel.PathogenicModerate
)
+
+ // assert:
expect(
AcmgCriteriaState.criteriaStates[StateSource.User][AcmgCriteria.PVS1].evidenceLevel
).toEqual(AcmgEvidenceLevel.PathogenicModerate)
@@ -259,12 +354,17 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly set evidence level for server', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setEvidenceLevel(
StateSource.Server,
AcmgCriteria.PVS1,
AcmgEvidenceLevel.PathogenicModerate
)
+
+ // assert:
expect(
AcmgCriteriaState.criteriaStates[StateSource.Server][AcmgCriteria.PVS1].evidenceLevel
).toEqual(AcmgEvidenceLevel.PathogenicModerate)
@@ -278,12 +378,17 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly set evidence level for interVar', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setEvidenceLevel(
StateSource.InterVar,
AcmgCriteria.PVS1,
AcmgEvidenceLevel.PathogenicModerate
)
+
+ // assert:
expect(
AcmgCriteriaState.criteriaStates[StateSource.InterVar][AcmgCriteria.PVS1].evidenceLevel
).toEqual(AcmgEvidenceLevel.PathogenicModerate)
@@ -297,7 +402,12 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should raise error for setting evidence level for Default', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+
+ // assert:
expect(() =>
AcmgCriteriaState.setEvidenceLevel(
StateSource.Default,
@@ -308,9 +418,13 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly get States', () => {
- const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
+ // arrange: nothing, only test check
+ // act:
+ const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
const criteriaStates = AcmgCriteriaState.getStates()
+
+ // assert:
// Check keys of AcmgCriteriaState.criteriaStates
expect(Object.keys(criteriaStates).length).toEqual(4)
expect(criteriaStates).toHaveProperty(StateSource.Default)
@@ -336,6 +450,9 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
})
it('should correctly get evidence counts', () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, Presence.Present)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PS1, Presence.Present)
@@ -349,6 +466,7 @@ describe.concurrent('MultiSourceAcmgCriteriaState', () => {
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS2, Presence.Present)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS3, Presence.Present)
+ // assert:
expect(
AcmgCriteriaState.getActiveEvidenceCounts(AcmgEvidenceLevel.PathogenicVeryStrong)
).toEqual(1)
@@ -470,6 +588,9 @@ describe.concurrent(
`should return 'Pathogenic' for 'PVS1: %s, PS1: %s, PS2: %s, PM1: %s, PM2: %s, PM3: %s,
PM4: %s, PP1: %s, PP2: %s, PP3: %s, PP4: %s' with no confclicts`,
(pvs1, ps1, ps2, pm1, pm2, pm3, pp1, pp2, pp3, pp4) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, pvs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PS1, ps1)
@@ -481,6 +602,8 @@ describe.concurrent(
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP2, pp2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP3, pp3)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP4, pp4)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Pathogenic', false])
}
)
@@ -574,6 +697,9 @@ describe.concurrent(
`should return 'Likely pathogenic' for 'PVS1: %s, PS1: %s, PS2: %s, PM1: %s, PM2: %s, PM3: %s,
PM4: %s, PP1: %s, PP2: %s, PP3: %s, PP4: %s' with no confclicts`,
(pvs1, ps1, ps2, pm1, pm2, pm3, pp1, pp2, pp3, pp4) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, pvs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PS1, ps1)
@@ -585,6 +711,8 @@ describe.concurrent(
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP2, pp2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP3, pp3)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP4, pp4)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Likely pathogenic', false])
}
)
@@ -598,12 +726,17 @@ describe.concurrent(
])(
`should return 'Benign' for 'BA1: %s, BS1: %s, BS2: %s, BP1: %s, BP2: %s' with no confclicts`,
(ba1, bs1, bs2, bp1, bp2) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BA1, ba1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS1, bs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS2, bs2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BP1, bp1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BP2, bp2)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Benign', false])
}
)
@@ -615,12 +748,17 @@ describe.concurrent(
`should return 'Likely benign' for 'BA1: %s, BS1: %s, BS2: %s, BP1: %s, BP2: %s' with no
confclicts`,
(ba1, bs1, bs2, bp1, bp2) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BA1, ba1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS1, bs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS2, bs2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BP1, bp1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BP2, bp2)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Likely benign', false])
}
)
@@ -638,12 +776,17 @@ describe.concurrent(
`should return 'Uncertain significance' for 'PM1: %s, PP1: %s, PP2: %s, BS1: %s, BP1: %s'
with no confclicts`,
(pm1, pp1, pp2, bs1, bp1) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PM1, pm1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP1, pp1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PP2, pp2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS1, bs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BP1, bp1)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Uncertain significance', false])
}
)
@@ -656,12 +799,17 @@ describe.concurrent(
`should return 'Conflicting' for 'PVS1: %s, PS1: %s, PS2: %s, BA1: %s, BS1: %s'
with confclicts`,
(pvs1, ps1, ps2, ba1, bs1) => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PVS1, pvs1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PS1, ps1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.PS2, ps2)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BA1, ba1)
AcmgCriteriaState.setPresence(StateSource.InterVar, AcmgCriteria.BS1, bs1)
+
+ // assert:
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Conflicting', true])
}
)
@@ -672,6 +820,9 @@ describe.concurrent(
'MultiSourceAcmgCriteriaState ACMG class computation with user override',
() => {
it(`should return 'Likely pathogenic' for PVS1 as Moderate and PS1`, () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
// Set PVS1 and PS1 to present
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.PVS1, Presence.Present)
@@ -685,11 +836,15 @@ describe.concurrent(
AcmgEvidenceLevel.PathogenicModerate
)
+ // assert:
// Expect to return 'Likely pathogenic'
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Likely pathogenic', false])
})
it(`should return 'Likely benign' for Ba1 as Strong and Bs1 as Supporting`, () => {
+ // arrange: nothing, only test check
+
+ // act:
const AcmgCriteriaState = new MultiSourceAcmgCriteriaState()
// Set Ba1 and Bs1 to present
AcmgCriteriaState.setPresence(StateSource.User, AcmgCriteria.BA1, Presence.Present)
@@ -709,6 +864,7 @@ describe.concurrent(
AcmgEvidenceLevel.BenignSupporting
)
+ // assert:
// Expect to return 'Likely benign'
expect(AcmgCriteriaState.getAcmgClass()).toEqual(['Likely benign', false])
})
diff --git a/frontend/src/lib/__tests__/genomeBuild.spec.ts b/frontend/src/lib/__tests__/genomeBuild.spec.ts
index 77f8f34b..6d73fe07 100644
--- a/frontend/src/lib/__tests__/genomeBuild.spec.ts
+++ b/frontend/src/lib/__tests__/genomeBuild.spec.ts
@@ -11,10 +11,18 @@ import {
describe.concurrent('constants', () => {
it('genomeBuildAliases should have the well-known keys', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(Object.keys(GENOME_BUILD_ALIASES)).toEqual(['hg19', 'grch37', 'hg38', 'grch38'])
})
it('CHROM_REFSEQ_37 should have the well-known keys', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(Object.keys(CHROM_REFSEQ_37)).toEqual([
'1',
'2',
@@ -45,6 +53,10 @@ describe.concurrent('constants', () => {
})
it('CHROM_REFSEQ_38 should have the well-known keys', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(Object.keys(CHROM_REFSEQ_38)).toEqual([
'1',
'2',
@@ -75,6 +87,10 @@ describe.concurrent('constants', () => {
})
it('CHROM_LENGTHS_37 should have the well-known keys', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(Object.keys(CHROM_LENGTHS_37)).toEqual([
'1',
'2',
@@ -105,6 +121,10 @@ describe.concurrent('constants', () => {
})
it('CHROM_LENGTHS_38 should have the well-known keys', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(Object.keys(CHROM_LENGTHS_38)).toEqual([
'1',
'2',
@@ -135,6 +155,10 @@ describe.concurrent('constants', () => {
})
it('lengths of 37 and 38 differ but not in chrMT', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(CHROM_LENGTHS_37.X).not.toEqual(CHROM_LENGTHS_38.X)
expect(CHROM_LENGTHS_37.Y).not.toEqual(CHROM_LENGTHS_38.Y)
expect(CHROM_LENGTHS_37.MT).toEqual(CHROM_LENGTHS_38.MT)
@@ -143,24 +167,44 @@ describe.concurrent('constants', () => {
describe.concurrent('refseqToGenomeBuild', () => {
it('should return grch37 for NC_000001.10', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(refseqToGenomeBuild('NC_000001.10')).toEqual('grch37')
})
it('should return grch38 for NC_000001.11', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(refseqToGenomeBuild('NC_000001.11')).toEqual('grch38')
})
it('should return grch38 for NC_012920.1', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(refseqToGenomeBuild('NC_012920.1')).toEqual('grch38')
})
it('should work case insensitive', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(refseqToGenomeBuild('nc_000001.10')).toEqual('grch37')
expect(refseqToGenomeBuild('nc_000001.11')).toEqual('grch38')
expect(refseqToGenomeBuild('nc_012920.1')).toEqual('grch38')
})
it('should throw an error for NC_000001.12', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(() => refseqToGenomeBuild('NC_000001.12')).toThrow(
'Unknown RefSeq identifier: NC_000001.12'
)
diff --git a/frontend/src/lib/__tests__/genomicVars.spec.ts b/frontend/src/lib/__tests__/genomicVars.spec.ts
index 7891ea46..85bf5e62 100644
--- a/frontend/src/lib/__tests__/genomicVars.spec.ts
+++ b/frontend/src/lib/__tests__/genomicVars.spec.ts
@@ -25,6 +25,10 @@ import {
describe.concurrent('regular expression REGEX_GNOMAD_VARIANT', () => {
it('should match variants with chromosome name only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('chr1-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
expect('chr22-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
expect('chrX-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
@@ -46,6 +50,10 @@ describe.concurrent('regular expression REGEX_GNOMAD_VARIANT', () => {
})
it('should match variants with valid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('hg19-chr1-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
expect('hg19-chr22-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
expect('hg38-chrX-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
@@ -67,6 +75,10 @@ describe.concurrent('regular expression REGEX_GNOMAD_VARIANT', () => {
})
it('should match variants with invalid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('T2T-Y-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
expect('T2T-MT-100-AT-TG').toMatch(REGEX_GNOMAD_VARIANT)
@@ -82,6 +94,10 @@ describe.concurrent('regular expression REGEX_GNOMAD_VARIANT', () => {
describe.concurrent('regular expression REGEX_CANONICAL_SPDI', () => {
it('should match correctly formatted variants only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('NC_000001.11:100:AT:TG').toMatch(REGEX_CANONICAL_SPDI)
expect('NC_999999.999:100:AT:TG').toMatch(REGEX_CANONICAL_SPDI)
expect('NC_000000.0:100:AT:TG').toMatch(REGEX_CANONICAL_SPDI)
@@ -103,6 +119,10 @@ describe.concurrent('regular expression REGEX_CANONICAL_SPDI', () => {
describe.concurrent('regular expression REGEX_RELAXED_SPDI', () => {
it('should match variants with chromosome name only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('chr1:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
expect('chr22:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
expect('chrX:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
@@ -124,6 +144,10 @@ describe.concurrent('regular expression REGEX_RELAXED_SPDI', () => {
})
it('should match variants with valid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('hg19:chr1:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
expect('hg19:chr22:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
expect('hg38:chrX:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
@@ -145,6 +169,10 @@ describe.concurrent('regular expression REGEX_RELAXED_SPDI', () => {
})
it('should match variants with invalid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('T2T:Y:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
expect('T2T:MT:100:AT:TG').toMatch(REGEX_RELAXED_SPDI)
@@ -160,6 +188,10 @@ describe.concurrent('regular expression REGEX_RELAXED_SPDI', () => {
describe.concurrent('regular expression REGEX_DBSNP_ID', () => {
it('should match correctly formatted rs IDs only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('rs1').toMatch(REGEX_DBSNP_ID)
expect('rs99999999999').toMatch(REGEX_DBSNP_ID)
expect('sr1').not.toMatch(REGEX_DBSNP_ID)
@@ -169,6 +201,10 @@ describe.concurrent('regular expression REGEX_DBSNP_ID', () => {
describe.concurrent('regular expression REGEX_CLINVAR_ID', () => {
it('should match correctly formatted IDs only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('VCV000148363.2').toMatch(REGEX_CLINVAR_ID)
expect('VCV000000000.0').toMatch(REGEX_CLINVAR_ID)
expect('RCV000148363.2').toMatch(REGEX_CLINVAR_ID)
@@ -194,6 +230,10 @@ describe.concurrent('regular expression REGEX_CLINVAR_ID', () => {
describe.concurrent('regular expression REGEX_CNV_COLON', () => {
it('should match variants with chromosome name only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL:chr1:100:200').toMatch(REGEX_CNV_COLON)
expect('DEL:1:100:200').toMatch(REGEX_CNV_COLON)
expect('DUP:chr1:100:200').toMatch(REGEX_CNV_COLON)
@@ -210,6 +250,10 @@ describe.concurrent('regular expression REGEX_CNV_COLON', () => {
})
it('should match variants with valid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL:GRCh37:chr1:100:200').toMatch(REGEX_CNV_COLON)
expect('DEL:GRCh38:1:100:200').toMatch(REGEX_CNV_COLON)
expect('DUP:hg19:chr1:100:200').toMatch(REGEX_CNV_COLON)
@@ -226,6 +270,10 @@ describe.concurrent('regular expression REGEX_CNV_COLON', () => {
})
it('should match variants with RefSeq identifiers', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL:NC_000001.10:100:200').toMatch(REGEX_CNV_COLON)
expect('DEL:NC_000001.11:100:200').toMatch(REGEX_CNV_COLON)
expect('DUP:NC_000001.10:100:200').toMatch(REGEX_CNV_COLON)
@@ -242,6 +290,10 @@ describe.concurrent('regular expression REGEX_CNV_COLON', () => {
})
it('should match variants with invalid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL:T2T:chr1:100:200').toMatch(REGEX_CNV_COLON)
expect('DEL:T2T:chr1:100:200'.match(REGEX_CNV_COLON)?.groups).toEqual({
@@ -257,6 +309,10 @@ describe.concurrent('regular expression REGEX_CNV_COLON', () => {
describe.concurrent('regular expression REGEX_CNV_HYPEN', () => {
it('should match variants with chromosome name only', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL-chr1-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DEL-1-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DUP-chr1-100-200').toMatch(REGEX_CNV_HYPHEN)
@@ -273,6 +329,10 @@ describe.concurrent('regular expression REGEX_CNV_HYPEN', () => {
})
it('should match variants with valid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL-GRCh37-chr1-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DEL-GRCh38-1-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DUP-hg19-chr1-100-200').toMatch(REGEX_CNV_HYPHEN)
@@ -289,6 +349,10 @@ describe.concurrent('regular expression REGEX_CNV_HYPEN', () => {
})
it('should match variants with RefSeq identifiers', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL-NC_000001.10-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DEL-NC_000001.11-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DUP-NC_000001.10-100-200').toMatch(REGEX_CNV_HYPHEN)
@@ -305,6 +369,10 @@ describe.concurrent('regular expression REGEX_CNV_HYPEN', () => {
})
it('should match variants with invalid genome releases name', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('DEL-T2T-chr1-100-200').toMatch(REGEX_CNV_HYPHEN)
expect('DEL-T2T-chr1-100-200'.match(REGEX_CNV_HYPHEN)?.groups).toEqual({
@@ -320,6 +388,10 @@ describe.concurrent('regular expression REGEX_CNV_HYPEN', () => {
describe.concurrent('regular expression REGEX_CNV_ISCN_2020', () => {
it('should match valid strings', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect('arr[GRCh37] 2q12.2q13 (107132950_110427254)x1').toMatch(REGEX_CNV_ISCN_2020)
expect(
'arr[GRCh37] 2q12.2q13 (107132950_110427254)x1'.match(REGEX_CNV_ISCN_2020)?.groups
@@ -368,6 +440,7 @@ describe.concurrent('validateSequenceVariant()', () => {
['1', 249250621, 'AT'],
['1', 249250622, 'A']
])('throws on %s-%d-%s', (chrom, pos, del) => {
+ // arrange:
const variant = {
genomeBuild: 'grch37' as GenomeBuild,
chrom,
@@ -376,6 +449,10 @@ describe.concurrent('validateSequenceVariant()', () => {
ins: 'TG',
userRepr: 'TEST'
}
+
+ // act: nothing to do
+
+ // assert:
expect(() => validateSeqvar(variant)).toThrow()
})
@@ -383,6 +460,7 @@ describe.concurrent('validateSequenceVariant()', () => {
['1', 249250620, 'AT'],
['1', 249250621, 'A']
])('work on %s-%d-%s', (chrom, pos, del) => {
+ // arrange:
const variant = {
genomeBuild: 'grch37' as GenomeBuild,
chrom,
@@ -391,6 +469,10 @@ describe.concurrent('validateSequenceVariant()', () => {
ins: 'TG',
userRepr: 'TEST'
}
+
+ // act: nothing to do
+
+ // assert:
expect(validateSeqvar(variant)).toEqual(variant)
})
})
@@ -404,6 +486,10 @@ describe.concurrent('parseSeparatedSeqvar()', () => {
['m-100-at-tg', 'grch37', 'MT'],
['mt-100-at-tg', 'grch37', 'MT']
])('hyphen-separated result for %s', (variant, expectedGenomeRelease, expectedChrom) => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedSeqvar(variant)).toEqual({
genomeBuild: expectedGenomeRelease,
chrom: expectedChrom,
@@ -422,6 +508,10 @@ describe.concurrent('parseSeparatedSeqvar()', () => {
['m:100:at:tg', 'grch37', 'MT'],
['mt:100:at:tg', 'grch37', 'MT']
])('colon-separated result for %s', (variant, expectedGenomeRelease, expectedChrom) => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedSeqvar(variant)).toEqual({
genomeBuild: expectedGenomeRelease,
chrom: expectedChrom,
@@ -440,6 +530,10 @@ describe.concurrent('parseCanonicalSpdiSeqvar()', () => {
['NC_000023.10:100:AT:TG', 'grch37', 'X'],
['NC_012920.1:100:at:tg', 'grch37', 'MT']
])('result for %s', (variant, expectedGenomeRelease, expectedChrom) => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseCanonicalSpdiSeqvar(variant)).toEqual({
genomeBuild: expectedGenomeRelease,
chrom: expectedChrom,
@@ -453,6 +547,10 @@ describe.concurrent('parseCanonicalSpdiSeqvar()', () => {
describe.concurrent('parseSeparatedStrucvar()', () => {
it('parse DEL:1:100:200', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedStrucvar('DEL:1:100:200')).toEqual({
chrom: '1',
copyNumber: undefined,
@@ -465,6 +563,10 @@ describe.concurrent('parseSeparatedStrucvar()', () => {
})
it('parse DEL:GRCh37:1:100:200', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedStrucvar('DEL:1:100:200')).toEqual({
chrom: '1',
copyNumber: undefined,
@@ -477,6 +579,10 @@ describe.concurrent('parseSeparatedStrucvar()', () => {
})
it('parse DEL:NC_000001.11:100:200', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedStrucvar('DEL:NC_000001.11:100:200')).toEqual({
chrom: '1',
copyNumber: undefined,
@@ -489,6 +595,10 @@ describe.concurrent('parseSeparatedStrucvar()', () => {
})
it('parse DUP-NC_000001.11-100-200', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseSeparatedStrucvar('DUP-NC_000001.11-100-200')).toEqual({
chrom: '1',
copyNumber: undefined,
@@ -501,20 +611,36 @@ describe.concurrent('parseSeparatedStrucvar()', () => {
})
it('throws when start > stop', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(() => parseSeparatedStrucvar('DEL:NC_000001.11:200:100')).toThrow()
})
it('throws when start > length', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(() => parseSeparatedStrucvar('DEL:NC_000001.11:249250621:249250621')).toThrow()
})
it('throws when stop > length', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(() => parseSeparatedStrucvar('DEL:NC_000001.11:1:249250623')).toThrow()
})
})
describe.concurrent('parseIscnCnv', () => {
it('should match valid strings', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(parseIscnCnv('arr[GRCh37] 2q12.2q13 (107132950_110427254)x1')).toEqual({
chrom: '2',
copyNumber: 1,
@@ -574,6 +700,10 @@ describe.concurrent('parseIscnCnv', () => {
})
it('should throw on invalid positions', () => {
+ // arrange: nothing to do
+ // act: nothing to do
+
+ // assert:
expect(() => parseSeparatedStrucvar('arr[GRCh37] 2q12.2q13 (200_100)x1')).toThrow()
expect(() => parseSeparatedStrucvar('arr[GRCh37] 2q12.2q13 (243199374_243199374)x1')).toThrow()
expect(() => parseSeparatedStrucvar('arr[GRCh37] 2q12.2q13 (1_243199374)x1')).toThrow()
@@ -586,11 +716,17 @@ describe.concurrent('parseIscnCnv', () => {
describe.concurrent('SeqvarImpl', () => {
it('should work properly with toName()', () => {
+ // arrange:
const variant = new SeqvarImpl('grch37', '1', 100, 'AT', 'TG')
+
+ // act: nothing to do
+
+ // assert:
expect(variant.toName()).toEqual('grch37-1-100-AT-TG')
})
it('should be constructable with seqvarImplFromSeqvar()', () => {
+ // arrange:
const seqvar: Seqvar = {
genomeBuild: 'grch37',
chrom: '1',
@@ -600,17 +736,27 @@ describe.concurrent('SeqvarImpl', () => {
userRepr: 'TEST'
}
const variant = seqvarImplFromSeqvar(seqvar)
+
+ // act: nothing to do
+
+ // assert:
expect(variant).toEqual(seqvar)
})
})
describe.concurrent('LinearStrucvarImpl', () => {
it('should work properly with toName()', () => {
+ // arrange:
const variant = new LinearStrucvarImpl('DEL', 'grch37', '1', 100, 200, undefined, undefined)
+
+ // act: nothing to do
+
+ // assert:
expect(variant.toName()).toEqual('DEL-grch37-1-100-200')
})
it('should be constructable with seqvarImplFromSeqvar()', () => {
+ // arrange:
const strucvar: LinearStrucvar = {
svType: 'DEL',
genomeBuild: 'grch37',
@@ -620,6 +766,10 @@ describe.concurrent('LinearStrucvarImpl', () => {
userRepr: 'DEL-grch37-1-100-200'
}
const variant = linearStrucvarImplFromLinearStrucvar(strucvar)
+
+ // act: nothing to do
+
+ // assert:
expect(variant).toEqual(strucvar)
})
})
diff --git a/frontend/src/lib/__tests__/query.spec.ts b/frontend/src/lib/__tests__/query.spec.ts
index 200e1267..4607d970 100644
--- a/frontend/src/lib/__tests__/query.spec.ts
+++ b/frontend/src/lib/__tests__/query.spec.ts
@@ -24,6 +24,7 @@ describe.concurrent('Variant lookup with dotty', () => {
})
it('should return a gene', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(
JSON.stringify({
success: true,
@@ -36,13 +37,20 @@ describe.concurrent('Variant lookup with dotty', () => {
})
)
+ // act:
const result = await lookupWithDotty(seqVar.userRepr, seqVar.genomeBuild)
+
+ // assert:
expect(result).toStrictEqual(seqVar)
})
it('should throw an error if dotty fails', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({ success: false }))
+ // act: nothing to do
+
+ // assert:
await expect(lookupWithDotty(seqVar.userRepr, seqVar.genomeBuild)).rejects.toThrow()
})
})
@@ -64,6 +72,7 @@ describe.concurrent('Resolve seqvar from the given query', () => {
})
it('should return a gene', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(
JSON.stringify({
success: true,
@@ -76,7 +85,10 @@ describe.concurrent('Resolve seqvar from the given query', () => {
})
)
+ // act:
const result = await resolveSeqvar(seqVar.userRepr, seqVar.genomeBuild)
+
+ // assert:
expect(result).toStrictEqual(seqVar)
})
})
@@ -99,11 +111,15 @@ describe.concurrent('Resolve strucvar from the given query', () => {
})
it('should return a gene', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({ success: true, value: strucVar }))
+ // act:
const result = resolveStrucvar(strucVar.userRepr, strucVar.genomeBuild)
const expected = structuredClone(strucVar)
expected.userRepr = 'DEL-GRCh37-17-41176312-41277500'
+
+ // assert:
expect(result).toStrictEqual(expected)
})
})
@@ -115,6 +131,7 @@ describe.concurrent('Gene lookup', () => {
})
it('should return a gene', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(
JSON.stringify({
success: true,
@@ -135,13 +152,20 @@ describe.concurrent('Gene lookup', () => {
})
)
+ // act:
const result = await lookupGene('BRCA1')
+
+ // assert:
expect(result).toContain('BRCA1')
})
it('should throw an error if dotty fails', async () => {
+ // arrange:
fetchMocker.mockResponseOnce(JSON.stringify({ success: false }))
+ // act: nothing to do
+
+ // assert:
await expect(lookupGene('BRCA1')).rejects.toThrow()
})
})
diff --git a/frontend/src/lib/__tests__/testUtils.spec.ts b/frontend/src/lib/__tests__/testUtils.spec.ts
index 5b6bd725..87dc328a 100644
--- a/frontend/src/lib/__tests__/testUtils.spec.ts
+++ b/frontend/src/lib/__tests__/testUtils.spec.ts
@@ -2,59 +2,80 @@ import { describe, expect, it } from 'vitest'
import { setupMountedComponents } from '@/lib/testUtils'
+// Test data
const TestComponent = { template: '