summaryrefslogtreecommitdiff
path: root/spec/frontend/content_editor/extensions/image_spec.js
blob: f73b0143fd937f85c264127a1f88d68461d44856 (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"></p>',
    );
  });
});