Commit 1f0b9525 authored by Tom Quirk's avatar Tom Quirk

Rename parseDesignRouteHash function

Rename it to extractDesignNoteId
parent dc510fbf
......@@ -20,7 +20,7 @@ import {
extractDesign,
updateImageDiffNoteOptimisticResponse,
toDiffNoteGid,
parseDesignRouteHash,
extractDesignNoteId,
} from '../../utils/design_management_utils';
import {
updateStoreAfterAddImageDiffNote,
......@@ -281,7 +281,7 @@ export default {
});
},
updateActiveDiscussionFromUrl() {
const noteId = parseDesignRouteHash(this.$route.hash);
const noteId = extractDesignNoteId(this.$route.hash);
const diffNoteGid = noteId ? toDiffNoteGid(noteId) : undefined;
return this.updateActiveDiscussion(diffNoteGid, ACTIVE_DISCUSSION_SOURCE_TYPES.url);
},
......
......@@ -38,11 +38,11 @@ export const toDiffNoteGid = noteId => `gid://gitlab/DiffNote/${noteId}`;
/**
* Return the note ID from a URL hash parameter
* @param {String} hash URL hash
* @param {String} urlHash URL hash, including `#` prefix
*/
export const parseDesignRouteHash = hash => {
const [, noteId] = hash.match('#note_([0-9]+$)') || [];
return noteId;
export const extractDesignNoteId = urlHash => {
const [, noteId] = urlHash.match('#note_([0-9]+$)') || [];
return noteId || null;
};
/**
......
......@@ -6,7 +6,7 @@ import {
updateImageDiffNoteOptimisticResponse,
isValidDesignFile,
extractDesign,
parseDesignRouteHash,
extractDesignNoteId,
} from '~/design_management/utils/design_management_utils';
import mockResponseNoDesigns from '../mock_data/no_designs';
import mockResponseWithDesigns from '../mock_data/designs';
......@@ -173,18 +173,18 @@ describe('extractDesign', () => {
});
});
describe('parseDesignRouteHash', () => {
describe('extractDesignNoteId', () => {
it.each`
hash | expectedNoteId
${'#note_0'} | ${'0'}
${'#note_1'} | ${'1'}
${'#note_23'} | ${'23'}
${'#note_456'} | ${'456'}
${'note_1'} | ${undefined}
${'#note_'} | ${undefined}
${'#note_asd'} | ${undefined}
${'#note_1asd'} | ${undefined}
${'note_1'} | ${null}
${'#note_'} | ${null}
${'#note_asd'} | ${null}
${'#note_1asd'} | ${null}
`('returns $expectedNoteId when hash is $hash', ({ hash, expectedNoteId }) => {
expect(parseDesignRouteHash(hash)).toBe(expectedNoteId);
expect(extractDesignNoteId(hash)).toBe(expectedNoteId);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment