1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

fix: read unleash version from ui-config (#219)

This commit is contained in:
Ivar Conradi Østhus 2020-08-03 13:38:14 +02:00 committed by GitHub
parent d7ae641274
commit 0d3cbd8294
13 changed files with 41 additions and 104 deletions

View File

@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly with details 1`] = `
exports[`renders correctly with empty version 1`] = `
<react-mdl-FooterSection
logo="Unleash 1.1.0"
logo="Unleash "
type="bottom"
>
<small>
@ -15,9 +15,9 @@ exports[`renders correctly with details 1`] = `
</react-mdl-FooterSection>
`;
exports[`renders correctly with empty api details 1`] = `
exports[`renders correctly with ui-config 1`] = `
<react-mdl-FooterSection
logo="Unleash "
logo="Unleash 1.1.0"
type="bottom"
>
<small>

View File

@ -5,28 +5,36 @@ import renderer from 'react-test-renderer';
jest.mock('react-mdl');
const uiConfig = {
slogan: 'We are the best!',
environment: 'test',
};
test('renders correctly with empty version', () => {
const uiConfig = {
name: 'Unleash',
slogan: 'We are the best!',
environment: 'test',
version: '',
};
test('renders correctly with empty api details', () => {
const tree = renderer
.create(<ShowApiDetailsComponent fetchAll={jest.fn()} apiDetails={{}} uiConfig={uiConfig} />)
.toJSON();
const tree = renderer.create(<ShowApiDetailsComponent uiConfig={uiConfig} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('renders correctly with details', () => {
const tree = renderer
.create(<ShowApiDetailsComponent fetchAll={jest.fn()} apiDetails={{ version: '1.1.0' }} uiConfig={uiConfig} />)
.toJSON();
test('renders correctly with ui-config', () => {
const uiConfig = {
name: 'Unleash',
slogan: 'We are the best!',
environment: 'test',
version: '1.1.0',
};
const tree = renderer.create(<ShowApiDetailsComponent uiConfig={uiConfig} />).toJSON();
expect(tree).toMatchSnapshot();
});
test('renders correctly without uiConfig', () => {
const tree = renderer
.create(<ShowApiDetailsComponent fetchAll={jest.fn()} apiDetails={{ version: '1.1.0' }} uiConfig={{}} />)
.toJSON();
const uiConfig = {
name: 'Unleash',
version: '1.1.0',
};
const tree = renderer.create(<ShowApiDetailsComponent uiConfig={uiConfig} />).toJSON();
expect(tree).toMatchSnapshot();
});

View File

@ -4,21 +4,14 @@ import { FooterSection } from 'react-mdl';
class ShowApiDetailsComponent extends Component {
static propTypes = {
apiDetails: PropTypes.object.isRequired,
uiConfig: PropTypes.object.isRequired,
fetchAll: PropTypes.func.isRequired,
};
componentDidMount() {
this.props.fetchAll();
}
render() {
const version = this.props.apiDetails.version || '';
const { slogan, environment } = this.props.uiConfig;
const { slogan, environment, version, name } = this.props.uiConfig;
return (
<FooterSection type="bottom" logo={`Unleash ${version}`}>
<FooterSection type="bottom" logo={`${name} ${version}`}>
<small>{environment ? `(${environment})` : ''}</small>
<br />
<small>{slogan}</small>

View File

@ -1,13 +1,9 @@
import { connect } from 'react-redux';
import ShowApiDetailsComponent from './show-api-details-component';
import { fetchAll } from '../../store/api/actions';
const mapDispatchToProps = {
fetchAll,
};
const mapDispatchToProps = {};
const mapStateToProps = state => ({
apiDetails: state.api.toJS(),
uiConfig: state.uiConfig.toJS(),
});

View File

@ -63,6 +63,7 @@ class AuthComponent extends React.Component {
unsecureLogin={this.props.unsecureLogin}
authDetails={authDetails}
fetchFeatureToggles={this.props.fetchFeatureToggles}
fetchUIConfig={this.props.fetchUIConfig}
history={this.props.history}
/>
);

View File

@ -7,6 +7,7 @@ class SimpleAuthenticationComponent extends React.Component {
authDetails: PropTypes.object.isRequired,
unsecureLogin: PropTypes.func.isRequired,
fetchFeatureToggles: PropTypes.func.isRequired,
fetchUIConfig: PropTypes.func.isRequired,
history: PropTypes.object.isRequired,
};
@ -19,6 +20,7 @@ class SimpleAuthenticationComponent extends React.Component {
this.props
.unsecureLogin(path, user)
.then(this.props.fetchFeatureToggles)
.then(this.props.fetchUIConfig)
.then(() => this.props.history.push(`/`));
};

View File

@ -1,13 +0,0 @@
import { throwIfNotSuccess, headers } from './helper';
const URI = 'api';
function fetchAll() {
return fetch(URI, { headers, credentials: 'include' })
.then(throwIfNotSuccess)
.then(response => response.json());
}
export default {
fetchAll,
};

View File

@ -1,18 +0,0 @@
import apiReducer from '../index';
import { RECIEVE_API_DETAILS } from '../actions';
test('should have inital state', () => {
const store = apiReducer(undefined, {});
expect(store.toJS()).toEqual({});
});
test('should have new state', () => {
const store = apiReducer(undefined, { type: RECIEVE_API_DETAILS, value: { version: '1.1.1' } });
expect(store.toJS()).toEqual({ version: '1.1.1' });
});
test('should have updated state', () => {
const inital = apiReducer(undefined, { type: RECIEVE_API_DETAILS, value: { version: '1.1.1' } });
const store = apiReducer(inital, { type: RECIEVE_API_DETAILS, value: { version: '1.2.1' } });
expect(store.toJS()).toEqual({ version: '1.2.1' });
});

View File

@ -1,24 +0,0 @@
import api from '../../data/api';
export const RECIEVE_API_DETAILS = 'RECIEVE_API_DETAILS';
export const ERROR_RECIEVE_API_DETAILS = 'ERROR_RECIEVE_API_DETAILS';
export const RECEIVE_APPLICATION = 'RECEIVE_APPLICATION';
const recieveApiDetails = json => ({
type: RECIEVE_API_DETAILS,
value: json,
});
const errorRecieveApiDetails = (statusCode, type = ERROR_RECIEVE_API_DETAILS) => ({
type,
statusCode,
});
export function fetchAll() {
return dispatch =>
api
.fetchAll()
.then(json => dispatch(recieveApiDetails(json)))
.catch(error => dispatch(errorRecieveApiDetails(error)));
}

View File

@ -1,14 +0,0 @@
import { Map } from 'immutable';
import { RECIEVE_API_DETAILS } from './actions';
const store = (state = new Map(), action) => {
switch (action.type) {
case RECIEVE_API_DETAILS:
state = new Map(action.value);
return state;
default:
return state;
}
};
export default store;

View File

@ -9,7 +9,6 @@ import error from './error-store';
import clientInstances from './client-instance-store';
import settings from './settings';
import user from './user';
import api from './api';
import applications from './application';
import uiConfig from './ui-config';
import context from './context';
@ -27,7 +26,6 @@ const unleashStore = combineReducers({
user,
applications,
uiConfig,
api,
context,
});

View File

@ -18,7 +18,9 @@ Object {
"value": "GitHub",
},
],
"name": "Unleash",
"slogan": "The enterprise ready feature toggle service.",
"version": "3.x",
}
`;
@ -40,7 +42,9 @@ Object {
"value": "GitHub",
},
],
"name": "Unleash",
"slogan": "hello",
"version": "3.x",
}
`;
@ -62,6 +66,8 @@ Object {
"value": "GitHub",
},
],
"name": "Unleash",
"slogan": "The enterprise ready feature toggle service.",
"version": "3.x",
}
`;

View File

@ -11,6 +11,8 @@ const UI_CONFIG = `${basePath}:ui_config`;
const DEFAULT = new $Map({
headerBackground: undefined,
name: 'Unleash',
version: '3.x',
environment: '',
slogan: 'The enterprise ready feature toggle service.',
links: [