Skip to content

Commit

Permalink
mock api in genotypesview component
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-ebi committed Feb 10, 2023
1 parent 9d160ff commit 54d8ed2
Show file tree
Hide file tree
Showing 7 changed files with 2,676 additions and 113 deletions.
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@babel/preset-react": "^7.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^12.1.5",
"@testing-library/user-event": "^14.4.3",
"babel-loader": "^8.0.2",
"css-loader": "^6.7.3",
"jest": "^29.4.1",
Expand Down
37 changes: 25 additions & 12 deletions src/mocks/handlers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { rest } from 'msw'
import {rest} from 'msw'
import { genotypes_view_test_consequences_data, genotypes_view_test_species_data, genotypes_view_test_studies_data,
genotypes_view_test_variants_data } from "../test/test_data/GenotypesTableData"

export const handlers = [
rest.post('/login', (req, res, ctx) => {
const { username } = req.body
rest.get('https://rest.ensembl.org/info/variation/consequence_types', (req, res, ctx) => {
return res(
ctx.json(genotypes_view_test_consequences_data),
)
}),

return res(
ctx.json({
id: 'f79e82e8-c34a-4dc7-a49e-9fadc0979fda',
username,
firstName: 'John',
lastName: 'Maverick',
}),
)
}),
rest.get('https://www.ebi.ac.uk/eva/webservices/rest/v1/meta/species/list', (req, res, ctx) => {
return res(
ctx.json(genotypes_view_test_species_data),
)
}),

rest.get('https://www.ebi.ac.uk/eva/webservices/rest/v1/meta/studies/list', (req, res, ctx) => {
return res(
ctx.json(genotypes_view_test_studies_data),
)
}),

rest.get('https://www.ebi.ac.uk/eva/webservices/rest/v1/segments/1:3000000-3100000/variants', (req, res, ctx) => {
return res(
ctx.json(genotypes_view_test_variants_data),
)
})
]
9 changes: 0 additions & 9 deletions src/test/GenotypeView.test.js

This file was deleted.

21 changes: 21 additions & 0 deletions src/test/GenotypesView.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react'

import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import GenotypeView from "../GenotypeView"

test('check genotype view component is loading everything correctly', () => {
render(<GenotypeView>{}</GenotypeView>)

const combo_boxes = screen.getAllByRole('combobox')
expect(combo_boxes[0].name).toBe("species")
expect(combo_boxes[1].name).toBe("assembly")
expect(combo_boxes[2].name).toBe("resultsPerPage")

expect(screen.getByRole('textbox').value).toBe('1:3000000-3100000')

expect(screen.getByRole('option', {name: '50'}).selected).toBe(true)
expect(screen.getByRole('option', {name: '10'}).selected).toBe(false)
expect(screen.getByRole('option', {name: '100'}).selected).toBe(false)

})
91 changes: 0 additions & 91 deletions src/test/test_data/GenotypesTableData.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,97 +669,6 @@ export const genotypes_table_test_data = {
"end": 3013263,
"reference": "T",
"alternate": "C",
"hgvs": {
"genomic": [
"1:g.3013263T>C"
]
},
"sourceEntries": {
"PRJEB9799_ERZ780739": {
"fileId": "ERZ780739",
"studyId": "PRJEB9799",
"format": "GT:AD:DP:GQ:PL",
"cohortStats": {
"ALL": {
"refAllele": "T",
"altAllele": "C",
"variantType": "SNV",
"refAlleleCount": 0,
"altAlleleCount": 0,
"missingAlleles": 0,
"missingGenotypes": 0,
"refAlleleFreq": 0,
"altAlleleFreq": 0,
"maf": 0.16666667,
"mgf": 0,
"mafAllele": "T",
"mgfGenotype": "0/0",
"numSamples": 0,
"transition": true,
"transversion": false
}
},
"attributes": {
"AC": "10",
"MQRankSum": "2.893",
"FILTER": "PASS",
"set": "variant",
"MQ": "8080",
"AF": "0.833",
"src": "chr1\t3013263\t.\tT\tC\t837.14\tPASS\tAC=10;AF=0.833;AN=12;BaseQRankSum=3.214;ClippingRankSum=-4.466;DP=60;FS=0.000;MLEAC=10;MLEAF=0.833;MQ=55.49;MQ0=0;MQRankSum=2.893;QD=13.95;ReadPosRankSum=-1.199;VQSLOD=1.73;culprit=FS;set=variant",
"MLEAC": "10",
"QUAL": "837.14",
"BaseQRankSum": "3.214",
"MLEAF": "0.833",
"DP": "59",
"ReadPosRankSum": "-1.199",
"AN": "12",
"FS": "0.000",
"MQ0": "0",
"culprit": "FS",
"QD": "13.95",
"VQSLOD": "1.73",
"ClippingRankSum": "-4.466"
},
"samplesData": {
"CH": {
"GT": "1/1"
},
"MM": {
"GT": "0/1"
},
"AMH": {
"GT": "1/1"
},
"PER": {
"GT": "1/1"
},
"ARB": {
"GT": "1/1"
},
"TWH": {
"GT": "0/1"
}
}
}
},
"annotation": {
"chromosome": "1",
"start": 3013263,
"end": 3013263,
"vepVersion": "89",
"vepCacheVersion": "89",
"consequenceTypes": [
{
"soTerms": [
{
"soName": "intergenic_variant",
"soAccession": "SO:0001628"
}
]
}
]
},
"length": 1,
"type": "SNV",
"alleleFreqs": {
Expand Down
Loading

0 comments on commit 54d8ed2

Please sign in to comment.