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

image_spec.js « extensions « content_editor « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 256f7bad309e612447ff530c4b10f055679e4a88 (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
import Image from '~/content_editor/extensions/image';
import { createTestEditor, createDocBuilder } from '../test_utils';

describe('content_editor/extensions/image', () => {
  let tiptapEditor;
  let doc;
  let p;
  let image;

  beforeEach(() => {
    tiptapEditor = createTestEditor({ extensions: [Image] });

    ({
      builders: { doc, p, image },
    } = createDocBuilder({
      tiptapEditor,
      names: {
        image: { nodeType: Image.name },
      },
    }));
  });

  it('adds data-canonical-src attribute when rendering to HTML', () => {
    const initialDoc = doc(
      p(
        image({
          canonicalSrc: 'uploads/image.jpg',
          src: '/-/wikis/uploads/image.jpg',
          alt: 'image',
          title: 'this is an image',
        }),
      ),
    );

    tiptapEditor.commands.setContent(initialDoc.toJSON());

    expect(tiptapEditor.getHTML()).toEqual(
      '<p><img src="/-/wikis/uploads/image.jpg" alt="image" title="this is an image" data-canonical-src="uploads/image.jpg"></p>',
    );
  });
});