Skip to content

Commit

Permalink
Merge eeec154 into 0a048f7
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielRMuller committed Jan 30, 2019
2 parents 0a048f7 + eeec154 commit c2adad0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ExpandedStoryNotes extends React.Component {
this.setState({ value: '' });
}

hasAnEmptyValue() {
return !this.state.value.trim()
}

notesForm() {
return (
<div>
Expand All @@ -39,6 +43,7 @@ class ExpandedStoryNotes extends React.Component {
type='button'
value={I18n.t('add note')}
onClick={this.handleSave}
disabled={this.hasAnEmptyValue()}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class ExpandedStoryTask extends Component {
});
}

hasAnEmptyValue() {
return !this.state.task.trim()
}

render() {
const { story, onToggle, onDelete } = this.props;

Expand Down Expand Up @@ -57,6 +61,7 @@ class ExpandedStoryTask extends Component {
type='submit'
className='Story__add-task-button'
onClick={this.onHandleSubmit}
disabled={this.hasAnEmptyValue()}
>
{I18n.t('add task')}
</button>
Expand Down
28 changes: 26 additions & 2 deletions app/assets/javascripts/views/story_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,11 +784,23 @@ module.exports = FormView.extend({
/>,
$noteForm.get(0)
);

$noteForm.find('textarea').atwho({
const addNoteButton = $noteForm.find('button')
const noteTextArea = $noteForm.find('textarea')

addNoteButton.attr('disabled', 'disabled')

noteTextArea.atwho({
at: '@',
data: window.projectView.usernames()
});

noteTextArea.keyup(function() {
if ($.trim(noteTextArea.val())) {
addNoteButton.removeAttr('disabled');
} else {
addNoteButton.attr('disabled', 'disabled');
}
});
}
},

Expand Down Expand Up @@ -839,6 +851,18 @@ module.exports = FormView.extend({
/>,
$taskForm.get(0)
);
const addTaskButton = $taskForm.find('button')
const taskTextArea = $taskForm.find('input')

addTaskButton.attr('disabled', 'disabled')

taskTextArea.keyup(function() {
if ($.trim(taskTextArea.val())) {
addTaskButton.removeAttr('disabled');
} else {
addTaskButton.attr('disabled', 'disabled');
}
});
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ describe('<ExpandedStoryNotes />', () => {
expect(wrapper.find('NotesList')).toExist();
});

it('disables the add note button if text area is empty', ()=>{
const story = { notes: [] };

const wrapper = shallow(
<ExpandedStoryNotes
story={story}
onCreate={onCreate}
onDelete={onDelete}
/>
);

const textArea = wrapper.find('.create-note-text');
const button = wrapper.find('.create-note-button input');

textArea.simulate('change', { target: { value: '' } });
expect(button.prop('disabled')).toBe(true);
});

describe('when user create a new note', () => {
it('triggers the onCreate callback passing the note', () => {
const story = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ describe('<ExpandedStoryTask />', () => {
expect(wrapper.text()).toContain(I18n.t('story.tasks'));
});

it('disables the add task button if text area is empty', ()=>{
const { input } = setup();
const { button } = setup();

input.simulate('change', { target: { value: '' } });
expect(button.prop('disabled')).toBe(true);
});

describe('onHandleSubmit', () => {
it('calls onSave with a task', () => {
const task = 'New Task';
Expand Down
17 changes: 17 additions & 0 deletions spec/javascripts/views/story_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,16 @@ describe('StoryView', function() {
expect(this.view.model.notes.last().isNew()).toBeTruthy();
});

describe("when the text area is empty", function() {

it("disables the add button", function() {
this.view.canEdit = sinon.stub().returns(true);
this.view.render();

expect(this.view.$('.add-note').is(':disabled')).toEqual(true);
});
})

it("doesn't add a blank note if the story is new", function() {
var stub = sinon.stub(this.view.model, 'isNew');
stub.returns(true);
Expand Down Expand Up @@ -484,6 +494,13 @@ describe('StoryView', function() {
expect(this.view.model.tasks.last().isNew()).toBeTruthy();
});

it("disables the add button if the input is empty", function() {
this.view.canEdit = sinon.stub().returns(true);
this.view.render();

expect(this.view.$('.add-task').is(':disabled')).toEqual(true);
});

it("doesn't add a blank task if the story is new", function() {
var stub = sinon.stub(this.view.model, 'isNew');
stub.returns(true);
Expand Down

0 comments on commit c2adad0

Please sign in to comment.