summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinnie Hellmann <winnie@gitlab.com>2018-10-09 13:20:48 +0200
committerWinnie Hellmann <winnie@gitlab.com>2018-10-09 14:14:37 +0200
commita6744b516197ace895d51bc84e3827bc9a3ea021 (patch)
tree37c2a32ca0de053a8eaa94c358d62098fdadfcb1
parent8d65c381d71dcc2768edfb2f727d0378b616ad0a (diff)
downloadgitlab-ce-winh-jest.tar.gz
Port spec/javascripts/behaviors/copy_as_gfm_spec.js to Jestwinh-jest
-rw-r--r--spec/frontend/behaviors/copy_as_gfm_spec.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/frontend/behaviors/copy_as_gfm_spec.js b/spec/frontend/behaviors/copy_as_gfm_spec.js
new file mode 100644
index 00000000000..bacd44830f2
--- /dev/null
+++ b/spec/frontend/behaviors/copy_as_gfm_spec.js
@@ -0,0 +1,55 @@
+import $ from 'jquery';
+import initCopyAsGFM, { CopyAsGFM } from '~/behaviors/markdown/copy_as_gfm';
+import { setHTMLFixture } from 'helpers/fixtures';
+
+describe('CopyAsGFM', () => {
+ describe('initCopyAsGFM', () => {
+ beforeEach(() => {
+ jest.spyOn(CopyAsGFM, 'copyAsGFM').mockImplementation(() => {});
+ jest.spyOn(CopyAsGFM, 'pasteGFM').mockImplementation(() => {});
+ setHTMLFixture(`
+ <div class="md"></div>
+ <div class="wiki"></div>
+ <pre class="code highlight"></pre>
+ <div class="diff-content"><div class="line_content"></div></div>
+ <div class="js-gfm-input"></div>
+ `);
+
+ initCopyAsGFM();
+ });
+
+ afterEach(() => {
+ $(document).off('copy');
+ $(document).off('paste');
+ });
+
+ it.each`
+ selector | expectedTransform
+ ${'.md'} | ${CopyAsGFM.transformGFMSelection}
+ ${'.wiki'} | ${CopyAsGFM.transformGFMSelection}
+ ${'pre.code.highlight'} | ${CopyAsGFM.transformCodeSelection}
+ ${'.diff-content .line_content'} | ${CopyAsGFM.transformCodeSelection}
+ `(
+ 'calls copyAsGFM with $expectedTransform.name for copy event on $selector',
+ ({ selector, expectedTransform }) => {
+ const copyEvent = $.Event('copy');
+ const $element = $(selector);
+ expect($element.length).toBe(1);
+
+ $element.trigger(copyEvent);
+
+ expect(CopyAsGFM.copyAsGFM).toHaveBeenCalledWith(copyEvent, expectedTransform);
+ },
+ );
+
+ it('calls pasteGFM for paste event on .js-gfm-input', () => {
+ const pasteEvent = $.Event('paste');
+ const $element = $('.js-gfm-input');
+ expect($element.length).toBe(1);
+
+ $element.trigger(pasteEvent);
+
+ expect(CopyAsGFM.pasteGFM).toHaveBeenCalledWith(pasteEvent);
+ });
+ });
+});