1 import {createTestContext} from "lexical/__tests__/utils";
2 import {$createMediaNode} from "@lexical/rich-text/LexicalMediaNode";
5 describe('LexicalMediaNode', () => {
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'};
13 mediaMode.setAttributes(defaultStyles);
14 mediaMode.setWidth(60);
15 expect(mediaMode.getWidth()).toBe(60);
16 expect(mediaMode.getAttributes().style).toBe('height:40px;color:red');
18 mediaMode.setAttributes(defaultStyles);
19 mediaMode.setHeight(77);
20 expect(mediaMode.getHeight()).toBe(77);
21 expect(mediaMode.getAttributes().style).toBe('width:20px;color:red');
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');
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'}]);
38 mediaMode.setSrc('c');
40 expect(mediaMode.getAttributes().src).toBeUndefined();
41 expect(mediaMode.getSources()).toHaveLength(1);
42 expect(mediaMode.getSources()[0].src).toBe('c');