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

remove old JS markdown tests, add a new one in selenium #5497

Merged
merged 3 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 0 additions & 98 deletions notebook/tests/notebook/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,112 +3,14 @@
//
casper.notebook_test(function () {
"use strict";
// Test JavaScript models.
var output = this.evaluate(function () {
IPython.notebook.to_markdown();
var cell = IPython.notebook.get_selected_cell();
cell.set_text('# Foo');
cell.render();
return cell.get_rendered();
});
this.test.assertEquals(output.trim(), '<h1 id=\"Foo\">Foo<a class=\"anchor-link\" href=\"#Foo\">¶</a></h1>', 'Markdown JS API works.');

// Test menubar entries.
output = this.evaluate(function () {
$('#to_code').mouseenter().click();
$('#to_markdown').mouseenter().click();
var cell = IPython.notebook.get_selected_cell();
cell.set_text('**Bar**');
$('#run_cell').mouseenter().click();
return cell.get_rendered();
});
this.test.assertEquals(output.trim(), '<p><strong>Bar</strong></p>', 'Markdown menubar items work.');

// Test toolbar buttons.
output = this.evaluate(function () {
$('#cell_type').val('code').change();
$('#cell_type').val('markdown').change();
var cell = IPython.notebook.get_selected_cell();
cell.set_text('*Baz*');
$("button[data-jupyter-action='jupyter-notebook:run-cell-and-select-next']")[0].click();
return cell.get_rendered();
});
this.test.assertEquals(output.trim(), '<p><em>Baz</em></p>', 'Markdown toolbar items work.');

// Test markdown headings

var text = 'multi\nline';

this.evaluate(function (text) {
var cell = IPython.notebook.insert_cell_at_index('markdown', 0);
cell.set_text(text);
}, {text: text});

var set_level = function (level) {
return casper.evaluate(function (level) {
var cell = IPython.notebook.get_cell(0);
cell.set_heading_level(level);
return cell.get_text();
}, {level: level});
};

var level_text;
var levels = [ 1, 2, 3, 4, 5, 6, 2, 1 ];
for (var idx=0; idx < levels.length; idx++) {
var level = levels[idx];
level_text = set_level(level);
var hashes = new Array(level + 1).join('#');
this.test.assertEquals(level_text, hashes + ' ' + text, 'markdown set_heading_level ' + level);
}

// Test markdown code blocks


function md_render_test (codeblock, result, message) {
// make a cell and trigger render
casper.thenEvaluate(function (text) {
var cell = Jupyter.notebook.insert_cell_at_bottom('markdown');
cell.set_text(text);
// signal window._rendered when cell render completes
window._rendered = null;
cell.events.one("rendered.MarkdownCell", function (event, data) {
window._rendered = data.cell.get_rendered();
});
cell.render();
}, {text: codeblock});
// wait for render to complete
casper.waitFor(function () {
return casper.evaluate(function () {
return window._rendered;
});
});
// test after waiting
casper.then(function () {
// get rendered result
var output = casper.evaluate(function () {
var rendered = window._rendered;
delete window._rendered;
return rendered;
});
// perform test
this.test.assertEquals(output.trim(), result, message);
});
};

var codeblock = '```\nx = 1\n```'
var result = '<pre><code>x = 1</code></pre>'
md_render_test(codeblock, result, 'Markdown code block no language');

codeblock = '```aaaa\nx = 1\n```'
result = '<pre><code class="cm-s-ipython language-aaaa">x = 1</code></pre>'
md_render_test(codeblock, result, 'Markdown code block unknown language');

codeblock = '```python\ns = "$"\nt = "$"\n```'
result = '<pre><code class="cm-s-ipython language-python">' +
'<span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span>\n' +
'<span class="cm-variable">t</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span></code></pre>';
md_render_test(codeblock, result, 'Markdown code block python');

function mathjax_render_test(input_string, result, message){
casper.thenEvaluate(function (text){
window._test_result = null;
Expand Down
17 changes: 17 additions & 0 deletions notebook/tests/selenium/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def get_rendered_contents(nb):
def test_markdown_cell(prefill_notebook):
nb = prefill_notebook([new_markdown_cell(md) for md in [
'# Foo', '**Bar**', '*Baz*', '```\nx = 1\n```', '```aaaa\nx = 1\n```',
'```python\ns = "$"\nt = "$"\n```'
]])

assert get_rendered_contents(nb) == [
Expand All @@ -21,4 +22,20 @@ def test_markdown_cell(prefill_notebook):
'<p><em>Baz</em></p>',
'<pre><code>x = 1</code></pre>',
'<pre><code class="cm-s-ipython language-aaaa">x = 1</code></pre>',
'<pre><code class="cm-s-ipython language-python">' +
'<span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span>\n' +
'<span class="cm-variable">t</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span></code></pre>'
]

def test_markdown_headings(notebook):
lst = list([1, 2, 3, 4, 5, 6, 2, 1])
for i in lst:
notebook.add_markdown_cell()
cell_text = notebook.browser.execute_script(f"""
var cell = IPython.notebook.get_cell(1);
cell.set_heading_level({i});
cell.get_text();
""")
assert notebook.get_cell_contents(1) == "#" * i + " "
notebook.delete_cell(1)