Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dual mode JS tests #5290

Merged
merged 38 commits into from Mar 27, 2014
Merged

Add dual mode JS tests #5290

merged 38 commits into from Mar 27, 2014

Conversation

jdfreder
Copy link
Member

@jdfreder jdfreder commented Mar 7, 2014

This PR adds 403 tests for the notebook's new dual mode.

how it works

After each action, the states of the notebook cells, code mirror instances, notebook, and keyboard manager are all verified as the expected results.

closes #4887

@ellisonbg
Copy link
Member

Other things to test:

  • shift+enter, ctrl+enter, alt+enter when the cell i) is the last one in the notebook, ii) is not the last one in the notebook, iii) when the cell starts out in edit mode and iv) when the cell starts out in command mode.
  • To code cell: y
  • Markdown cell: to and from, render using *+enter, to and from edit mode in both rendered+unrendered state.
  • Raw cell: to (r)
  • up/k: test in edit mode as well, at the top/bottom line of the edit cell it should jump to the next/prev cell and put it in edit mode.
  • down/j: same
  • ctrl+k: moving cells up/down should focus them.
  • ctrl+j: same
  • a
  • b
  • x/c/v/shift+v/z: various combinations of cut/copy/paste/undo
  • d: delete cell
  • split/merge above&below: very careful about which cell is selected and what its mode is in (it depends on the mode of the original cell).



// Utility functions.
this.validate_state = function(message, mode, cell_index) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this into utils.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's actually move most of these utility function to utils.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some tests, especially those involving markdown or heading cells, we should test the rendered state as well.

@ellisonbg
Copy link
Member

Closes #4887

@jdfreder
Copy link
Member Author

  • shift+enter, ctrl+enter, alt+enter when the cell i) is the last one in the notebook, ii) is not the last one in the notebook, iii) when the cell starts out in edit mode and iv) when the cell starts out in command mode.
  • To code cell: y
  • Raw cell: to (r)
  • d: delete cell
  • k: test in edit mode as well, at the top/bottom line of the edit cell it should jump to the next/prev cell and put it in edit mode.
  • j: same
  • up: test in edit mode as well, at the top/bottom line of the edit cell it should jump to the next/prev cell and put it in edit mode.
  • down: same
  • Markdown cell: to and from, render using *+enter, to and from edit mode in both rendered+unrendered state.
  • ctrl+k: moving cells up/down should focus them.
  • ctrl+j: same
  • a
  • b
  • x/c/v/shift+v/z: various combinations of cut/copy/paste/undo
  • split/merge above&below: very careful about which cell is selected and what its mode is in (it depends on the mode of the original cell).

@jdfreder
Copy link
Member Author

@ellisonbg I've implemented all of the things you mentioned here and that we talked about in person, it's ready for another review. I think the only other thing I need to do before merge is add some comments to the new util.js methods.

@jdfreder
Copy link
Member Author

Ahh and I forgot to mention, I removed the arrow keys test since the dualmode_arrows.js tests the exact same thing in much greater detail.

@minrk
Copy link
Member

minrk commented Mar 12, 2014

Can you remove the unused IPython.keyboard.trigger_keydown in this PR? It looks like you redefined the method where it belongs, in the test utils.

@jdfreder
Copy link
Member Author

Can you remove the unused IPython.keyboard.trigger_keydown in this PR? It looks like you redefined the method where it belongs, in the test utils.

Yup, went ahead and removed it... Also jshinted the file since I was touching it anyways.

};

// Emulate a keydown in the notebook.
casper.trigger_keydown = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because casper.trigger_keydown has to rely on calls to IPython.keyboard... and basically has to reimplement the logic of IPython.keyboard.trigger_keydown I actually think it makes sense to put IPython.keyboard.trigger_keydown back into place. If the casper.trigger_keydown version didn't need to make calls back into al the stuff in keyboard I would feel differently, but in this case I think this refactoring makes it less clear. Are you OK with this @minrk ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. IPython.keyboard.trigger_keydown never made sense - it is a utility exclusively for testing, so its definition belongs in tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine.

