Skip to content

Commit

Permalink
More typescripting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Sep 6, 2022
1 parent 464b6a5 commit 87d1761
Show file tree
Hide file tree
Showing 12 changed files with 979 additions and 849 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { fireEvent, render } 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 { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'

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

type LGV = LinearGenomeViewModel
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 @@ -23,43 +28,46 @@ const delay = { timeout: 15000 }

test('click and drag rubberBand, bookmarks region', async () => {
const pm = getPluginManager()
const state = pm.rootModel
const { findByTestId, findByText } = render(<JBrowse pluginManager={pm} />)
const rubberBandComponent = await findByTestId(
'rubberBand_controls',
{},
delay,
)
const state = pm.rootModel!
const session = state.session!
const view = session.views[0] as LGV

expect(state.session.views[0].bpPerPx).toEqual(0.05)
fireEvent.mouseDown(rubberBandComponent, { clientX: 100, clientY: 0 })
fireEvent.mouseMove(rubberBandComponent, { clientX: 250, clientY: 0 })
fireEvent.mouseUp(rubberBandComponent, { clientX: 250, clientY: 0 })
const rubberband = await findByTestId('rubberBand_controls', {}, delay)
expect(view.bpPerPx).toEqual(0.05)
fireEvent.mouseDown(rubberband, { clientX: 100, clientY: 0 })
fireEvent.mouseMove(rubberband, { clientX: 250, clientY: 0 })
fireEvent.mouseUp(rubberband, { clientX: 250, clientY: 0 })
const bookmarkMenuItem = await findByText('Bookmark region')
fireEvent.click(bookmarkMenuItem)
const { widgets } = state.session
// @ts-ignore
const { widgets } = session
const bookmarkWidget = widgets.get('GridBookmark')
expect(bookmarkWidget.bookmarkedRegions[0].assemblyName).toEqual('volvox')
}, 20000)

test('bookmarks current region', async () => {
const pm = getPluginManager()
const state = pm.rootModel
const state = pm.rootModel!
const session = state.session!
const { findByTestId, findByText } = render(<JBrowse pluginManager={pm} />)

fireEvent.click(await findByTestId('view_menu_icon'))
fireEvent.click(await findByText('Bookmark current region'))
const { widgets } = state.session
// @ts-ignore
const { widgets } = session
const { bookmarkedRegions } = widgets.get('GridBookmark')
expect(bookmarkedRegions[0].start).toEqual(100)
expect(bookmarkedRegions[0].end).toEqual(140)
}, 20000)

test('navigates to bookmarked region from widget', async () => {
const pm = getPluginManager()
const state = pm.rootModel

const { findByTestId, findByText } = render(<JBrowse pluginManager={pm} />)
const state = pm.rootModel!
const session = state.session!
const view = session.views[0] as LGV

// need this to complete before we can try to navigate
fireEvent.click(
Expand All @@ -75,17 +83,17 @@ test('navigates to bookmarked region from widget', async () => {
fireEvent.click(viewMenu)
fireEvent.click(await findByText('Open bookmark widget'))

const { widgets } = state.session
// @ts-ignore
const { widgets } = session
const bookmarkWidget = widgets.get('GridBookmark')
bookmarkWidget.addBookmark({
start: 200,
end: 240,
refName: 'ctgA',
assemblyName: 'volvox',
})
const view = state.session.views[0]

fireEvent.click(await findByText('ctgA:201..240'), {}, delay)
fireEvent.click(await findByText('ctgA:201..240', {}, delay))
const newRegion = view.getSelectedRegions(
view.leftOffset,
view.rightOffset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ setup()
beforeEach(() => {
clearCache()
clearAdapterCache()
// @ts-ignore
fetch.resetMocks()
// @ts-ignore
fetch.mockResponse(
generateReadBuffer(url => {
return new LocalFile(require.resolve(`../../test_data/breakpoint/${url}`))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, render, waitFor } from '@testing-library/react'
Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-web/src/tests/CopyAndDelete.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, render, waitFor } from '@testing-library/react'
Expand Down
1 change: 1 addition & 0 deletions products/jbrowse-web/src/tests/ReadVsRef.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { LocalFile } from 'generic-filehandle'
Expand Down
12 changes: 4 additions & 8 deletions products/jbrowse-web/src/tests/StartScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { fireEvent, render } from '@testing-library/react'
Expand Down Expand Up @@ -25,37 +26,32 @@ describe('<StartScreen />', () => {
test('Add New Session', async () => {
const pluginManager = getPluginManager()
const root = pluginManager.rootModel!
const session = root.session!
const { findByText } = render(
<StartScreen rootModel={root} onFactoryReset={factoryReset} />,
)
await findByText('Start a new session')
fireEvent.click(await findByText('Empty'))
expect(session).toBeTruthy()
expect(root.session).toBeTruthy()
})

test('Add New LGV Session', async () => {
const pluginManager = getPluginManager()
const root = pluginManager.rootModel!
const session = root.session!
const { findByText } = render(
<StartScreen rootModel={root} onFactoryReset={factoryReset} />,
)
await findByText('Start a new session')
fireEvent.click(await findByText('Linear Genome View'))
expect(session).toBeTruthy()
expect(session.views.length).toBeGreaterThan(0)
expect(root.session!.views.length).toBeGreaterThan(0)
})

test('Add New SV Inspector Session', async () => {
const pluginManager = getPluginManager()
const root = pluginManager.rootModel!
const session = root.session!
const { findByText } = render(
<StartScreen rootModel={root} onFactoryReset={factoryReset} />,
)
await findByText('Start a new session')
fireEvent.click(await findByText('Structural Variant Inspector'))
expect(session).toBeTruthy()
expect(session.views.length).toBeGreaterThan(0)
expect(root.session!.views.length).toBeGreaterThan(0)
})
Loading

0 comments on commit 87d1761

Please sign in to comment.