Add specs for new team modal

This commit is contained in:
Jonas Schwabe
2017-01-16 23:51:36 +01:00
parent 42c8f4e2ed
commit 8f3f59392d
4 changed files with 111 additions and 1 deletions

View File

@@ -49,7 +49,9 @@ class NewTeamModal extends React.Component {
render() { render() {
return ( return (
<Modal.Dialog> <Modal.Dialog
id='newServerModal'
>
<Modal.Header> <Modal.Header>
<Modal.Title>{'Add a new Team'}</Modal.Title> <Modal.Title>{'Add a new Team'}</Modal.Title>
</Modal.Header> </Modal.Header>
@@ -62,6 +64,7 @@ class NewTeamModal extends React.Component {
> >
<ControlLabel>{'Server Display Name'}</ControlLabel> <ControlLabel>{'Server Display Name'}</ControlLabel>
<FormControl <FormControl
id='teamNameInput'
type='text' type='text'
value={this.state.teamName} value={this.state.teamName}
placeholder='Server Name' placeholder='Server Name'
@@ -75,6 +78,7 @@ class NewTeamModal extends React.Component {
> >
<ControlLabel>{'Team URL'}</ControlLabel> <ControlLabel>{'Team URL'}</ControlLabel>
<FormControl <FormControl
id='teamUrlInput'
type='text' type='text'
value={this.state.teamUrl} value={this.state.teamUrl}
placeholder='https://example.org' placeholder='https://example.org'
@@ -88,9 +92,11 @@ class NewTeamModal extends React.Component {
<Modal.Footer> <Modal.Footer>
<Button <Button
id='cancelNewServerModal'
onClick={this.props.onClose} onClick={this.props.onClose}
>{'Cancel'}</Button> >{'Cancel'}</Button>
<Button <Button
id='saveNewServerModal'
onClick={() => { onClick={() => {
this.props.onSave({ this.props.onSave({
url: this.state.teamUrl, url: this.state.teamUrl,

View File

@@ -83,6 +83,7 @@ class TabBar extends React.Component {
renderAddTeamButton() { renderAddTeamButton() {
return ( return (
<Button <Button
id='tabBarAddNewTeam'
onClick={this.props.onAddTeam} onClick={this.props.onAddTeam}
bsStyle='tabButton' bsStyle='tabButton'
> >

View File

@@ -171,4 +171,11 @@ describe('browser/index.html', function desc() {
browserWindow.getTitle().should.eventually.equal('Title 1'); browserWindow.getTitle().should.eventually.equal('Title 1');
}); });
}); });
it('should open the new server prompt after clicking the add button', () => {
// See settings_test for specs that cover the actual prompt
return this.app.client.waitUntilWindowLoaded().
click('#tabBarAddNewTeam').
isExisting('#newServerModal').should.eventually.be.true;
});
}); });

View File

@@ -245,4 +245,100 @@ describe('browser/settings.html', function desc() {
isExisting(modalTitleSelector).should.eventually.false; isExisting(modalTitleSelector).should.eventually.false;
}); });
}); });
describe('NewTeamModal', () => {
beforeEach(() => {
env.addClientCommands(this.app.client);
return this.app.client.
loadSettingsPage().
click('#addNewServer');
});
it('should open the new server modal', () => {
return this.app.client.isExisting('#newServerModal').should.eventually.equal(true);
});
it('should close the window after clicking cancel', () => {
return this.app.client.
click('#cancelNewServerModal').
isExisting('#newServerModal').should.eventually.equal(false);
});
it('should not be valid if no team name has been set', () => {
return this.app.client.
isExisting('.has-error #teamNameInput').should.eventually.equal(true);
});
it('should not be valid if no server address has been set', () => {
return this.app.client.
isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
});
describe('Valid server name', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamNameInput', 'TestTeam');
});
it('should not be marked invalid', () => {
return this.app.client.
isExisting('.has-error #teamNameInput').should.eventually.equal(false);
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true');
});
});
describe('Valid server url', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamUrlInput', 'http://example.org');
});
it('should be valid', () => {
return this.app.client.
isExisting('.has-error #teamUrlInput').should.eventually.equal(false);
});
it('should not be possible to click save', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true');
});
});
it('should not be valid if an invalid server address has been set', () => {
return this.app.client.
setValue('#teamUrlInput', 'superInvalid url').
isExisting('.has-error #teamUrlInput').should.eventually.equal(true);
});
describe('Valid Team Settings', () => {
beforeEach(() => {
return this.app.client.
setValue('#teamUrlInput', 'http://example.org').
setValue('#teamNameInput', 'TestTeam');
});
it('should be possible to click add', () => {
return this.app.client.
getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal(null);
});
it('should add the team to the config file', (done) => {
this.app.client.
click('#saveNewServerModal').
click('#btnSave');
this.app.client.pause(1000).then(() => {
const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8'));
savedConfig.teams.should.contain({
name: 'TestTeam',
url: 'http://example.org'
});
return done();
});
});
});
});
}); });