Skip to content

Commit

Permalink
Improved solution and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Feb 9, 2024
1 parent d16736f commit 546e7d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/client/product/components/viewer/about/VersionInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class VersionInfo extends React.Component {
</div>
<div className="v_commit">
{
this.props.githubUrl ?
this.props.githubUrl && this.props.commit !== 'no-commit' ?
<a href={this.props.githubUrl + this.props.commit} target="_blank" className="v_githubUrl">
{this.props.commit}
</a> :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,18 @@ describe("The VersionInfo component", () => {
expect(dateValue.textContent.trim()).toBe(date);
expect(githubUrlValue.textContent.trim()).toBe(commit);
});
it('no commit', () => {
const githubUrl = "https://github.com/geosolutions-it/MapStore/tree/";
const vd = ReactDOM.render(
<VersionInfo
version={'version'}
githubUrl={githubUrl}
commit={'no-commit'}
message={'no-mssage'}
date={'no-date'}
/>, document.getElementById("container"));
expect(vd).toBeTruthy();
const commitValue = document.querySelector('.v_commit');
expect(commitValue.textContent.trim()).toBe('no-commit'); // No URL for 'no-commit' value
});
});
9 changes: 2 additions & 7 deletions web/client/reducers/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { CHANGE_VERSION, LOAD_VERSION_ERROR } from '../actions/version';
const splitData = __COMMIT_DATA__.split('\n');
import { parseCommitDataMessage } from '../utils/VersionUtils';
/**
* Manages the state of the version identifier
* @prop {string} current mapstore version identifier
Expand All @@ -22,12 +22,7 @@ const splitData = __COMMIT_DATA__.split('\n');
*}
* @memberof reducers
*/
function version(state = {
splitData,
message: splitData.find((x)=> x.includes('Message:'))?.split('Message: ')?.[1] ?? 'no-message',
commit: splitData.find((x)=> x.includes('Commit:'))?.split('Commit: ')?.[1] ?? 'no-commit',
date: splitData.find((x)=> x.includes('Date:'))?.split('Date: ')?.[1] ?? 'no-date'
}, action) {
function version(state = parseCommitDataMessage(__COMMIT_DATA__), action) {
switch (action.type) {
case CHANGE_VERSION: {
return {
Expand Down
8 changes: 8 additions & 0 deletions web/client/utils/VersionUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const parseCommitDataMessage = (commitData = "") => {
const splitData = commitData.split('\n');
return {
message: splitData.find((x)=> x.includes('Message:'))?.split('Message: ')?.[1] ?? 'no-message',
commit: splitData.find((x)=> x.includes('Commit:'))?.split('Commit: ')?.[1] ?? 'no-commit',
date: splitData.find((x)=> x.includes('Date:'))?.split('Date: ')?.[1] ?? 'no-date'
};
};
12 changes: 12 additions & 0 deletions web/client/utils/styleparser/__tests__/VersionUtils-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import expect from 'expect';
import { parseCommitDataMessage } from '../../VersionUtils';

describe('VersionUtils', () => {
it('parseCommitDataMessage', () => {
const commitData = 'Message: test\nCommit: 123456\nDate: 2022-01-01';
const result = parseCommitDataMessage(commitData);
expect(result.message).toBe('test');
expect(result.commit).toBe('123456');
expect(result.date).toBe('2022-01-01');
});
});

0 comments on commit 546e7d8

Please sign in to comment.