Skip to content

Commit

Permalink
Add initial UI for config changes in desktop GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
lilaconlee committed Jan 24, 2019
1 parent c223551 commit deccabe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,29 @@ describe "WarningMessage", ->
.click()
.then ->
expect(@ipc.externalOpen).not.to.be.called

describe "for error type CONFIGURATION_CHANGED", ->
beforeEach ->
configWarningObj = {
type: "CONFIGURATION_CHANGED",
name: "Configuration changed",
message: "This file was changed: `cypress.json`\nPlease restart Cypress for changes to take effect."
}

cy.shouldBeOnProjectSpecs().then =>
@ipc.onProjectWarning.yield(null, configWarningObj)

it "renders configuration change message with the correct file name", ->
cy
.contains(".alert-warning", "This file was changed: cypress.json")
.contains(".alert-warning", "Please restart Cypress for changes to take effect.")

it "is not dismissable", ->
cy.get(".alert-warning .close").should("not.exist")

it "can reload the project", ->
cy.contains(".alert-warning strong", "Restart")
.click()
.should =>
expect(@ipc.closeProject).to.be.called
expect(@ipc.openProject).to.be.called
4 changes: 4 additions & 0 deletions packages/desktop-gui/src/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const errors = {
isUnknown (err) {
return _.get(err, 'type') === 'UNKNOWN'
},

isConfigurationChanged (err) {
return _.get(err, 'type') === 'CONFIGURATION_CHANGED'
},
}

export default errors
2 changes: 1 addition & 1 deletion packages/desktop-gui/src/project/project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Project extends Component {
<ProjectNav project={this.props.project}/>
<div className='project-content'>
{warning &&
<WarningMessage warning={warning} onClearWarning={this._removeWarning}/>
<WarningMessage warning={warning} onClearWarning={this._removeWarning} onRestart={this._reopenProject}/>
}
{this._currentView()}
</div>
Expand Down
18 changes: 17 additions & 1 deletion packages/desktop-gui/src/project/warning-message.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react'
import { observer } from 'mobx-react'
import Markdown from 'markdown-it'

import errors from '../lib/errors'
import ipc from '../lib/ipc'

const md = new Markdown({
Expand All @@ -28,7 +29,22 @@ class WarningMessage extends Component {
}

render () {
const warningText = this.props.warning.message.split('\n').join('<br />')
const warning = this.props.warning
const warningText = warning.message.split('\n').join('<br />')

if (errors.isConfigurationChanged(warning)) {
return (
<div className='alert alert-warning'>
<div ref={(node) => this.warningMessageNode = node} dangerouslySetInnerHTML={{
__html: md.render(warningText),
}}></div>
<strong onClick={this.props.onRestart}>
<i className='fa fa-refresh'></i>{' '}
Restart
</strong>
</div>
)
}

return (
<div className='alert alert-warning'>
Expand Down

0 comments on commit deccabe

Please sign in to comment.