Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-10-13 00:31:47 +0300
committerMike Greiling <mike@pixelcog.com>2017-11-01 20:59:35 +0300
commitb356997ab3d3b526da58d18da249aeeb15c75f0b (patch)
tree5aba6501ff61ce8a0575a64818a081b1e603a513 /spec/javascripts/behaviors
parent9fd89990613b765af8b7518ff8fb8579f5a529e1 (diff)
remove global export except in test environments
Diffstat (limited to 'spec/javascripts/behaviors')
-rw-r--r--spec/javascripts/behaviors/copy_as_gfm_spec.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/javascripts/behaviors/copy_as_gfm_spec.js b/spec/javascripts/behaviors/copy_as_gfm_spec.js
new file mode 100644
index 00000000000..b8155144e2a
--- /dev/null
+++ b/spec/javascripts/behaviors/copy_as_gfm_spec.js
@@ -0,0 +1,47 @@
+import { CopyAsGFM } from '~/behaviors/copy_as_gfm';
+
+describe('CopyAsGFM', () => {
+ describe('CopyAsGFM.pasteGFM', () => {
+ function callPasteGFM() {
+ const e = {
+ originalEvent: {
+ clipboardData: {
+ getData(mimeType) {
+ // When GFM code is copied, we put the regular plain text
+ // on the clipboard as `text/plain`, and the GFM as `text/x-gfm`.
+ // This emulates the behavior of `getData` with that data.
+ if (mimeType === 'text/plain') {
+ return 'code';
+ }
+ if (mimeType === 'text/x-gfm') {
+ return '`code`';
+ }
+ return null;
+ },
+ },
+ },
+ preventDefault() {},
+ };
+
+ CopyAsGFM.pasteGFM(e);
+ }
+
+ it('wraps pasted code when not already in code tags', () => {
+ spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
+ const insertedText = textFunc('This is code: ', '');
+ expect(insertedText).toEqual('`code`');
+ });
+
+ callPasteGFM();
+ });
+
+ it('does not wrap pasted code when already in code tags', () => {
+ spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
+ const insertedText = textFunc('This is code: `', '`');
+ expect(insertedText).toEqual('code');
+ });
+
+ callPasteGFM();
+ });
+ });
+});