|
| 1 | +import React from 'react'; |
| 2 | +import { mount } from 'enzyme'; |
| 3 | +import { mocked } from 'ts-jest/utils'; |
| 4 | +import { jest, beforeEach, describe, expect, test } from '@jest/globals'; |
| 5 | + |
| 6 | +import { Ajax, Utils, ActionURL} from '@labkey/api'; |
| 7 | +import View from "./Browser" |
| 8 | + |
| 9 | +const mockData = |
| 10 | +{ |
| 11 | + "configuration": {}, |
| 12 | + "assemblies": |
| 13 | + { |
| 14 | + "name": "hg38", |
| 15 | + "aliases": ["GRCh38"], |
| 16 | + "sequence": { |
| 17 | + "type": "ReferenceSequenceTrack", |
| 18 | + "trackId": "P6R5xbRqRr", |
| 19 | + "adapter": { |
| 20 | + "type": "BgzipFastaAdapter", |
| 21 | + "fastaLocation": { |
| 22 | + "uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz" |
| 23 | + }, |
| 24 | + "faiLocation": { |
| 25 | + "uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.fai" |
| 26 | + }, |
| 27 | + "gziLocation": { |
| 28 | + "uri": "https://jbrowse.org/genomes/GRCh38/fasta/hg38.prefix.fa.gz.gzi" |
| 29 | + } |
| 30 | + } |
| 31 | + }, |
| 32 | + "refNameAliases": { |
| 33 | + "adapter": { |
| 34 | + "type": "RefNameAliasAdapter", |
| 35 | + "location": { |
| 36 | + "uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/hg38_aliases.txt" |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + }, |
| 41 | + "tracks": [ |
| 42 | + { |
| 43 | + "type": "VariantTrack", |
| 44 | + "trackId": "clinvar_ncbi_hg38", |
| 45 | + "name": "ClinVar variants (NCBI)", |
| 46 | + "assemblyNames": ["hg38"], |
| 47 | + "category": ["Annotation"], |
| 48 | + "adapter": { |
| 49 | + "type": "VcfTabixAdapter", |
| 50 | + "vcfGzLocation": { |
| 51 | + "uri": "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh38/clinvar.vcf.gz" |
| 52 | + }, |
| 53 | + "index": { |
| 54 | + "location": { |
| 55 | + "uri": "https://ftp.ncbi.nlm.nih.gov/pub/clinvar/vcf_GRCh38/clinvar.vcf.gz.tbi" |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + { |
| 61 | + "type": "FeatureTrack", |
| 62 | + "trackId": "ncbi_refseq_109_hg38_latest", |
| 63 | + "name": "NCBI RefSeq (GFF3Tabix)", |
| 64 | + "assemblyNames": ["hg38"], |
| 65 | + "category": ["Annotation"], |
| 66 | + "adapter": { |
| 67 | + "type": "Gff3TabixAdapter", |
| 68 | + "gffGzLocation": { |
| 69 | + "uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz" |
| 70 | + }, |
| 71 | + "index": { |
| 72 | + "location": { |
| 73 | + "uri": "https://s3.amazonaws.com/jbrowse.org/genomes/GRCh38/ncbi_refseq/GRCh38_latest_genomic.sort.gff.gz.tbi" |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + ], |
| 79 | + "connections": [] |
| 80 | +} |
| 81 | + |
| 82 | +jest.mock('@labkey/api', () => { |
| 83 | + return { |
| 84 | + Ajax: { |
| 85 | + request: jest.fn() |
| 86 | + }, |
| 87 | + ActionURL: { |
| 88 | + buildURL: jest.fn() |
| 89 | + } |
| 90 | + } |
| 91 | +}) |
| 92 | +const mockedRequest = mocked(Ajax, true) |
| 93 | + |
| 94 | +describe('JBrowse 2 Browser', () => { |
| 95 | + |
| 96 | + |
| 97 | + test('Renders error string if no config provided', async () => { |
| 98 | + |
| 99 | + const wrapper = mount(<View />); |
| 100 | + expect(wrapper.contains(<p>Error - no session provided.</p>)).toEqual(true); |
| 101 | + }); |
| 102 | + |
| 103 | + |
| 104 | + test('Renders browser if config provided', async () => { |
| 105 | + jest.spyOn(URLSearchParams.prototype, "get").mockImplementation(() => "demo") // in theory this should set session to "demo" when queryParam.get is called. |
| 106 | + |
| 107 | + mockedRequest.request.mockReset(); |
| 108 | + mockedRequest.request.mockImplementation(({ success }) => { |
| 109 | + success({ response: JSON.stringify(mockData) } as XMLHttpRequest, null); |
| 110 | + return {} as XMLHttpRequest; |
| 111 | + }); |
| 112 | + const wrapper = mount(<View />); |
| 113 | + expect(wrapper.find('.MuiPaper-root')).toHaveLength(2) |
| 114 | + }); |
| 115 | + |
| 116 | +}); |
0 commit comments