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

copy_as_gfm_spec.js « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ded450749d33c9bf86d9caae8bffae5db4d31fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import '~/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();
      });
    });
  });
})();