diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-05-24 13:02:17 +0300 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-05-24 13:02:17 +0300 |
commit | b39b02d4a422ca240916a28bb4600a3a741b6194 (patch) | |
tree | 929cad643e3bc8dc8585578237bded93a83b2972 /spec | |
parent | 4c78eff2e32ce09fb9d0bc87e89a321b795543c2 (diff) | |
parent | 6127192783171f6fc2b64c674dd21d0544b62707 (diff) |
Merge branch 'dm-paste-code-inside-gfm-code' into 'master'
Don't wrap pasted code when it's already inside code tags
Closes #32507
See merge request !11524
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/copy_as_gfm_spec.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/javascripts/copy_as_gfm_spec.js b/spec/javascripts/copy_as_gfm_spec.js new file mode 100644 index 00000000000..1a850bb56ab --- /dev/null +++ b/spec/javascripts/copy_as_gfm_spec.js @@ -0,0 +1,49 @@ +require('~/copy_as_gfm'); + +(() => { + describe('gl.CopyAsGFM', () => { + describe('gl.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() {}, + }; + + window.gl.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(); + }); + }); + }); +})(); |