-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor track list in observation with maintainable architect…
…ure (#883) * chore: find associated track with test * chore: refactor TrackAccordian * chore: integrate new tracsk accordian * chore: pr review * chore: change to mts file
- Loading branch information
Showing
6 changed files
with
275 additions
and
85 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/frontend/screens/Observation/findAssociatedTrack.test.mts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {findAssociatedTrack} from './findAssociatedTrack'; | ||
import mock from '@mapeo/mock-data'; | ||
import {assert} from '../../lib/assert'; | ||
|
||
describe('Tests findAssociatedTrack', () => { | ||
it('returns the correct track with the associated observationId', () => { | ||
const [observation] = mock.generate('observation'); | ||
assert(observation); | ||
const tracks = mock.generate('track', {count: 10}); | ||
const targetTrack = tracks[3]; | ||
assert(targetTrack); | ||
targetTrack.observationRefs.push({ | ||
docId: observation.docId, | ||
versionId: observation.versionId, | ||
}); | ||
const track = findAssociatedTrack({ | ||
tracks, | ||
observationId: observation.docId, | ||
}); | ||
expect(track).toStrictEqual(targetTrack); | ||
}); | ||
|
||
it('returns undefined when there is no matching observation docId', () => { | ||
const [observation] = mock.generate('observation'); | ||
assert(observation); | ||
const tracks = mock.generate('track', {count: 10}); | ||
const track = findAssociatedTrack({ | ||
tracks, | ||
observationId: observation.docId, | ||
}); | ||
expect(track).toBeUndefined(); | ||
}); | ||
|
||
it('returns undefined when tracks array is empty', () => { | ||
const [observation] = mock.generate('observation'); | ||
assert(observation); | ||
const track = findAssociatedTrack({ | ||
tracks: [], | ||
observationId: observation.docId, | ||
}); | ||
expect(track).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {type Track} from '@comapeo/schema'; | ||
|
||
export function findAssociatedTrack({ | ||
tracks, | ||
observationId, | ||
}: { | ||
tracks: Track[]; | ||
observationId: string; | ||
}) { | ||
return tracks.find(trackData => | ||
trackData.observationRefs.some(ref => ref.docId === observationId), | ||
); | ||
} |
Oops, something went wrong.