Skip to content

Commit

Permalink
Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tavinathanson committed Mar 25, 2015
1 parent f6e0a14 commit 2d190e8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 45 deletions.
20 changes: 8 additions & 12 deletions cycledash/static/js/examine/components/CommentBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var VCFComment = React.createClass({
},
getInitialState: function() {
return {commentText: this.props.commentText,
isEdit: this.props.defaultEditState};
isEditing: this.props.defaultEditState};
},
setCommentTextState: function(commentText) {
// If passed no value, setCommentTextState resets the commentText.
Expand All @@ -203,14 +203,14 @@ var VCFComment = React.createClass({
this.setState({commentText: commentText});
},
setDefaultEditState: function() {
this.setState({isEdit: this.props.defaultEditState});
this.setState({isEditing: this.props.defaultEditState});
},
setEditState: function(isEdit) {
this.setState({isEdit: isEdit});
setEditState: function(isEditing) {
this.setState({isEditing: isEditing});
},

makeEditable: function() {
this.setState({isEdit: true});
this.setState({isEditing: true});
},
componentDidUpdate: function(prevProps, prevState) {
if (prevProps.commentText !==
Expand All @@ -222,16 +222,12 @@ var VCFComment = React.createClass({
var placeHolder = 'Enter your comment here';
// Only use "Anonymous" in the viewer; the editor should just be
// blank in that case.
var authorNameOrAnonymous = this.props.authorName ?
this.props.authorName :
'Anonymous';
var authorNameOrBlank = this.props.authorName ?
this.props.authorName :
'';
var authorNameOrAnonymous = this.props.authorName || 'Anonymous';
var authorNameOrBlank = this.props.authorName || '';

// handleDelete is optional, but not providing it requires the
// edit view.
var commentElement = (this.state.isEdit || !this.props.handleDelete) ?
var commentElement = (this.state.isEditing || !this.props.handleDelete) ?
<VCFCommentEditor commentText={this.props.commentText}
authorName={authorNameOrBlank}
saveLocalAuthorName={this.props.saveLocalAuthorName}
Expand Down
1 change: 0 additions & 1 deletion tests/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ SET search_path = public, pg_catalog;
COPY projects (id, name, notes) FROM stdin;
1 PT 5656 This is a project. This is a note.
2 Noteless \N
3 TEST PROJECT \N
\.


Expand Down
10 changes: 1 addition & 9 deletions tests/js/CommentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,7 @@ function getCommentIdFromPath(path) {
// however our HTTP GET response needs to key comments by row key (as is
// done in comments.py).
function getCommentResponse(commentDatabase) {
var obj = {};
_.each(commentDatabase, comment => {
var rowKey = utils.getRowKey(comment);
if (!_.has(obj, rowKey)) {
obj[rowKey] = [];
}
obj[rowKey].push(comment);
});
return {comments: obj};
return {comments: _.groupBy(commentDatabase, utils.getRowKey)};
}

function isFailingPath(type, path, failingPaths) {
Expand Down
51 changes: 28 additions & 23 deletions tests/js/ExaminePage-comments-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('ExaminePage Comments', function() {
created_at: '',
uri: '/tests/js/data/snv.vcf'
};
var igvHttpfsUrl = 'http://example.com/';
var igvHttpfsUrl = 'http://example.com/';

var dispatcher = new Dispatcher();
var recordActions = RecordActions.getRecordActions(dispatcher);
Expand All @@ -59,21 +59,23 @@ describe('ExaminePage Comments', function() {
vcf={run} comparableVcfs={[]} />);
}

// Get text for the nth comment (0-indexed) in the row
function commentText(n) {
if (_.isUndefined(n)) {
n = 1;
n = 0;
}

var comments = Utils.findInComponent(
'.vcf-table .variant-info div p', examine);
assert.ok(comments.length >= n || comments.length === 0);
return comments.length >= n ? comments[n - 1].textContent : null;
'.vcf-table .variant-info div p', examine);
assert.ok(comments.length > n || comments.length === 0);
return comments.length > n ? comments[n].textContent : null;
}

// Click the nth row (0-indexed)
function clickRow(n) {
var rows = Utils.findInComponent('.vcf-table tbody tr', examine);
assert.ok(rows.length >= n);
TestUtils.Simulate.click(rows[n - 1]);
assert.ok(rows.length > n);
TestUtils.Simulate.click(rows[n]);
}

// Initially, to ensure that indexing into <tr> elements is valid, make
Expand All @@ -83,9 +85,11 @@ describe('ExaminePage Comments', function() {
clickRow(n);
}

// Click the button with buttonText for the nth comment (0-indexed)
// in the row
function clickCommentButton(buttonText, n) {
if (_.isUndefined(n)) {
n = 1;
n = 0;
}

var buttons = Utils.findInComponent(
Expand All @@ -94,19 +98,20 @@ describe('ExaminePage Comments', function() {
var buttonsWithText = buttons.filter(function(button) {
return button.textContent === buttonText;
});
assert.ok(buttonsWithText.length >= n);
TestUtils.Simulate.click(buttonsWithText[n - 1]);
assert.ok(buttonsWithText.length > n);
TestUtils.Simulate.click(buttonsWithText[n]);
}

// Change the comment text for the nth comment (0-indexed) in the row
function changeCommentText(commentText, n) {
if (_.isUndefined(n)) {
n = 1;
n = 0;
}

var textAreas = Utils.findInComponent(
'.vcf-table .variant-info div textarea', examine);
assert.ok(textAreas.length >= n);
TestUtils.Simulate.change(textAreas[n - 1], {target: {value: commentText}});
assert.ok(textAreas.length > n);
TestUtils.Simulate.change(textAreas[n], {target: {value: commentText}});
}

function getNumComments() {
Expand All @@ -133,26 +138,26 @@ describe('ExaminePage Comments', function() {
assert.equal(null, commentText());

// Click on the records with comments.
resetAndClickRow(1);
resetAndClickRow(0);
assert.equal('First', commentText());
assert.equal('Another First', commentText(2));
resetAndClickRow(3);
assert.equal('Another First', commentText(1));
resetAndClickRow(2);
assert.equal('Second', commentText());
resetAndClickRow(10);
resetAndClickRow(9);
assert.equal('Third', commentText());

// Click on a record without a comment.
resetAndClickRow(2);
resetAndClickRow(1);
assert.equal(null, commentText());

// Select and deselect a record.
resetAndClickRow(1);
resetAndClickRow(0);
assert.equal('First', commentText());
clickRow(1);
clickRow(0);
assert.equal(null, commentText());

// Edit the second comment, save it, and check that the fake DB was updated.
resetAndClickRow(3);
resetAndClickRow(2);
assert.equal('Second', commentText());
clickCommentButton('Edit');
changeCommentText('Edited Comment');
Expand Down Expand Up @@ -190,7 +195,7 @@ describe('ExaminePage Comments', function() {

// Edit the second comment, save it, and check that the fake DB was *not*
// updated. Then try to delete it.
resetAndClickRow(3);
resetAndClickRow(2);
assert.equal('Second', commentText());
clickCommentButton('Edit');
changeCommentText('Edited Comment');
Expand All @@ -206,7 +211,7 @@ describe('ExaminePage Comments', function() {
// Make a new comment, save it, and check that the fake DB was *not*
// updated. (We can't delete it, because the comment will revert
// to edit mode, which doesn't have "Delete".)
resetAndClickRow(4);
resetAndClickRow(3);
assert.equal(null, commentText());
changeCommentText('New Comment');
clickCommentButton('Save');
Expand Down
Binary file modified tests/pdifftests/images/examine_comments-edit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pdifftests/images/examine_comments-view.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pdifftests/images/runs_bams.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pdifftests/images/runs_info.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pdifftests/images/runs_page.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/pdifftests/images/website_comments.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d190e8

Please sign in to comment.