Skip to content

Commit

Permalink
Change sequences test to expect uuid ins..
Browse files Browse the repository at this point in the history
..tead of undefined id for first v3 sequence
- Add checkes in getSequences selector before setting id for first v3 sequence which has undefined id initially
  • Loading branch information
System Administrator authored and System Administrator committed Nov 10, 2020
1 parent 4d03374 commit 2f0fdb5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion __tests__/src/selectors/sequences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
getSequenceBehaviors,
} from '../../../src/state/selectors/sequences';

jest.mock('uuid', () => ({ v4: () => '00000000-0000-0000-0000-000000000000' }));

describe('getSequences', () => {
describe('with a v2 manifest', () => {
const state = { manifests: { x: { json: manifestFixtureGau } } };
Expand Down Expand Up @@ -49,7 +51,7 @@ describe('getSequences', () => {
const state = { manifests: { x: { json: manifest } } };
const sequences = getSequences(state, { manifestId: 'x' });
expect(sequences.length).toEqual(3);
expect(sequences.map(s => s.id)).toEqual([undefined, 'a', 'b']);
expect(sequences.map(s => s.id)).toEqual(['00000000-0000-0000-0000-000000000000', 'a', 'b']);
});
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.53",
"@researchgate/react-intersection-observer": "^1.0.0",
"canvas": "^2.6.1",
"classnames": "^2.2.6",
"clsx": "^1.0.4",
"deepmerge": "^4.2.2",
Expand Down
3 changes: 2 additions & 1 deletion src/state/selectors/sequences.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const getSequences = createSelector(

// v3 sequence (not range sequence): assign id if not there
const manifestSequences = manifest.getSequences();
if (v3RangeSequences && !manifestSequences[0].id) {
if (v3RangeSequences && manifestSequences && manifestSequences.length > 0
&& !manifestSequences[0].id) {
manifestSequences[0].id = uuid();
}

Expand Down

0 comments on commit 2f0fdb5

Please sign in to comment.