Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhermeF03 committed Jun 15, 2024
1 parent 0e242c5 commit b1ed40d
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 129 deletions.
6 changes: 4 additions & 2 deletions code/client/src/domain/editor/connectors/history/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { BlockStyle, getStyleType, InlineStyle } from '@notespace/shared/src/doc
import { ServiceConnector } from '@domain/editor/connectors/service/connector';
import {
ApplyHistory,
HistoryConnector,
HistoryConnector
} from '@domain/editor/connectors/history/types'
import {
HistoryOperation,
InsertNodeOperation,
InsertTextOperation,
Expand All @@ -15,7 +17,7 @@ import {
SetNodeOperation,
SplitNodeOperation,
UnsetNodeOperation,
} from '@domain/editor/connectors/history/types';
} from '@domain/editor/shared/historyTypes';
import { Operation } from '@notespace/shared/src/document/types/operations';

export default (fugue: Fugue, servicesConnector: ServiceConnector): HistoryConnector => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HistoryOperation } from '@domain/editor/slate/operations/history/types';
import { HistoryOperation } from '@domain/editor/shared/historyTypes';

export type HistoryConnector = {
applyHistoryOperation: ApplyHistory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {
BaseInsertNodeOperation,
BaseInsertTextOperation,
BaseMergeNodeOperation,
BaseRemoveNodeOperation,
BaseRemoveTextOperation,
BaseSetNodeOperation,
BaseSplitNodeOperation,
Node,
BaseInsertNodeOperation,
BaseInsertTextOperation,
BaseMergeNodeOperation,
BaseRemoveNodeOperation,
BaseRemoveTextOperation,
BaseSetNodeOperation,
BaseSplitNodeOperation,
Node,
} from 'slate';
import { Cursor, Selection } from '@domain/editor/cursor';

export type HistoryOperation =
| InsertTextOperation
| RemoveTextOperation
| InsertNodeOperation
| RemoveNodeOperation
| SplitNodeOperation
| MergeNodeOperation
| SetNodeOperation
| UnsetNodeOperation;
| InsertTextOperation
| RemoveTextOperation
| InsertNodeOperation
| RemoveNodeOperation
| SplitNodeOperation
| MergeNodeOperation
| SetNodeOperation
| UnsetNodeOperation;

/**
* Base operation for inserting text
Expand All @@ -27,9 +27,9 @@ export type HistoryOperation =
* @param text - The text to insert
*/
export type InsertTextOperation = {
type: BaseInsertTextOperation['type'];
cursor: Cursor;
text: string[];
type: BaseInsertTextOperation['type'];
cursor: Cursor;
text: string[];
};

/**
Expand All @@ -38,8 +38,8 @@ export type InsertTextOperation = {
* @param selection - The selection to remove the text
*/
export type RemoveTextOperation = {
type: BaseRemoveTextOperation['type'];
selection: Selection;
type: BaseRemoveTextOperation['type'];
selection: Selection;
};

/**
Expand All @@ -49,10 +49,10 @@ export type RemoveTextOperation = {
* @param selection - The selection to insert the node
*/
export type InsertNodeOperation = {
type: BaseInsertNodeOperation['type'];
node: Node;
lineOperation: boolean;
selection: Selection;
type: BaseInsertNodeOperation['type'];
node: Node;
lineOperation: boolean;
selection: Selection;
};

/**
Expand All @@ -62,10 +62,10 @@ export type InsertNodeOperation = {
* @param selection - The selection to remove the node
*/
export type RemoveNodeOperation = {
type: BaseRemoveNodeOperation['type'];
node: Node;
lineOperation: boolean;
selection: Selection;
type: BaseRemoveNodeOperation['type'];
node: Node;
lineOperation: boolean;
selection: Selection;
};

/**
Expand All @@ -75,9 +75,9 @@ export type RemoveNodeOperation = {
* @param cursor - The cursor position to split the node
*/
export type SplitNodeOperation = {
type: BaseSplitNodeOperation['type'];
properties: Partial<Node>;
cursor: Cursor;
type: BaseSplitNodeOperation['type'];
properties: Partial<Node>;
cursor: Cursor;
};

/**
Expand All @@ -87,9 +87,9 @@ export type SplitNodeOperation = {
* @param cursor - The cursor position to merge the node
*/
export type MergeNodeOperation = {
type: BaseMergeNodeOperation['type'];
properties: Partial<Node>;
cursor: Cursor;
type: BaseMergeNodeOperation['type'];
properties: Partial<Node>;
cursor: Cursor;
};

/**
Expand All @@ -100,10 +100,10 @@ export type MergeNodeOperation = {
* @param newProperties - The new properties of the node
*/
export type SetNodeOperation = {
type: BaseSetNodeOperation['type'];
lineOperation: boolean;
selection: Selection;
properties: Partial<Node>;
type: BaseSetNodeOperation['type'];
lineOperation: boolean;
selection: Selection;
properties: Partial<Node>;
};

/**
Expand All @@ -114,8 +114,8 @@ export type SetNodeOperation = {
* @param newProperties - The new properties of the node
*/
export type UnsetNodeOperation = {
type: 'unset_node';
lineOperation: boolean;
selection: Selection;
properties: Partial<Node>;
type: 'unset_node';
lineOperation: boolean;
selection: Selection;
properties: Partial<Node>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
SetNodeOperation,
SplitNodeOperation,
UnsetNodeOperation,
} from '@domain/editor/slate/operations/history/types';
} from '@domain/editor/shared/historyTypes';
import { pointToCursor } from '@domain/editor/slate/utils/selection';

