From 01f778cebb92fa3a13cc3be281ad226c4d3d3e54 Mon Sep 17 00:00:00 2001 From: Wils Dawson Date: Wed, 22 Dec 2021 10:28:25 -0800 Subject: [PATCH] Cleanup extra 'v' in version of the document card (#4319) * Cleanup extra 'v' in version of the document card * adds tests Co-authored-by: Dimitri Mitropoulos --- .../__tests__/workspace-card.test.ts | 20 ++++++++++ .../app/ui/components/workspace-card.tsx | 38 +++++++++++-------- 2 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 packages/insomnia-app/app/ui/components/__tests__/workspace-card.test.ts diff --git a/packages/insomnia-app/app/ui/components/__tests__/workspace-card.test.ts b/packages/insomnia-app/app/ui/components/__tests__/workspace-card.test.ts new file mode 100644 index 000000000..cc21f896a --- /dev/null +++ b/packages/insomnia-app/app/ui/components/__tests__/workspace-card.test.ts @@ -0,0 +1,20 @@ +import { getVersionDisplayment } from '../workspace-card'; + +describe('getVersionDisplayment', () => { + it('returns falsey values as-is', () => { + expect(getVersionDisplayment(undefined)).toEqual(undefined); + expect(getVersionDisplayment(null)).toEqual(null); + expect(getVersionDisplayment('')).toEqual(''); + }); + + it('does not add a `v` if the string starts with one', () => { + expect(getVersionDisplayment('v1')).toEqual('v1'); + expect(getVersionDisplayment('victor')).toEqual('victor'); + }); + + it("adds a `v` to all strings that don't start with a v", () => { + expect(getVersionDisplayment('1')).toEqual('v1'); + expect(getVersionDisplayment('1.0.0')).toEqual('v1.0.0'); + expect(getVersionDisplayment('alpha1')).toEqual('valpha1'); // yes, we know this is non-ideal, see INS-1320. + }); +}); diff --git a/packages/insomnia-app/app/ui/components/workspace-card.tsx b/packages/insomnia-app/app/ui/components/workspace-card.tsx index abd11c31b..b32a14b89 100644 --- a/packages/insomnia-app/app/ui/components/workspace-card.tsx +++ b/packages/insomnia-app/app/ui/components/workspace-card.tsx @@ -33,6 +33,18 @@ export interface WorkspaceCardProps { onSelect: (workspaceId: string, activity: GlobalActivity) => void; } +export const getVersionDisplayment = (version?: string | null) => { + if (!version) { + return version; + } + + if (!version.startsWith('v')) { + return `v${version}`; + } + + return version; +}; + export const WorkspaceCard: FC = ({ apiSpec, filter, @@ -85,7 +97,7 @@ export const WorkspaceCard: FC = ({ /> ); - const version = spec?.info?.version || ''; + const version = getVersionDisplayment(spec?.info?.version); let label: string = strings.collection.singular; let format = ''; let labelIcon = ; @@ -108,7 +120,7 @@ export const WorkspaceCard: FC = ({ } // Filter the card by multiple different properties - const matchResults = fuzzyMatchAll(filter, [title, label, branch, version], { + const matchResults = fuzzyMatchAll(filter, [title, label, branch || '', version || ''], { splitSpace: true, loose: true, }); @@ -120,21 +132,15 @@ export const WorkspaceCard: FC = ({ return ( : undefined - } + docBranch={branch ? : undefined} docTitle={title ? : undefined} - docVersion={ - version ? : undefined - } - tagLabel={ - label ? ( - <> - {labelIcon} - - - ) : undefined - } + docVersion={version ? : undefined} + tagLabel={label ? ( + <> + {labelIcon} + + + ) : undefined} docLog={log} docMenu={docMenu} docFormat={format}