From 151fc5a390595c11aab2b19369f798845c4ccff4 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Tue, 18 Jul 2017 23:15:09 +0800 Subject: [PATCH 1/2] implement NewVersionAvailable component --- src-react/actions/version.js | 4 ++++ src-react/components/alert-area/index.js | 3 ++- .../alert-area/new-version-available.js | 16 +++++++++------- src-react/constants/action-types.js | 3 ++- src-react/containers/path.js | 5 +++-- src-react/reducers/app.js | 4 ++++ 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src-react/actions/version.js b/src-react/actions/version.js index 210090f..fa00dd2 100644 --- a/src-react/actions/version.js +++ b/src-react/actions/version.js @@ -31,4 +31,8 @@ export function fetchGitVersion() { export function dismissGitVersionError() { return { type: types.DISMISS_GIT_VERSION_ERROR }; +} + +export function dismissNewVersion() { + return { type: types.DISMISS_NEW_VERSION }; } \ No newline at end of file diff --git a/src-react/components/alert-area/index.js b/src-react/components/alert-area/index.js index 6737cc7..d9ae726 100644 --- a/src-react/components/alert-area/index.js +++ b/src-react/components/alert-area/index.js @@ -43,7 +43,8 @@ class AlertArea extends Component { showNewVersionAvailable ? ( + platform={ platform } + onDismiss={ actions.dismissNewVersion }/> ) : null } { diff --git a/src-react/components/alert-area/new-version-available.js b/src-react/components/alert-area/new-version-available.js index ed138cf..75cb592 100644 --- a/src-react/components/alert-area/new-version-available.js +++ b/src-react/components/alert-area/new-version-available.js @@ -1,21 +1,23 @@ -import React, { Component, PropTypes } from 'react'; +import React, { Component } from 'react'; +import { PropTypes } from 'prop-types'; class NewVersionAvailable extends Component { static propTypes = { latestVersion: PropTypes.string, - platform: PropTypes.string + platform: PropTypes.string, + onDismiss: PropTypes.func.isRequired } render() { - const newVersionInstallCommand = `#{this.props.platform ? '' : 'sudo -H'}npm update -g ungit`; + const { platform, onDismiss } = this.props; return (
- A new version of ungit ({ this.props.latestVersion }) is + A new version of ungit ({ this.props.latestVersion }) is  available! Run - { newVersionInstallCommand } to install. - See what's new in the + { `${platform ? '' : 'sudo -H'} npm update -g ungit` } to install. + See what's new in the  changelog. - +
); } diff --git a/src-react/constants/action-types.js b/src-react/constants/action-types.js index 88d091a..17d49e7 100644 --- a/src-react/constants/action-types.js +++ b/src-react/constants/action-types.js @@ -15,4 +15,5 @@ export const FETCH_LATEST_VERSION_SUCCESS = 'FETCH_LATEST_VERSION_SUCCESS'; export const FETCH_GIT_VERSION_SUCCESS = 'FETCH_GIT_VERSION_SUCCESS'; export const FETCH_UNGIT_CONFIG_SUCCESS = 'FETCH_UNGIT_CONFIG_SUCCESS'; -export const DISMISS_GIT_VERSION_ERROR = 'DISMISS_GIT_VERSION_ERROR'; \ No newline at end of file +export const DISMISS_GIT_VERSION_ERROR = 'DISMISS_GIT_VERSION_ERROR'; +export const DISMISS_NEW_VERSION = 'DISMISS_NEW_VERSION'; \ No newline at end of file diff --git a/src-react/containers/path.js b/src-react/containers/path.js index d444b7f..d83467e 100644 --- a/src-react/containers/path.js +++ b/src-react/containers/path.js @@ -26,9 +26,10 @@ class Path extends Component { app, path: { pending, errMessage }, actions: { - dismissGitVersionError + dismissGitVersionError, + dismissNewVersion } } = this.props; - const alertAreaActions = { dismissGitVersionError }; + const alertAreaActions = { dismissGitVersionError, dismissNewVersion }; return (
diff --git a/src-react/reducers/app.js b/src-react/reducers/app.js index 86152f2..11bdb94 100644 --- a/src-react/reducers/app.js +++ b/src-react/reducers/app.js @@ -43,6 +43,10 @@ function app(state, action, config) { return { ...state, gitVersionErrorVisible: false }; } + case types.DISMISS_NEW_VERSION: { + return { ...state, showNewVersionAvailable: false }; + } + default: const NPSSurveyLastDismissed = parseInt(localStorage.getItem('NPSSurveyLastDismissed') || '0', 10); const monthsSinceNPSLastDismissed = (Date.now() - NPSSurveyLastDismissed) / (1000 * 60 * 60 * 24 * 30); From 985cfe36c78b777ca14bb5fc63183728b8761573 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Tue, 18 Jul 2017 23:52:38 +0800 Subject: [PATCH 2/2] 1. add test case for NewVersionAvailable component 2. also patch reudcer test for DISMISS_GIT_VERSION_ERROR and DISMISS_NEW_VERSION actions --- .../alert-area/new-version-available.test.js | 52 +++++++++++++++++++ src-react/__tests__/reducers/app.js | 19 +++++++ 2 files changed, 71 insertions(+) create mode 100644 src-react/__tests__/components/alert-area/new-version-available.test.js diff --git a/src-react/__tests__/components/alert-area/new-version-available.test.js b/src-react/__tests__/components/alert-area/new-version-available.test.js new file mode 100644 index 0000000..ecd494b --- /dev/null +++ b/src-react/__tests__/components/alert-area/new-version-available.test.js @@ -0,0 +1,52 @@ +jest.dontMock('components/alert-area/new-version-available'); +import sinon from 'sinon'; +import React from 'react'; +import { shallow, mount, render } from 'enzyme'; +import NewVersionAvailable from 'components/alert-area/new-version-available'; + +describe('alert-area/new-version-available component', () => { + let wrapper; + let platform = 'windows'; + const latestVersion = '1.3'; + const onDismiss = sinon.spy(); + + beforeEach(() => { + wrapper = mount( + + ); + }); + + it("should render successfully", function() { + expect(wrapper.exists()).toBe(true); + expect(wrapper.find('.alert.alert-info').length).toBe(1); + expect(wrapper.contains({ latestVersion })).toBe(true); + expect(wrapper.contains(available)).toBe(true); + expect(wrapper.contains(changelog)).toBe(true); + expect(wrapper.contains({ ' npm update -g ungit' })).toBe(true); + expect(wrapper.find('button').length).toBe(1); + }); + + it('should trigger click events when clicking dismiss button', () => { + wrapper.find('button').simulate('click'); + expect(onDismiss.callCount).toBe(1); + }); + + describe('when platform is not existing', () => { + beforeEach(() => { + platform = null; + wrapper = mount( + + ); + }); + + it('should render installation indication with sudo -H ', () => { + expect(wrapper.contains({ 'sudo -H npm update -g ungit' })).toBe(true); + }); + }); +}); \ No newline at end of file diff --git a/src-react/__tests__/reducers/app.js b/src-react/__tests__/reducers/app.js index 6423dfb..acbf6b3 100644 --- a/src-react/__tests__/reducers/app.js +++ b/src-react/__tests__/reducers/app.js @@ -228,4 +228,23 @@ describe('app.js reducers', () => { }); }); }); + + describe('when DISMISS_GIT_VERSION_ERROR action dispatch', () => { + it('should force set gitVersionErrorDismissed as ture in localStorage', () => { + const state = app(initialState, { type: types.DISMISS_GIT_VERSION_ERROR }, {}); + expect(localStorage.getItem('gitVersionErrorDismissed')).toEqual('true'); + }); + + it('gitVersionErrorVisible state will be false', () => { + const state = app(initialState, { type: types.DISMISS_GIT_VERSION_ERROR }, {}); + expect(state.gitVersionErrorVisible).toBe(false); + }); + }); + + describe('when DISMISS_NEW_VERSION action dispatch', () => { + it('showNewVersionAvailable state will be false', () => { + const state = app(initialState, { type: types.DISMISS_NEW_VERSION }, {}); + expect(state.showNewVersionAvailable).toBe(false); + }); + }); }); \ No newline at end of file