Skip to content

Commit

Permalink
More typescripting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 7, 2022
1 parent b031e6e commit b98f59a
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 99 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import { fireEvent, waitFor } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { TextEncoder, TextDecoder } from 'web-encoding'

import { JBrowse, setup, getPluginManager, generateReadBuffer } from './util'
import { createView, setup, generateReadBuffer } from './util'

window.TextEncoder = TextEncoder
window.TextDecoder = TextDecoder

expect.extend({ toMatchImageSnapshot })

setup()

beforeEach(() => {
clearCache()
clearAdapterCache()
// @ts-ignore
fetch.resetMocks()
// @ts-ignore
fetch.mockResponse(
generateReadBuffer(
url => new LocalFile(require.resolve(`../../test_data/volvox/${url}`)),
Expand All @@ -30,10 +28,7 @@ beforeEach(() => {
const delay = { timeout: 10000 }

test('opens a vcf.gz file in the spreadsheet view', async () => {
const pluginManager = getPluginManager()
const { findByTestId, getByTestId, findByText } = render(
<JBrowse pluginManager={pluginManager} />,
)
const { session, findByTestId, getByTestId, findByText } = createView()
fireEvent.click(await findByText('File'))
fireEvent.click(await findByText('Add'))
fireEvent.click(await findByText('Spreadsheet view'))
Expand All @@ -48,14 +43,11 @@ test('opens a vcf.gz file in the spreadsheet view', async () => {
).not.toBeDisabled(),
)
fireEvent.click(await findByTestId('open_spreadsheet'))
expect(pluginManager.rootModel.session.views.length).toBe(2)
expect(session.views.length).toBe(2)
}, 15000)

test('opens a bed.gz file in the spreadsheet view', async () => {
const pluginManager = getPluginManager()
const { findByTestId, getByTestId, findByText } = render(
<JBrowse pluginManager={pluginManager} />,
)
const { findByTestId, session, getByTestId, findByText } = createView()
fireEvent.click(await findByText('File'))
fireEvent.click(await findByText('Add'))
fireEvent.click(await findByText('Spreadsheet view'))
Expand All @@ -70,5 +62,5 @@ test('opens a bed.gz file in the spreadsheet view', async () => {
).not.toBeDisabled(),
)
fireEvent.click(await findByTestId('open_spreadsheet'))
expect(pluginManager.rootModel.session.views.length).toBe(2)
expect(session.views.length).toBe(2)
}, 15000)
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import { fireEvent, waitFor } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { TextEncoder, TextDecoder } from 'web-encoding'

import { JBrowse, setup, getPluginManager, generateReadBuffer } from './util'
import { setup, createView, generateReadBuffer } from './util'

window.TextEncoder = TextEncoder
window.TextDecoder = TextDecoder

expect.extend({ toMatchImageSnapshot })

setup()

beforeEach(() => {
clearCache()
clearAdapterCache()
// @ts-ignore
fetch.resetMocks()
// @ts-ignore
fetch.mockResponse(
generateReadBuffer(url => {
return new LocalFile(require.resolve(`../../test_data/volvox/${url}`))
Expand All @@ -31,13 +29,8 @@ const delay = { timeout: 20000 }

test('opens a vcf.gz file in the sv inspector view', async () => {
console.warn = jest.fn()
const pluginManager = getPluginManager()
const { findByTestId, getByTestId, findByText } = render(
<JBrowse pluginManager={pluginManager} />,
)
const {
rootModel: { session },
} = pluginManager
const { session, findByTestId, getByTestId, findByText } = createView()

fireEvent.click(await findByText('File'))
fireEvent.click(await findByText('Add'))
fireEvent.click(await findByText('SV inspector'))
Expand Down
2 changes: 0 additions & 2 deletions products/jbrowse-web/src/tests/Alignments.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LocalFile } from 'generic-filehandle'
// locals
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import {
setup,
expectCanvasMatch,
Expand All @@ -14,7 +13,6 @@ import {
pc,
} from './util'

expect.extend({ toMatchImageSnapshot })
setup()

beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions products/jbrowse-web/src/tests/AlignmentsFeatures.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LocalFile } from 'generic-filehandle'
// locals
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import {
setup,
expectCanvasMatch,
Expand All @@ -14,7 +13,6 @@ import {
hts,
} from './util'

expect.extend({ toMatchImageSnapshot })
setup()

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import React from 'react'
import { fireEvent, render, waitFor, within } from '@testing-library/react'
import { fireEvent, waitFor, within } from '@testing-library/react'
import { LocalFile, RemoteFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import crypto from 'crypto'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import config from '../../test_data/volvox/config.json'
import {
JBrowse,
setup,
createView,
expectCanvasMatch,
generateReadBuffer,
getPluginManager,
} from './util'

expect.extend({ toMatchImageSnapshot })
setup()

// @ts-ignore
global.crypto = { getRandomValues: crypto.randomFillSync }

beforeEach(() => {
clearCache()
clearAdapterCache()
sessionStorage.clear()
// @ts-ignore
fetch.resetMocks()
// @ts-ignore
fetch.mockResponse(
generateReadBuffer(
url => new LocalFile(require.resolve(`../../test_data/volvox/${url}`)),
Expand All @@ -34,7 +32,7 @@ beforeEach(() => {
const delay = { timeout: 20000 }

test('open a bigwig track that needs oauth authentication and has existing token', async () => {
const pm = getPluginManager({
const { state, view, findByTestId, findByText } = createView({
...config,
tracks: [
{
Expand All @@ -54,17 +52,18 @@ test('open a bigwig track that needs oauth authentication and has existing token
},
],
})
const state = pm.rootModel
const { findByTestId, findByText } = render(<JBrowse pluginManager={pm} />)
const token = '1234'
sessionStorage.setItem('dropboxOAuth-token', token)
// @ts-ignore
await waitFor(() => expect(state.internetAccounts.length).toBe(2))
// @ts-ignore
state.internetAccounts[0].validateToken = jest.fn().mockReturnValue(token)
// @ts-ignore
state.internetAccounts[0].openLocation = jest
.fn()
.mockReturnValue(new RemoteFile('volvox_microarray_dropbox.bw'))
await findByText('Help')
state.session.views[0].setNewView(5, 0)
view.setNewView(5, 0)
fireEvent.click(
await findByTestId('htsTrackEntry-volvox_microarray_dropbox', {}, delay),
)
Expand All @@ -78,7 +77,7 @@ test('open a bigwig track that needs oauth authentication and has existing token
}, 25000)

test('opens a bigwig track that needs external token authentication', async () => {
const pm = getPluginManager({
const { view, findByTestId } = createView({
...config,
internetAccounts: [
{
Expand Down Expand Up @@ -107,9 +106,7 @@ test('opens a bigwig track that needs external token authentication', async () =
},
],
})
const state = pm.rootModel
const { findByTestId } = render(<JBrowse pluginManager={pm} />)
state.session.views[0].setNewView(5, 0)
view.setNewView(5, 0)
fireEvent.click(
await findByTestId(
'htsTrackEntry-volvox_microarray_externaltoken',
Expand Down Expand Up @@ -138,7 +135,7 @@ test('opens a bigwig track that needs external token authentication', async () =
}, 25000)

test('opens a bigwig track that needs httpbasic authentication', async () => {
const pm = getPluginManager({
const { view, findByTestId, findByText } = createView({
...config,
tracks: [
{
Expand All @@ -158,9 +155,7 @@ test('opens a bigwig track that needs httpbasic authentication', async () => {
},
],
})
const state = pm.rootModel
const { findByTestId, findByText } = render(<JBrowse pluginManager={pm} />)
state.session.views[0].setNewView(5, 0)
view.setNewView(5, 0)
fireEvent.click(
await findByTestId('htsTrackEntry-volvox_microarray_httpbasic', {}, delay),
)
Expand Down
2 changes: 0 additions & 2 deletions products/jbrowse-web/src/tests/BigWig.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { fireEvent } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { toMatchImageSnapshot } from 'jest-image-snapshot'

import {
setup,
Expand All @@ -13,7 +12,6 @@ import {
hts,
} from './util'

expect.extend({ toMatchImageSnapshot })
setup()

beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions products/jbrowse-web/src/tests/BookmarkWidget.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { fireEvent } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { waitFor } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, waitFor } from '@testing-library/react'
Expand Down
17 changes: 4 additions & 13 deletions products/jbrowse-web/src/tests/Dotplot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { fireEvent } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import { TextEncoder, TextDecoder } from 'web-encoding'
import path from 'path'
import dotplotConfig from '../../test_data/config_dotplot.json'
Expand All @@ -19,18 +18,9 @@ if (!window.TextEncoder) {
if (!window.TextDecoder) {
window.TextDecoder = TextDecoder
}
const config = {
...dotplotConfig,
configuration: {
rpc: {
defaultDriver: 'MainThreadRpcDriver',
},
},
}

const delay = { timeout: 25000 }

expect.extend({ toMatchImageSnapshot })
setup()

beforeEach(() => {
Expand All @@ -48,12 +38,13 @@ beforeEach(() => {
})

test('open a dotplot view', async () => {
const { findByTestId } = createView(config)
const { findByTestId } = createView(dotplotConfig)
expectCanvasMatch(await findByTestId('prerendered_canvas_done', {}, delay))
}, 20000)

test('open a dotplot view with import form', async () => {
const { findByTestId, findAllByTestId, findByText } = createView(config)
const { findByTestId, findAllByTestId, findByText } =
createView(dotplotConfig)

fireEvent.click(await findByTestId('close_view'))
fireEvent.click(await findByText('File'))
Expand All @@ -67,7 +58,7 @@ test('open a dotplot view with import form', async () => {
})
fireEvent.change(await findByTestId('urlInput', {}, delay), {
target: {
value: 'peach_grape_small.paf',
value: 'peach_grape_small.paf.gz',
},
})
fireEvent.click(await findByTestId('submitDotplot'))
Expand Down
1 change: 0 additions & 1 deletion products/jbrowse-web/src/tests/ErrorConditions.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { render } from '@testing-library/react'
import { ErrorBoundary } from 'react-error-boundary'
Expand Down
2 changes: 0 additions & 2 deletions products/jbrowse-web/src/tests/ExportSvg.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { fireEvent, waitFor } from '@testing-library/react'
import { TextEncoder } from 'web-encoding'
import { LocalFile } from 'generic-filehandle'
Expand Down
12 changes: 2 additions & 10 deletions products/jbrowse-web/src/tests/Hic.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fireEvent } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
import { toMatchImageSnapshot } from 'jest-image-snapshot'

import {
setup,
Expand All @@ -12,7 +11,6 @@ import {
} from './util'
import hicConfig from '../../../../extra_test_data/hic_integration_test.json'

expect.extend({ toMatchImageSnapshot })
setup()

const delay = { timeout: 20000 }
Expand All @@ -28,14 +26,8 @@ test('hic', async () => {
),
)

const { view, findByTestId } = createView({
...hicConfig,
configuration: {
rpc: {
defaultDriver: 'MainThreadRpcDriver',
},
},
})
const { view, findByTestId } = createView(hicConfig)

view.setNewView(5000, 0)
fireEvent.click(await findByTestId(hts('hic_test'), {}, delay))
expectCanvasMatch(await findByTestId(pc('{hg19}1:1..4,000,000-0'), {}, delay))
Expand Down
4 changes: 0 additions & 4 deletions products/jbrowse-web/src/tests/ReadVsRef.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { fireEvent, waitFor } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'

// locals
import { clearCache } from '@jbrowse/core/util/io/RemoteFileWithRangeCache'
import { clearAdapterCache } from '@jbrowse/core/data_adapters/dataAdapterCache'
import { toMatchImageSnapshot } from 'jest-image-snapshot'
import {
setup,
createView,
expectCanvasMatch,
generateReadBuffer,
} from './util'

expect.extend({ toMatchImageSnapshot })
setup()

beforeEach(() => {
Expand Down
Loading

0 comments on commit b98f59a

Please sign in to comment.