const reverseTypes: { [key: string]: HistoryOperation['type'] } = {
Expand Down
44 changes: 26 additions & 18 deletions code/client/tests/editor/domain/document/fugueOperations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ import {
InsertOperation,
DeleteOperation,
InlineStyleOperation,
BlockStyleOperation,
BlockStyleOperation, Operation,
} from '@notespace/shared/src/document/types/operations';
import getFugueOperations from '@domain/editor/fugue/operations/fugue/operations';
import { FugueDomainOperations } from '@domain/editor/fugue/operations/fugue/types';
import { Document } from '@notespace/shared/src/workspace/types/document';
import { Node, RootNode } from '@domain/editor/fugue/nodes';
import { rootNode, treeNode } from '@notespace/shared/src/document/utils';
import {ServiceConnector} from "@domain/editor/connectors/service/connector";
import {DocumentContent} from "@notespace/shared/src/workspace/types/document";
import {rootNode, treeNode} from "@domain/editor/fugue/utils";

import serviceConnector from '@domain/editor/connectors/service/connector';
import {mockCommunication} from "@tests/mocks/mockCommunication";




describe('Fugue Operations', () => {
let fugue: Fugue;
let fugueOperations: FugueDomainOperations;
const communication = mockCommunication();
let _serviceConnector: ServiceConnector;
let applyOperations: (operations: Operation[]) => void;

beforeEach(() => {
fugue = new Fugue();
fugueOperations = getFugueOperations(fugue);
_serviceConnector = serviceConnector(fugue, communication);
applyOperations = _serviceConnector.applyFugueOperations;
});

test('should apply operations', () => {
Expand All @@ -29,10 +37,11 @@ describe('Fugue Operations', () => {
value: 'a',
parent: { sender: 'root', counter: 0 },
side: 'R',
cursor: { line: 0, column: 0}
};

// when
fugueOperations.applyOperations([insertOperation]);
applyOperations([insertOperation]);

// then
expect(fugue.toString()).toEqual('a');
Expand All @@ -41,10 +50,11 @@ describe('Fugue Operations', () => {
const deleteOperation: DeleteOperation = {
type: 'delete',
id: { sender: 'A', counter: 0 },
cursor: { line: 0, column: 0 }
};

// when
fugueOperations.applyOperations([deleteOperation]);
applyOperations([deleteOperation]);

// then
expect(fugue.toString()).toEqual('');
Expand All @@ -53,7 +63,7 @@ describe('Fugue Operations', () => {
const insertOperation2 = { ...insertOperation, id: { sender: 'A', counter: 1 }, value: 'b' };

// when
fugueOperations.applyOperations([insertOperation2]);
applyOperations([insertOperation2]);

// given
const inlineStyleOperation: InlineStyleOperation = {
Expand All @@ -64,7 +74,7 @@ describe('Fugue Operations', () => {
};

// when
fugueOperations.applyOperations([inlineStyleOperation]);
applyOperations([inlineStyleOperation]);

// then
expect(fugue.getNodeByCursor({ line: 0, column: 1 })?.styles).toEqual(['bold']);
Expand All @@ -78,7 +88,7 @@ describe('Fugue Operations', () => {
};

// when
fugueOperations.applyOperations([blockStyleOperation]);
applyOperations([blockStyleOperation]);

// then
expect(fugue.getBlockStyle(0)).toEqual('paragraph');
Expand All @@ -91,17 +101,15 @@ describe('Fugue Operations', () => {
const node2: Node<string> = treeNode({ sender: 'A', counter: 1 }, 'b', node1.id, 'R', 2);
root.rightChildren = [node1.id];
node1.rightChildren = [node2.id];
const document: Document = {
id: 'test',
title: 'test',
const document: DocumentContent = {
operations: [
{ type: 'insert', ...node1, parent: root.id, styles: [] },
{ type: 'insert', ...node2, parent: node1.id, styles: [] },
{ type: 'insert', ...node1, parent: root.id, styles: [], cursor: { line: 0, column: 0 }},
{ type: 'insert', ...node2, parent: node1.id, styles: [], cursor: { line: 0, column: 1 }},
],
};

// when
fugueOperations.applyOperations(document.operations);
applyOperations(document.operations);

// then
expect(fugue.toString()).toEqual('ab');
Expand Down
34 changes: 19 additions & 15 deletions code/client/tests/editor/domain/document/inputOperations.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { describe, test, expect, beforeEach } from 'vitest';
import { Fugue } from '@domain/editor/fugue/Fugue';
import getInputOperations from '@domain/editor/fugue/operations/input/operations';
import { InputDomainOperations } from '@domain/editor/fugue/operations/input/types';

import { mockCommunication } from '@tests/mocks/mockCommunication';
import {InputConnector} from "@domain/editor/connectors/input/types";
import serviceConnector, {ServiceConnector} from "@domain/editor/connectors/service/connector";
import inputConnector from "@domain/editor/connectors/input/connector";

describe('Input Operations', () => {
const communication = mockCommunication();
let fugue: Fugue;
let inputOperations: InputDomainOperations;
let _inputConnector : InputConnector;
let servicesConnector : ServiceConnector;

beforeEach(() => {
fugue = new Fugue();
inputOperations = getInputOperations(fugue, communication);
servicesConnector = serviceConnector(fugue, communication);
_inputConnector = inputConnector(fugue, servicesConnector);
});

test('should insert character', () => {
// given
const cursor = { line: 0, column: 0 };

// when
inputOperations.insertCharacter('a', cursor);
_inputConnector.insertCharacter('a', cursor);

// then
expect(fugue.toString()).toEqual('a');
Expand All @@ -30,7 +34,7 @@ describe('Input Operations', () => {
const cursor = { line: 0, column: 0 };

// when
inputOperations.insertLineBreak(cursor);
_inputConnector.insertLineBreak(cursor);

// then
expect(fugue.toString()).toEqual('\n');
Expand All @@ -40,10 +44,10 @@ describe('Input Operations', () => {
// given
const cursor1 = { line: 0, column: 0 };
const cursor2 = { line: 0, column: 1 };
inputOperations.insertCharacter('a', cursor1);
_inputConnector.insertCharacter('a', cursor1);

// when
inputOperations.deleteCharacter(cursor2);
_inputConnector.deleteCharacter(cursor2);

// then
expect(fugue.toString()).toEqual('');
Expand All @@ -54,11 +58,11 @@ describe('Input Operations', () => {
const cursor1 = { line: 0, column: 0 };
const cursor2 = { line: 0, column: 1 };
const cursor3 = { line: 0, column: 2 };
inputOperations.insertCharacter('a', cursor1);
inputOperations.insertCharacter('b', cursor2);
_inputConnector.insertCharacter('a', cursor1);
_inputConnector.insertCharacter('b', cursor2);

// when
inputOperations.deleteSelection({ start: cursor1, end: cursor3 });
_inputConnector.deleteSelection({ start: cursor1, end: cursor3 });

// then
expect(fugue.toString()).toEqual('');
Expand All @@ -72,15 +76,15 @@ describe('Input Operations', () => {

// when
text.split('').forEach((char, index) => {
inputOperations.insertCharacter(char, { line: 0, column: index });
_inputConnector.insertCharacter(char, { line: 0, column: index });
});
inputOperations.deleteWord(cursor1, true);
_inputConnector.deleteWord(cursor1, true);

// then
expect(fugue.toString()).toEqual('hello ');

// when
inputOperations.deleteWord(cursor2, false);
_inputConnector.deleteWord(cursor2, false);

// then
expect(fugue.toString()).toEqual(' ');
Expand All @@ -92,7 +96,7 @@ describe('Input Operations', () => {
const cursor = { line: 0, column: 0 };

// when
inputOperations.pasteText(cursor, text);
_inputConnector.pasteText(cursor, text);

// then
expect(fugue.toString()).toEqual(text);
Expand Down
Loading

0 comments on commit b1ed40d

Please sign in to comment.