summaryrefslogtreecommitdiff
path: root/spec/javascripts/shortcuts_issuable_spec.js
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-01-17 13:07:20 -0500
committerDouwe Maan <douwe@selenight.nl>2017-01-17 13:07:20 -0500
commit6089ece09860e99528932ef574086c113ec08ae7 (patch)
treeaf6986e494ac7261f7010718b87c353eece006a0 /spec/javascripts/shortcuts_issuable_spec.js
parent72620ea1b725f8776087e516cdc3dd13f5f8e075 (diff)
downloadgitlab-ce-6089ece09860e99528932ef574086c113ec08ae7.tar.gz
Fix ShortcutsIssuable#replyWithSelectedText tests
Diffstat (limited to 'spec/javascripts/shortcuts_issuable_spec.js')
-rw-r--r--spec/javascripts/shortcuts_issuable_spec.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/spec/javascripts/shortcuts_issuable_spec.js b/spec/javascripts/shortcuts_issuable_spec.js
index ae5d639ad9c..7e5c0e2f144 100644
--- a/spec/javascripts/shortcuts_issuable_spec.js
+++ b/spec/javascripts/shortcuts_issuable_spec.js
@@ -1,6 +1,7 @@
/* eslint-disable space-before-function-paren, no-return-assign, no-var, quotes, padded-blocks */
/* global ShortcutsIssuable */
+/*= require copy_as_gfm */
/*= require shortcuts_issuable */
(function() {
@@ -14,10 +15,12 @@
});
return describe('#replyWithSelectedText', function() {
var stubSelection;
- // Stub window.getSelection to return the provided String.
- stubSelection = function(text) {
- return window.getSelection = function() {
- return text;
+ // Stub window.gl.CopyAsGFM.getSelectedFragment to return a node with the provided HTML.
+ stubSelection = function(html) {
+ window.gl.CopyAsGFM.getSelectedFragment = function() {
+ var node = document.createElement('div');
+ node.innerHTML = html;
+ return node;
};
};
beforeEach(function() {
@@ -32,13 +35,13 @@
});
describe('with any selection', function() {
beforeEach(function() {
- return stubSelection('Selected text.');
+ return stubSelection('<p>Selected text.</p>');
});
it('leaves existing input intact', function() {
$(this.selector).val('This text was already here.');
expect($(this.selector).val()).toBe('This text was already here.');
this.shortcut.replyWithSelectedText();
- return expect($(this.selector).val()).toBe("This text was already here.\n> Selected text.\n\n");
+ return expect($(this.selector).val()).toBe("This text was already here.\n\n> Selected text.\n\n");
});
it('triggers `input`', function() {
var triggered;
@@ -61,16 +64,16 @@
});
describe('with a one-line selection', function() {
return it('quotes the selection', function() {
- stubSelection('This text has been selected.');
+ stubSelection('<p>This text has been selected.</p>');
this.shortcut.replyWithSelectedText();
return expect($(this.selector).val()).toBe("> This text has been selected.\n\n");
});
});
return describe('with a multi-line selection', function() {
return it('quotes the selected lines as a group', function() {
- stubSelection("Selected line one.\n\nSelected line two.\nSelected line three.\n");
+ stubSelection("<p>Selected line one.</p>\n\n<p>Selected line two.</p>\n\n<p>Selected line three.</p>");
this.shortcut.replyWithSelectedText();
- return expect($(this.selector).val()).toBe("> Selected line one.\n> Selected line two.\n> Selected line three.\n\n");
+ return expect($(this.selector).val()).toBe("> Selected line one.\n>\n> Selected line two.\n>\n> Selected line three.\n\n");
});
});
});