Skip to content

Commit

Permalink
fix(about): be more lenient about build version format (#1524)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Jan 9, 2025
1 parent ddf3500 commit d63322c
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/app/About/AboutDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { Text, TextContent, TextList, TextListItem, TextVariants } from '@patter
import * as React from 'react';
import { useTranslation } from 'react-i18next';

export const VERSION_REGEX = /^(v?[0-9]+\.[0-9]+\.[0-9]+)(?:-(.+))?$/;

export const AboutDescription: React.FC = () => {
const serviceContext = React.useContext(ServiceContext);
const notificationsContext = React.useContext(NotificationsContext);
Expand All @@ -40,16 +42,15 @@ export const AboutDescription: React.FC = () => {
if (!cryostatVersion) {
return;
}
const expr = /^(v[0-9]+\.[0-9]+\.[0-9]+)(?:-snapshot)?$/;
const result = cryostatVersion.match(expr);
const result = cryostatVersion.match(VERSION_REGEX);
if (!result) {
notificationsContext.warning(
'Cryostat version parse failure',
`Could not parse Cryostat version string '${cryostatVersion}'.`,
);
return;
}
return result.groups?.tag;
return result[1];
}, [cryostatVersion, notificationsContext]);

const versionComponent = React.useMemo(() => {
Expand Down
89 changes: 89 additions & 0 deletions src/test/About/AboutDescription.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright The Cryostat Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AboutDescription, VERSION_REGEX } from '@app/About/AboutDescription';
import { ThemeSetting } from '@app/Settings/types';
import { defaultServices } from '@app/Shared/Services/Services';
import { cleanup, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { of } from 'rxjs';
import { mockMediaQueryList, render, renderSnapshot } from '../utils';

jest.spyOn(defaultServices.settings, 'themeSetting').mockReturnValue(of(ThemeSetting.DARK));
jest.spyOn(defaultServices.settings, 'media').mockReturnValue(of(mockMediaQueryList));

const versionString = 'v1.2.3-snapshot';
jest.spyOn(defaultServices.api, 'cryostatVersion').mockReturnValue(of(versionString));
const commitHash = 'abcd1234';
jest.spyOn(defaultServices.api, 'buildInfo').mockReturnValue(of({ git: { hash: commitHash } }));

describe('<AboutDescription />', () => {
afterEach(cleanup);

it('renders correctly', async () => {
const tree = await renderSnapshot({
routerConfigs: { routes: [{ path: '/about', element: <AboutDescription /> }] },
});
expect(tree?.toJSON()).toMatchSnapshot();
});

it('contains the correct information', async () => {
render({
routerConfigs: { routes: [{ path: '/about', element: <AboutDescription /> }] },
});

expect(screen.getByText(versionString)).toBeInTheDocument();
expect(screen.getByText(versionString)).toHaveRole('link');
expect(screen.getByText(versionString)).toHaveAttribute(
'href',
'https://github.com/cryostatio/cryostat/releases/tag/v1.2.3',
);

expect(screen.getByText(`commit ${commitHash}`)).toBeInTheDocument();
expect(screen.getByText(`commit ${commitHash}`)).toHaveRole('link');
expect(screen.getByText(`commit ${commitHash}`)).toHaveAttribute(
'href',
'https://github.com/cryostatio/cryostat/commit/abcd1234',
);
});

const validVersions = [
{ str: 'v3.0.0', version: 'v3.0.0' },
{ str: 'v3.0.1', version: 'v3.0.1' },
{ str: 'v3.0.0-snapshot', version: 'v3.0.0', build: 'snapshot' },
{ str: '3.0.0', version: '3.0.0' },
{ str: '3.0.0-vendor123', version: '3.0.0', build: 'vendor123' },
{ str: 'v3.0.0-vendor123', version: 'v3.0.0', build: 'vendor123' },
{ str: 'v1.2.3-branch-vendor123', version: 'v1.2.3', build: 'branch-vendor123' },
{ str: 'v1.2.3-branch-vendor.tag123_a', version: 'v1.2.3', build: 'branch-vendor.tag123_a' },
{ str: 'v1.2.3-abcd1234', version: 'v1.2.3', build: 'abcd1234' },
];
validVersions.forEach((version) => {
it(`handles "${version.str}" version string correctly`, () => {
expect(VERSION_REGEX.test(version.str)).toBeTruthy();
const result = version.str.match(VERSION_REGEX);
expect(result).toBeTruthy();
expect(result![1]).toEqual(version.version);
expect(result![2]).toEqual(version.build);
});
});

const invalidVersions = ['v3', '3', '3.0', 'v3.0', 'v1.2.3abcd1234'];
invalidVersions.forEach((str) => {
it(`rejects "${str}" version string`, () => {
expect(VERSION_REGEX.test(str)).toBeFalsy();
});
});
});
152 changes: 152 additions & 0 deletions src/test/About/__snapshots__/AboutDescription.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<AboutDescription /> renders correctly 1`] = `
<div
className="pf-v5-c-content"
>
<dl
className=""
>
<dt
className=""
>
Version
</dt>
<dd
className=""
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-1"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://github.com/cryostatio/cryostat/releases/tag/v1.2.3"
target="_blank"
>
v1.2.3-snapshot
</a>
</dd>
<dt
className=""
>
Build Information
</dt>
<dd
className=""
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-2"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://github.com/cryostatio/cryostat/commit/abcd1234"
target="_blank"
>
commit abcd1234
</a>
</dd>
<dt
className=""
>
Homepage
</dt>
<dd
className=""
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-3"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://cryostat.io"
target="_blank"
>
cryostat.io
</a>
</dd>
<dt
className=""
>
Bugs
</dt>
<dd
className=""
>
<p
className=""
data-ouia-component-id="OUIA-Generated-Text-4"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-5"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://github.com/cryostatio/cryostat/issues"
target="_blank"
>
Known issues
</a>
 | 
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-6"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://github.com/cryostatio/cryostat/issues/new?labels=user+report,bug&body=Affects+v1.2.3-snapshot"
target="_blank"
>
File a report
</a>
</p>
</dd>
<dt
className=""
>
Mailing list
</dt>
<dd
className=""
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-7"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://groups.google.com/g/cryostat-development"
target="_blank"
>
Google Groups
</a>
</dd>
<dt
className=""
>
Open source license
</dt>
<dd
className=""
>
<a
className=""
data-ouia-component-id="OUIA-Generated-Text-8"
data-ouia-component-type="PF5/Text"
data-ouia-safe={true}
data-pf-content={true}
href="https://github.com/cryostatio/cryostat/blob/main/LICENSE.txt"
target="_blank"
>
License
</a>
</dd>
</dl>
</div>
`;

0 comments on commit d63322c

Please sign in to comment.