Skip to content

Commit 5b56fb8

Browse files
authored
Fix opening temporaryAssemblies sequence tracks (#5393)
1 parent f8432b4 commit 5b56fb8

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

packages/product-core/src/Session/Tracks.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@ export function TracksManagerSessionMixin(pluginManager: PluginManager) {
3131
return self.jbrowse.tracks
3232
},
3333

34+
/**
35+
* #getter
36+
* Base assemblies from jbrowse config. Child sessions can override
37+
* to include additional assemblies (e.g. sessionAssemblies).
38+
*/
39+
get assemblies(): { sequence: { trackId: string } }[] {
40+
return self.jbrowse.assemblies
41+
},
42+
3443
/**
3544
* #getter
3645
*/
3746
get tracksById(): Record<string, AnyConfigurationModel> {
47+
const temporaryAssemblies =
48+
'temporaryAssemblies' in self
49+
? (self.temporaryAssemblies as { sequence: { trackId: string } }[])
50+
: []
51+
3852
return Object.fromEntries([
3953
...this.tracks.map(t => [t.trackId, t]),
4054
// Include assembly sequence tracks so they can be resolved by trackId
41-
...self.jbrowse.assemblies.map(
42-
(a: { sequence: { trackId: string } }) => [
43-
a.sequence.trackId,
44-
a.sequence,
45-
],
46-
),
55+
...this.assemblies.map(a => [a.sequence.trackId, a.sequence]),
56+
// Include temporary assembly sequence tracks
57+
...temporaryAssemblies.map(a => [a.sequence.trackId, a.sequence]),
4758
])
4859
},
4960
}))

packages/web-core/src/BaseWebSession/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,6 @@ export function BaseWebSession({
126126
task: undefined,
127127
}))
128128
.views(self => ({
129-
/**
130-
* #getter
131-
*/
132-
get tracksById(): Record<string, AnyConfigurationModel> {
133-
return Object.fromEntries([
134-
...this.tracks.map(t => [t.trackId, t]),
135-
...this.assemblies.map(a => [a.sequence.trackId, a.sequence]),
136-
])
137-
},
138129
/**
139130
* #getter
140131
*/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { fireEvent, waitFor } from '@testing-library/react'
2+
3+
import { createView, doBeforeEach, hts, setup } from './util.tsx'
4+
5+
setup()
6+
7+
beforeEach(() => {
8+
doBeforeEach()
9+
})
10+
11+
const delay = { timeout: 10000 }
12+
const opts = [{}, delay]
13+
14+
test('add temporary assembly and toggle reference sequence track', async () => {
15+
const { session, view, findByTestId, findAllByText } = await createView()
16+
17+
// Wait for initial view to load
18+
await findAllByText('ctgA', ...opts)
19+
20+
const testAssemblyName = 'testProtein'
21+
const refSeqTrackId = `${testAssemblyName}-ReferenceSequenceTrack`
22+
23+
// Add a temporary assembly programmatically
24+
session.addTemporaryAssembly?.({
25+
name: testAssemblyName,
26+
sequence: {
27+
type: 'ReferenceSequenceTrack',
28+
trackId: refSeqTrackId,
29+
adapter: {
30+
type: 'FromConfigSequenceAdapter',
31+
features: [
32+
{
33+
refName: testAssemblyName,
34+
uniqueId: 'test-seq-1',
35+
start: 0,
36+
end: 100,
37+
seq: 'MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSH',
38+
},
39+
],
40+
},
41+
},
42+
})
43+
44+
// Verify the assembly was added
45+
expect(session.temporaryAssemblies?.length).toBeGreaterThan(0)
46+
47+
// Clear the current view and navigate to the new assembly
48+
view.clearView()
49+
50+
// Try to navigate to the new assembly
51+
await view.navToLocString(testAssemblyName, testAssemblyName)
52+
53+
// Now try to toggle the reference sequence track via UI
54+
// The track selector should show the reference sequence track for this assembly
55+
const trackEntry = await findByTestId(hts(refSeqTrackId), ...opts)
56+
fireEvent.click(trackEntry)
57+
58+
// Wait for the track to be added
59+
await waitFor(
60+
() => {
61+
expect(view.tracks.length).toBe(1)
62+
},
63+
{ timeout: 10000 },
64+
)
65+
66+
// Verify the track was added successfully
67+
expect(view.tracks[0]?.configuration.trackId).toBe(refSeqTrackId)
68+
}, 60000)

0 commit comments

Comments
 (0)