aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2019-04-11 11:18:49 +0200
committerSonarTech <sonartech@sonarsource.com>2019-04-11 20:21:04 +0200
commit4380a1d1594cb112f3d3e17b99f4a801c3d2fda8 (patch)
tree3265b53ac03fd6492f6383d2d156ba62ec7848ec /server/sonar-web/src
parentc4d959d2bc45a19decdb03dddb840e267d20bac6 (diff)
downloadsonarqube-4380a1d1594cb112f3d3e17b99f4a801c3d2fda8.tar.gz
sonarqube-4380a1d1594cb112f3d3e17b99f4a801c3d2fda8.zip
SONARCLOUD-520 change location of homepage data file
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/Home.tsx38
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/Home-test.tsx30
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/__snapshots__/Home-test.tsx.snap37
-rw-r--r--server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts10
4 files changed, 104 insertions, 11 deletions
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/Home.tsx b/server/sonar-web/src/main/js/apps/about/sonarcloud/Home.tsx
index fd78f1cc580..6f003a2dffb 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/Home.tsx
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/Home.tsx
@@ -19,6 +19,7 @@
*/
import * as React from 'react';
import Helmet from 'react-helmet';
+import { connect } from 'react-redux';
import { FixedNavBar, TopNavBar } from './components/NavBars';
import FeaturedProjects from './components/FeaturedProjects';
import Footer from './components/Footer';
@@ -26,32 +27,48 @@ import { Languages } from './components/Languages';
import LoginButtons from './components/LoginButtons';
import Statistics from './components/Statistics';
import { requestHomepageData, HomepageData, FeaturedProject } from './utils';
+import { getGlobalSettingValue, Store } from '../../../store/rootReducer';
import { addWhitePageClass, removeWhitePageClass } from '../../../helpers/pages';
import { getBaseUrl } from '../../../helpers/urls';
import './new_style.css';
+interface Props {
+ homePageDataUrl?: string;
+}
+
interface State {
data?: HomepageData;
}
-export default class Home extends React.PureComponent<{}, State> {
+export class Home extends React.PureComponent<Props, State> {
+ mounted = false;
state: State = {};
componentDidMount() {
+ this.mounted = true;
addWhitePageClass();
this.fetchData();
}
componentWillUnmount() {
removeWhitePageClass();
+ this.mounted = false;
}
fetchData = () => {
- requestHomepageData()
- .then(data => this.setState({ data }))
- .catch(() => {
- /* Fail silently */
- });
+ const { homePageDataUrl } = this.props;
+ if (homePageDataUrl) {
+ requestHomepageData(homePageDataUrl).then(
+ data => {
+ if (this.mounted) {
+ this.setState({ data });
+ }
+ },
+ () => {
+ /* Fail silently */
+ }
+ );
+ }
};
render() {
@@ -84,6 +101,15 @@ export default class Home extends React.PureComponent<{}, State> {
}
}
+const mapStateToProps = (state: Store) => {
+ const homePageDataUrl = getGlobalSettingValue(state, 'sonar.homepage.url');
+ return {
+ homePageDataUrl: homePageDataUrl && homePageDataUrl.value
+ };
+};
+
+export default connect(mapStateToProps)(Home);
+
function PageBackgroundHeader() {
return (
<div className="sc-header-background">
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/Home-test.tsx b/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/Home-test.tsx
index ce5282fe00e..bb3374ffe14 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/Home-test.tsx
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/Home-test.tsx
@@ -21,6 +21,8 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import Home from '../Home';
import { waitAndUpdate } from '../../../../helpers/testUtils';
+import { mockStore } from '../../../../helpers/testMocks';
+import { requestHomepageData } from '../utils';
jest.mock('../utils', () => {
const utils = require.requireActual('../utils');
@@ -53,8 +55,13 @@ jest.mock('../utils', () => {
return utils;
});
+beforeEach(() => {
+ jest.clearAllMocks();
+});
+
it('should render', async () => {
- const wrapper = shallow(<Home />);
+ const wrapper = shallowRender('https://static.sonarcloud.io/homepage.json');
+ expect(requestHomepageData).toBeCalled();
await waitAndUpdate(wrapper);
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('PageBackgroundHeader').dive()).toMatchSnapshot();
@@ -65,3 +72,24 @@ it('should render', async () => {
expect(wrapper.find('Stats').dive()).toMatchSnapshot();
expect(wrapper.find('Projects').dive()).toMatchSnapshot();
});
+
+it('should not render real Stats and Projects', () => {
+ const wrapper = shallowRender(undefined);
+ expect(requestHomepageData).not.toBeCalled();
+ expect(wrapper.find('Stats').dive()).toMatchSnapshot();
+ expect(wrapper.find('Projects').dive()).toMatchSnapshot();
+});
+
+function shallowRender(homePageDataUrl: string | undefined) {
+ return shallow(<Home />, {
+ context: {
+ store: mockStore({
+ settingsApp: {
+ values: {
+ global: { 'sonar.homepage.url': { key: 'sonar.homepage.url', value: homePageDataUrl } }
+ }
+ }
+ })
+ }
+ }).dive();
+}
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/__snapshots__/Home-test.tsx.snap b/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/__snapshots__/Home-test.tsx.snap
index 46988fe232d..0527dbd3e26 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/__snapshots__/Home-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/__tests__/__snapshots__/Home-test.tsx.snap
@@ -1,5 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`should not render real Stats and Projects 1`] = `
+<div
+ className="sc-section sc-columns"
+>
+ <div
+ className="sc-column sc-column-full"
+ >
+ <h3>
+ Over 3,000 Projects
+ <br />
+ Continuously Analyzed
+ </h3>
+ </div>
+</div>
+`;
+
+exports[`should not render real Stats and Projects 2`] = `
+<div
+ className="sc-section sc-columns"
+>
+ <div
+ className="sc-column sc-column-full"
+ >
+ <h6
+ className="spacer-bottom"
+ >
+ Come join the fun, it’s entirely free for open-source projects!
+ </h6>
+ <div
+ className="sc-spacer-bottom"
+ >
+ <LoginButtons />
+ </div>
+ </div>
+</div>
+`;
+
exports[`should render 1`] = `
<div
className="global-container"
diff --git a/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts b/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts
index 9ad2eb78dbb..7f4301429d9 100644
--- a/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts
+++ b/server/sonar-web/src/main/js/apps/about/sonarcloud/utils.ts
@@ -17,6 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { getJSON } from '../../../helpers/request';
+
export interface FeaturedProject {
key: string;
avatarUrl: string | null;
@@ -45,10 +47,6 @@ export interface HomepageData {
newPullRequests7d: number;
}
-export function requestHomepageData(): Promise<HomepageData> {
- return fetch('/json/homepage.json').then(response => response.json());
-}
-
export const LANGUAGES = [
{ name: 'Java', file: 'java.svg', width: 65 },
{ name: 'JavaScript', file: 'js.svg', width: 60 },
@@ -74,3 +72,7 @@ export const LANGUAGES = [
{ name: 'XML', file: 'xml.svg', width: 67 },
{ name: 'COBOL', file: 'cobol.svg', width: 65 }
];
+
+export function requestHomepageData(url: string): Promise<HomepageData> {
+ return getJSON(url);
+}