Skip to content

Commit

Permalink
fix: gui option 'auto-run'
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Mar 21, 2018
1 parent 57013d5 commit 90bbddd
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 28 deletions.
7 changes: 5 additions & 2 deletions lib/gui/tool-runner-factory/gemini/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ module.exports = class GeminiReporter extends BaseToolRunner {
return new this(paths, tool, configs);
}

constructor(paths, tool, {program: globalOpts, pluginConfig}) {
constructor(paths, tool, {program: globalOpts, pluginConfig, options: guiOpts}) {
super(paths);

this._globalOpts = globalOpts;
this._guiOpts = guiOpts;
this._reportPath = pluginConfig.path;
this._gemini = tool;
this._collection = null;
Expand Down Expand Up @@ -66,6 +67,8 @@ module.exports = class GeminiReporter extends BaseToolRunner {

_readTests() {
const {grep, set, browser} = this._globalOpts;
const {autoRun} = this._guiOpts;

return this._gemini.readTests(this._testFiles, {grep, sets: set})
.then((collection) => {
this._collection = collection;
Expand All @@ -85,7 +88,7 @@ module.exports = class GeminiReporter extends BaseToolRunner {
: this.reportBuilder.addIdle(state);
});

this.tree = Object.assign(this.reportBuilder.getResult(), {gui: true});
this.tree = Object.assign(this.reportBuilder.getResult(), {gui: true, autoRun});
this.tree.suites = this._applyReuseData(this.tree.suites);
});
}
Expand Down
14 changes: 7 additions & 7 deletions lib/static/components/controls/gui-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {connect} from 'react-redux';
import * as actions from '../../modules/actions';
import CommonControls from './common-controls';
import ControlButton from './button';
import RunButton from './run-button';

class ControlButtons extends Component {
_runFailedTests = () => {
Expand All @@ -21,15 +22,14 @@ class ControlButtons extends Component {
}

render() {
const {actions, failed, running} = this.props;
const {actions, failed, running, autoRun} = this.props;

return (
<div className="control-buttons">
<ControlButton
label="Run"
isAction={true}
handler={actions.runAllTests}
<RunButton
autoRun={autoRun}
isDisabled={running}
handler={actions.runAllTests}
/>
<ControlButton
label="Retry failed tests"
Expand All @@ -40,7 +40,6 @@ class ControlButtons extends Component {
label="Accept all"
isDisabled={running || !failed.length}
handler={this._acceptAll}
isDisabled={running || !failed.length}
/>
<CommonControls/>
</div>
Expand All @@ -52,7 +51,8 @@ export default connect(
(state) => ({
view: state.view,
failed: state.suites.failed,
running: state.running
running: state.running,
autoRun: state.autoRun
}),
(dispatch) => ({actions: bindActionCreators(actions, dispatch)})
)(ControlButtons);
25 changes: 25 additions & 0 deletions lib/static/components/controls/run-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import ControlButton from './button';

export default class RunButton extends Component {
static propTypes = {
handler: PropTypes.func.isRequired,
autoRun: PropTypes.bool.isRequired,
isDisabled: PropTypes.bool
}

componentWillReceiveProps({autoRun}) {
if (this.props.autoRun !== autoRun && autoRun) {
this.props.handler();
}
}

render() {
const {handler, isDisabled} = this.props;

return (<ControlButton label="Run" isAction={true} handler={handler} isDisabled={isDisabled} />);
}
}
10 changes: 9 additions & 1 deletion lib/static/components/gui.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
'use strict';

import React, {Component, Fragment} from 'react';
import {connect} from 'react-redux';
import {initial} from '../modules/actions';
import ControlButtons from './controls/gui-controls';
import SkippedList from './skipped-list';
import Suites from './suites';

export default class Gui extends Component {
class Gui extends Component {
componentDidMount() {
this.props.gui && this.props.initial();
}

render() {
return (
<Fragment>
Expand All @@ -16,3 +22,5 @@ export default class Gui extends Component {
);
}
}

export default connect(({gui}) => ({gui}), {initial})(Gui);
10 changes: 3 additions & 7 deletions lib/static/components/suites.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {connect} from 'react-redux';
import {uniqueId} from 'lodash';
import SectionCommon from './section/section-common';
import {bindActionCreators} from 'redux';
import {initial, suiteBegin, testBegin, testResult, updateResult, testsEnd} from '../modules/actions';
import {suiteBegin, testBegin, testResult, updateResult, testsEnd} from '../modules/actions';

class Suites extends Component {
static propTypes = {
Expand All @@ -15,11 +15,7 @@ class Suites extends Component {
}

componentDidMount() {
const {gui, actions} = this.props;
if (gui) {
actions.initial();
this._subscribeToEvents();
}
this.props.gui && this._subscribeToEvents();
}

_subscribeToEvents() {
Expand Down Expand Up @@ -71,7 +67,7 @@ class Suites extends Component {
}
}

const actions = {initial, testBegin, suiteBegin, testResult, updateResult, testsEnd};
const actions = {testBegin, suiteBegin, testResult, updateResult, testsEnd};

export default connect(
(state) => ({
Expand Down
1 change: 1 addition & 0 deletions lib/static/modules/default-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export default {
gui: true,
running: false,
autoRun: false,
skips: [],
suites: {
all: [],
Expand Down
19 changes: 10 additions & 9 deletions lib/static/modules/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function getInitialState(compiledData) {

export default function reducer(state = getInitialState(compiledData), action) {
switch (action.type) {
case actionNames.VIEW_INITIAL: {
const {gui, autoRun, suites, skips} = action.payload;

return merge({}, state, {
gui,
autoRun,
skips,
suites: {all: suites}
});
}
case actionNames.RUN_ALL_TESTS: {
const suites = cloneDeep(state.suites.all);
setStatusToAll(suites, action.payload.status);
Expand All @@ -40,15 +50,6 @@ export default function reducer(state = getInitialState(compiledData), action) {
case actionNames.RUN_FAILED_TESTS: {
return assign(clone(state), {running: true});
}
case actionNames.VIEW_INITIAL: {
const {gui, suites, skips} = action.payload;

return merge({}, state, {
gui,
skips,
suites: {all: suites}
});
}
case actionNames.SUITE_BEGIN: {
const suites = cloneDeep(state.suites.all);
const {suitePath, status} = action.payload;
Expand Down
4 changes: 2 additions & 2 deletions test/lib/gui/tool-runner-factory/gemini/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('lib/gui/tool-runner-factory/gemini/index', () => {
let gemini;

const mkGemini_ = () => stubTool(stubConfig());
const mkGeminiCliOpts_ = (cliOpts = {}) => ({program: cliOpts});
const mkCliOpts_ = (globalCliOpts = {}, guiCliOpts = {}) => ({program: globalCliOpts, options: guiCliOpts});
const mkPluginConfig_ = (config = {}) => {
const pluginConfig = _.defaults(config, {path: 'default-path'});
return {pluginConfig};
Expand All @@ -42,7 +42,7 @@ describe('lib/gui/tool-runner-factory/gemini/index', () => {
gemini = opts.gemini;
gemini.readTests.resolves(mkSuiteCollection_());

const configs = _.defaults(opts.configs, mkGeminiCliOpts_(), mkPluginConfig_());
const configs = _.defaults(opts.configs, mkCliOpts_(), mkPluginConfig_());

return GeminiGuiReporter.create(opts.paths, gemini, configs);
};
Expand Down

0 comments on commit 90bbddd

Please sign in to comment.