Repository: aurora Updated Branches: refs/heads/master 2507e6f59 -> 5201cf16a
Reload instance page when URL changes. Reviewed at https://reviews.apache.org/r/63221/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/5201cf16 Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/5201cf16 Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/5201cf16 Branch: refs/heads/master Commit: 5201cf16a7a29799664e4baaf741233ff59edec7 Parents: 2507e6f Author: Reza Motamedi <[email protected]> Authored: Wed Oct 25 15:30:37 2017 -0700 Committer: David McLaughlin <[email protected]> Committed: Wed Oct 25 15:30:37 2017 -0700 ---------------------------------------------------------------------- ui/package.json | 2 +- ui/src/main/js/pages/Instance.js | 21 +++++++-- ui/src/main/js/pages/__tests__/Instance-test.js | 47 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/5201cf16/ui/package.json ---------------------------------------------------------------------- diff --git a/ui/package.json b/ui/package.json index 0651fc7..634d0f7 100644 --- a/ui/package.json +++ b/ui/package.json @@ -5,6 +5,7 @@ "main": "index.js", "dependencies": { "bootstrap": "^3.3.7", + "deep-equal": "^1.0.1", "diff": "^3.4.0", "es6-shim": "^0.35.3", "moment": "^2.18.1", @@ -23,7 +24,6 @@ "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "css-loader": "^0.28.5", - "deep-equal": "^1.0.1", "enzyme": "^3.0.0", "enzyme-adapter-react-16": "^1.0.0", "eslint": "^4.4.1", http://git-wip-us.apache.org/repos/asf/aurora/blob/5201cf16/ui/src/main/js/pages/Instance.js ---------------------------------------------------------------------- diff --git a/ui/src/main/js/pages/Instance.js b/ui/src/main/js/pages/Instance.js index 4b85545..2979b3c 100644 --- a/ui/src/main/js/pages/Instance.js +++ b/ui/src/main/js/pages/Instance.js @@ -1,4 +1,5 @@ import React from 'react'; +import deepEqual from 'deep-equal'; import Breadcrumb from 'components/Breadcrumb'; import InstanceHistory from 'components/InstanceHistory'; @@ -8,13 +9,16 @@ import TaskStatus from 'components/TaskStatus'; import { isActive } from 'utils/Task'; export default class Instance extends React.Component { + getInitialState() { + return {cluster: '', tasks: [], loading: true}; + } + constructor(props) { super(props); - this.state = {cluster: '', tasks: [], loading: true, loadingNeighbors: true}; + this.state = this.getInitialState(); } - componentWillMount(props) { - const { role, environment, name, instance } = this.props.match.params; + fetchTask(role, environment, name, instance) { const query = new TaskQuery(); query.role = role; query.environment = environment; @@ -31,6 +35,11 @@ export default class Instance extends React.Component { }); } + componentWillMount(props) { + const { role, environment, name, instance } = this.props.match.params; + this.fetchTask(role, environment, name, instance); + } + componentWillUpdate(nextProps, nextState) { if (this.state.loading && !nextState.loading) { const activeTask = nextState.tasks.find(isActive); @@ -49,6 +58,12 @@ export default class Instance extends React.Component { }); }); } + + if (!deepEqual(this.props.match.params, nextProps.match.params)) { + const { role, environment, name, instance } = nextProps.match.params; + this.setState(this.getInitialState()); + this.fetchTask(role, environment, name, instance); + } } render() { http://git-wip-us.apache.org/repos/asf/aurora/blob/5201cf16/ui/src/main/js/pages/__tests__/Instance-test.js ---------------------------------------------------------------------- diff --git a/ui/src/main/js/pages/__tests__/Instance-test.js b/ui/src/main/js/pages/__tests__/Instance-test.js index 2395e2e..1a8cd7b 100644 --- a/ui/src/main/js/pages/__tests__/Instance-test.js +++ b/ui/src/main/js/pages/__tests__/Instance-test.js @@ -17,6 +17,13 @@ const params = { instance: '1' }; +const differentParams = { + role: 'test-role', + environment: 'test-env', + name: 'test-job', + instance: '2' +}; + function createMockApi(tasks) { const api = {}; api.getTasksWithoutConfigs = (query, handler) => handler({ @@ -40,6 +47,16 @@ const tasks = [{ status: ScheduleStatus.KILLED }]; +function apiSpy() { + return { + getTasksWithoutConfigs: jest.fn(), + getPendingReason: jest.fn(), + getConfigSummary: jest.fn(), + getJobUpdateDetails: jest.fn(), + getJobSummary: jest.fn() + }; +} + describe('Instance', () => { it('Should render Loading before data is fetched', () => { expect(shallow(<Instance @@ -58,4 +75,34 @@ describe('Instance', () => { expect(el.contains(<TaskStatus task={tasks[1]} />)).toBe(true); expect(el.contains(<InstanceHistory tasks={[tasks[0], tasks[2]]} />)).toBe(true); }); + + const props = () => { + return { + api: apiSpy(), + cluster: 'test', + match: {params: params} + }; + }; + + it('Should fetch data once params change', () => { + const apiProps = props(); + const api = apiSpy(); + apiProps.api = api; + const el = shallow(<Instance {...apiProps} />); + + expect(api['getTasksWithoutConfigs'].mock.calls.length).toBe(1); + el.setProps({match: {params: differentParams}}); + expect(api['getTasksWithoutConfigs'].mock.calls.length).toBe(2); + }); + + it('Should not fetch data for any instance if params has not changed', () => { + const apiProps = props(); + const api = apiSpy(); + apiProps.api = api; + const el = shallow(<Instance {...apiProps} />); + + expect(api['getTasksWithoutConfigs'].mock.calls.length).toBe(1); + el.setProps({match: {params: params}}); + expect(api['getTasksWithoutConfigs'].mock.calls.length).toBe(1); + }); });
