Skip to content

Commit

Permalink
remove unneeded changes and improve name of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanValverdeU committed Apr 4, 2024
1 parent 2fd8242 commit ce82f11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
ParsedTable,
TableSelectionInfo,
TableCellCoordinate,
RangeSelection,
} from 'roosterjs-content-model-types';

const MouseLeftButton = 0;
Expand Down Expand Up @@ -257,8 +258,7 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
private onKeyDown(editor: IEditor, rawEvent: KeyboardEvent) {
const key = rawEvent.key;
const selection = editor.getDOMSelection();
const doc = editor.getDocument();
const win = doc.defaultView;
const win = editor.getDocument().defaultView;

switch (selection?.type) {
case 'image':
Expand Down Expand Up @@ -617,8 +617,8 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
}
}

private trySelectSingleImage(selection: DOMSelection) {
if (selection?.type == 'range' && !selection.range.collapsed) {
private trySelectSingleImage(selection: RangeSelection) {
if (!selection.range.collapsed) {
const image = isSingleImageInSelection(selection.range);
if (image) {
this.selectImage(image, selection.isReverted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,7 @@ describe('isSingleImageInSelection |', () => {
expect(result).toBeNull();
});

it('Is not single image in Selection: Containers are not the same', () => {
const focusNode: any = {};
const anchorNode: any = { test: '' };
const selection: any = <Partial<Selection>>{
focusNode,
anchorNode,
focusOffset: 0,
anchorOffset: 1,
getRangeAt: () => <any>{},
};

const result = isSingleImageInSelection(selection);

expect(result).toBeNull();
});

it('Is not single image in Selection: Element is not the same', () => {
it('Is not single image in Selection: Element is not image', () => {
const mockedElement = document.createElement('div');
const focusNode: any = <Partial<Node>>{
childNodes: <any>{
Expand All @@ -69,26 +53,6 @@ describe('isSingleImageInSelection |', () => {
expect(result).toBeNull();
});

it('Is not single image in Selection: Element is not the element', () => {
const mockedElement = document.createTextNode('div');
const focusNode: any = <Partial<Node>>{
childNodes: <any>{
item: () => mockedElement,
},
};
const selection: any = <Partial<Selection>>{
focusNode,
anchorNode: focusNode,
focusOffset: 0,
anchorOffset: 1,
getRangeAt: () => <any>{},
};

const result = isSingleImageInSelection(selection);

expect(result).toBeNull();
});

it('Is single image in selection', () => {
const mockedElement = document.createElement('img');
const focusNode: any = <Partial<Node>>{
Expand Down Expand Up @@ -140,22 +104,7 @@ describe('isSingleImageInSelection |', () => {
expect(result).toBeNull();
});

it('Is not single image in Selection: Containers are not the same', () => {
const endContainer: any = {};
const startContainer: any = { test: '' };
const selection: any = <Partial<Range>>{
endContainer,
startContainer,
endOffset: 0,
startOffset: 1,
};

const result = isSingleImageInSelection(selection);

expect(result).toBeNull();
});

it('Is not single image in Selection: Element is not the same', () => {
it('Is not single image in Selection: Element is not image', () => {
const mockedElement = document.createElement('div');
const endContainer: any = <Partial<Node>>{
childNodes: <any>{
Expand All @@ -174,25 +123,6 @@ describe('isSingleImageInSelection |', () => {
expect(result).toBeNull();
});

it('Is not single image in Selection: Element is not the element', () => {
const mockedElement = document.createTextNode('div');
const endContainer: any = <Partial<Node>>{
childNodes: <any>{
item: () => mockedElement,
},
};
const selection: any = <Partial<Range>>{
endContainer,
startContainer: endContainer,
endOffset: 0,
startOffset: 1,
};

const result = isSingleImageInSelection(selection);

expect(result).toBeNull();
});

it('Is single image in selection', () => {
const mockedElement = document.createElement('img');
const endContainer: any = <Partial<Node>>{
Expand Down

0 comments on commit ce82f11

Please sign in to comment.