-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(about): be more lenient about build version format (#1524)
- Loading branch information
1 parent
ddf3500
commit d63322c
Showing
3 changed files
with
245 additions
and
3 deletions.
There are no files selected for viewing
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
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
152
src/test/About/__snapshots__/AboutDescription.test.tsx.snap
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,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> | ||
`; |