@ellisonbg
Copy link
Member

Only minor changes needed.

@jdfreder
Copy link
Member Author

Changes addressed

@@ -9,7 +10,10 @@ casper.notebook_test(function() {
var cell_one = IPython.notebook.get_selected_cell();
cell_one.set_text('a = 5');

IPython.keyboard.trigger_keydown('b');
var element = $(document);
var event = IPython.keyboard.shortcut_to_event('b', 'keydown');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use this.trigger_keydown here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without rewriting the entire test since it's nested in an evaluate... But that's okay, I think it makes more sense to rewrite the test.

@ellisonbg
Copy link
Member

This looks good, but I am seeing a test failure:

Test file: /Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/html/tests/notebook/tooltip.js
PASS tooltip token: C
PASS tooltip token: MyClass
PASS tooltip token: foo123
FAIL 530 tests executed in 104.283s, 529 passed, 1 failed, 0 dubious, 0 skipped.

Details for the 1 failed test:

In /Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/html/tests/notebook/dualmode_arrows.js:41
  Untitled suite in /Users/bgranger/Documents/Computing/IPython/code/ipython/IPython/html/tests/notebook/dualmode_arrows.js
    assert: up; cell 2 is the only cell selected

@jdfreder
Copy link
Member Author

a test failure

That particular failure is very concerning because it means you've encountered a situation where two cells are selected at once. 😦

@jdfreder
Copy link
Member Author

@ellisonbg here is the human reproducable steps performed by the failing test. Can you try these and see if you can break your notebook's state?

Start in a notebook with four code cells, all executed, the first one left blank:

cell 2

print("a")

cell 3

print("b")

cell 4

print("c")

Select the last cell by clicking on it.
Click escape to enter command mode.
Hit this sequence of keys: j, down, up

Select the first cell by clicking on it.
Click escape to enter command mode.
Hit this sequence of keys: k, up, down

Select the last cell by clicking on it.
Stay in edit mode.
Hit this sequence of keys: down, up

FAILURE HERE

The test continues to try some more things...

@ellisonbg
Copy link
Member

Tests pass for me locally, once Travis passes, lets merge.

@@ -262,8 +262,7 @@ IPython.keyboard = (function (IPython) {
normalize_key : normalize_key,
normalize_shortcut : normalize_shortcut,
shortcut_to_event : shortcut_to_event,
event_to_shortcut : event_to_shortcut,
trigger_keydown : trigger_keydown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you removed the export here, but not the actual function itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with trigger_keydown being removed from here, but definitely think that event_to_shortcut should stay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, nevermind, it is still here...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mention anything about event_to_shortcut; that's actually used in the code. Just pointing out that trigger_keydown has just been made unreachable here, but the actual definition is what should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was the result of a bad rebase...

@jdfreder
Copy link
Member Author

I re-removed the trigger keydown method... It was un-removed during a bad rebase. erg

@@ -210,7 +201,7 @@ IPython.keyboard = (function (IPython) {
if (!suppress_help_update) {
// update the keyboard shortcuts notebook help
$([IPython.events]).trigger('rebuild.QuickHelp');
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these indentation changes are not correct

@jdfreder
Copy link
Member Author

I just fixed the broken indents

@ellisonbg ellisonbg added this to the 2.0 milestone Mar 26, 2014
@takluyver
Copy link
Member

In the dev meeting, we seemed to think this is ready to merge. Is there anything else we want to do/review with it before I press the green button?

@minrk
Copy link
Member

minrk commented Mar 27, 2014

Don't think so.

takluyver added a commit that referenced this pull request Mar 27, 2014
@takluyver takluyver merged commit 78455ba into ipython:master Mar 27, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for modal UI
4 participants