fix: Init test output on backend challenges

Makes sure the test output console is initialized on backend as well as
classic challenges.  Previously it was tied to SidePanel which was not
always present.
This commit is contained in:
Oliver Eyton-Williams
2019-06-20 10:04:36 +02:00
committed by mrugesh
parent 7dd2fe19f3
commit a8c86f6168
3 changed files with 16 additions and 16 deletions

View File

@ -10,6 +10,7 @@ import {
challengeMounted, challengeMounted,
challengeTestsSelector, challengeTestsSelector,
consoleOutputSelector, consoleOutputSelector,
initConsole,
initTests, initTests,
updateBackendFormValues, updateBackendFormValues,
updateChallengeMeta, updateChallengeMeta,
@ -44,6 +45,7 @@ const propTypes = {
description: PropTypes.string, description: PropTypes.string,
executeChallenge: PropTypes.func.isRequired, executeChallenge: PropTypes.func.isRequired,
id: PropTypes.string, id: PropTypes.string,
initConsole: PropTypes.func.isRequired,
initTests: PropTypes.func.isRequired, initTests: PropTypes.func.isRequired,
isSignedIn: PropTypes.bool, isSignedIn: PropTypes.bool,
output: PropTypes.string, output: PropTypes.string,
@ -71,6 +73,7 @@ const mapStateToProps = createSelector(
const mapDispatchToActions = { const mapDispatchToActions = {
challengeMounted, challengeMounted,
executeChallenge, executeChallenge,
initConsole,
initTests, initTests,
updateBackendFormValues, updateBackendFormValues,
updateChallengeMeta, updateChallengeMeta,
@ -96,6 +99,7 @@ export class BackEnd extends Component {
componentDidMount() { componentDidMount() {
const { const {
challengeMounted, challengeMounted,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
data: { data: {
@ -106,6 +110,7 @@ export class BackEnd extends Component {
}, },
pageContext: { challengeMeta } pageContext: { challengeMeta }
} = this.props; } = this.props;
initConsole('');
initTests(tests); initTests(tests);
updateChallengeMeta({ ...challengeMeta, challengeType }); updateChallengeMeta({ ...challengeMeta, challengeType });
challengeMounted(challengeMeta.id); challengeMounted(challengeMeta.id);
@ -128,6 +133,7 @@ export class BackEnd extends Component {
} = prevProps; } = prevProps;
const { const {
challengeMounted, challengeMounted,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
data: { data: {
@ -140,6 +146,7 @@ export class BackEnd extends Component {
pageContext: { challengeMeta } pageContext: { challengeMeta }
} = this.props; } = this.props;
if (prevTitle !== currentTitle) { if (prevTitle !== currentTitle) {
initConsole('');
initTests(tests); initTests(tests);
updateChallengeMeta({ ...challengeMeta, challengeType }); updateChallengeMeta({ ...challengeMeta, challengeType });
challengeMounted(challengeMeta.id); challengeMounted(challengeMeta.id);

View File

@ -28,6 +28,7 @@ import {
createFiles, createFiles,
challengeFilesSelector, challengeFilesSelector,
challengeTestsSelector, challengeTestsSelector,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
challengeMounted, challengeMounted,
@ -47,6 +48,7 @@ const mapDispatchToProps = dispatch =>
bindActionCreators( bindActionCreators(
{ {
createFiles, createFiles,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
challengeMounted challengeMounted
@ -63,6 +65,7 @@ const propTypes = {
files: PropTypes.shape({ files: PropTypes.shape({
key: PropTypes.string key: PropTypes.string
}), }),
initConsole: PropTypes.func.isRequired,
initTests: PropTypes.func.isRequired, initTests: PropTypes.func.isRequired,
output: PropTypes.string, output: PropTypes.string,
pageContext: PropTypes.shape({ pageContext: PropTypes.shape({
@ -104,6 +107,7 @@ class ShowClassic extends Component {
const { const {
challengeMounted, challengeMounted,
createFiles, createFiles,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
data: { data: {
@ -116,6 +120,7 @@ class ShowClassic extends Component {
}, },
pageContext: { challengeMeta } pageContext: { challengeMeta }
} = this.props; } = this.props;
initConsole('');
createFiles(files); createFiles(files);
initTests(tests); initTests(tests);
updateChallengeMeta({ ...challengeMeta, title, challengeType }); updateChallengeMeta({ ...challengeMeta, title, challengeType });
@ -131,6 +136,7 @@ class ShowClassic extends Component {
const { const {
challengeMounted, challengeMounted,
createFiles, createFiles,
initConsole,
initTests, initTests,
updateChallengeMeta, updateChallengeMeta,
data: { data: {
@ -144,6 +150,7 @@ class ShowClassic extends Component {
pageContext: { challengeMeta } pageContext: { challengeMeta }
} = this.props; } = this.props;
if (prevTitle !== currentTitle) { if (prevTitle !== currentTitle) {
initConsole('');
createFiles(files); createFiles(files);
initTests(tests); initTests(tests);
updateChallengeMeta({ updateChallengeMeta({

View File

@ -1,7 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ChallengeTitle from './Challenge-Title'; import ChallengeTitle from './Challenge-Title';
import ChallengeDescription from './Challenge-Description'; import ChallengeDescription from './Challenge-Description';
@ -9,7 +8,7 @@ import ToolPanel from './Tool-Panel';
import TestSuite from './Test-Suite'; import TestSuite from './Test-Suite';
import Spacer from '../../../components/helpers/Spacer'; import Spacer from '../../../components/helpers/Spacer';
import { initConsole, challengeTestsSelector } from '../redux'; import { challengeTestsSelector } from '../redux';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import './side-panel.css'; import './side-panel.css';
@ -20,20 +19,11 @@ const mapStateToProps = createSelector(
}) })
); );
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
initConsole
},
dispatch
);
const MathJax = global.MathJax; const MathJax = global.MathJax;
const propTypes = { const propTypes = {
description: PropTypes.string, description: PropTypes.string,
guideUrl: PropTypes.string, guideUrl: PropTypes.string,
initConsole: PropTypes.func.isRequired,
instructions: PropTypes.string, instructions: PropTypes.string,
introPath: PropTypes.string, introPath: PropTypes.string,
nextChallengePath: PropTypes.string, nextChallengePath: PropTypes.string,
@ -60,7 +50,6 @@ export class SidePanel extends Component {
MathJax.Hub, MathJax.Hub,
document.querySelector('.rosetta-code') document.querySelector('.rosetta-code')
]); ]);
this.props.initConsole('');
} }
render() { render() {
@ -106,7 +95,4 @@ export class SidePanel extends Component {
SidePanel.displayName = 'SidePanel'; SidePanel.displayName = 'SidePanel';
SidePanel.propTypes = propTypes; SidePanel.propTypes = propTypes;
export default connect( export default connect(mapStateToProps)(SidePanel);
mapStateToProps,
mapDispatchToProps
)(SidePanel);