schlechtenburg/packages/rich-text/lib/test/get-active-object.test.ts
2024-10-08 09:15:26 +02:00

39 lines
948 B
TypeScript

import { describe, expect, it } from 'vitest'
import { getActiveObject } from '../get-active-object';
import { OBJECT_REPLACEMENT_CHARACTER } from '../special-characters';
describe( 'getActiveObject', () => {
it( 'should return object if selected', () => {
const record = {
replacements: [ { type: 'img' } ],
text: OBJECT_REPLACEMENT_CHARACTER,
start: 0,
end: 1,
};
expect( getActiveObject( record ) ).toEqual( { type: 'img' } );
} );
it( 'should return nothing if nothing is selected', () => {
const record = {
replacements: [ { type: 'img' } ],
text: OBJECT_REPLACEMENT_CHARACTER,
start: 0,
end: 0,
};
expect( getActiveObject( record ) ).toBe( undefined );
} );
it( 'should return nothing if te selection is not an object', () => {
const record = {
replacements: [ { type: 'em' } ],
text: 'a',
start: 0,
end: 1,
};
expect( getActiveObject( record ) ).toBe( undefined );
} );
} );