]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/lexical/rich-text/__tests__/unit/LexicalMediaNode.test.ts
Merge pull request #5917 from BookStackApp/copy_references
[bookstack] / resources / js / wysiwyg / lexical / rich-text / __tests__ / unit / LexicalMediaNode.test.ts
1 import {createTestContext} from "lexical/__tests__/utils";
2 import {$createMediaNode} from "@lexical/rich-text/LexicalMediaNode";
3
4
5 describe('LexicalMediaNode', () => {
6
7     test('setWidth/setHeight/setWidthAndHeight functions remove relevant styles', () => {
8         const {editor} = createTestContext();
9         editor.updateAndCommit(() => {
10             const mediaMode = $createMediaNode('video');
11             const defaultStyles = {style: 'width:20px;height:40px;color:red'};
12
13             mediaMode.setAttributes(defaultStyles);
14             mediaMode.setWidth(60);
15             expect(mediaMode.getWidth()).toBe(60);
16             expect(mediaMode.getAttributes().style).toBe('height:40px;color:red');
17
18             mediaMode.setAttributes(defaultStyles);
19             mediaMode.setHeight(77);
20             expect(mediaMode.getHeight()).toBe(77);
21             expect(mediaMode.getAttributes().style).toBe('width:20px;color:red');
22
23             mediaMode.setAttributes(defaultStyles);
24             mediaMode.setWidthAndHeight('6', '7');
25             expect(mediaMode.getWidth()).toBe(6);
26             expect(mediaMode.getHeight()).toBe(7);
27             expect(mediaMode.getAttributes().style).toBe('color:red');
28         });
29     });
30
31     test('setSrc on video uses sources if existing', () => {
32         const {editor} = createTestContext();
33         editor.updateAndCommit(() => {
34             const mediaMode = $createMediaNode('video');
35             mediaMode.setAttributes({src: 'z'});
36             mediaMode.setSources([{src: 'a', type: 'video'}, {src: 'b', type: 'video'}]);
37
38             mediaMode.setSrc('c');
39
40             expect(mediaMode.getAttributes().src).toBeUndefined();
41             expect(mediaMode.getSources()).toHaveLength(1);
42             expect(mediaMode.getSources()[0].src).toBe('c');
43         });
44     });
45
46 });