Skip to content

Commit

Permalink
Fix collab manager tests and add ci (#83)
Browse files Browse the repository at this point in the history
* fix tests

* use new method in the model

* add ci for collab manager

* lint fixes

* revert

* feat(collab-manager): add reference to model in tsconfig.build.json

* chore: fix build script in collaboration-manager package.json

* install and build model

* fix

---------

Co-authored-by: George Berezhnoy <[email protected]>
  • Loading branch information
nikmel2803 and gohabereg authored Aug 29, 2024
1 parent 312b636 commit 929d996
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/collaboration-manager.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Collaboration manager check
on:
pull_request:
merge_group:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ESLint check
uses: ./.github/actions/lint
with:
package-name: '@editorjs/collaboration-manager'

tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- run: yarn

- name: Build the package
uses: ./.github/actions/build
with:
package-name: '@editorjs/model'

- name: Run unit tests
uses: ./.github/actions/unit-tests
with:
package-name: '@editorjs/collaboration-manager'
working-directory: './packages/collaboration-manager'
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build the package
uses: ./.github/actions/build
with:
package-name: '@editorjs/collaboration-manager'
2 changes: 1 addition & 1 deletion packages/collaboration-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "dist/index.d.ts",
"type": "module",
"scripts": {
"build": "tsc --project tsconfig.build.json",
"build": "tsc --build tsconfig.build.json",
"dev": "tsc --project tsconfig.build.json --watch",
"lint": "eslint ./src",
"lint:ci": "yarn lint --max-warnings 0",
Expand Down
24 changes: 18 additions & 6 deletions packages/collaboration-manager/src/CollaborationManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Operation, OperationType } from './Operation.js';
describe('CollaborationManager', () => {
describe('applyOperation', () => {
it('should add text on apply Insert Operation', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down Expand Up @@ -47,7 +49,9 @@ describe('CollaborationManager', () => {


it('should remove text on apply Remove Operation', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down Expand Up @@ -89,7 +93,9 @@ describe('CollaborationManager', () => {

describe('undo logic', () => {
it('should invert Insert operation', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down Expand Up @@ -129,7 +135,9 @@ describe('CollaborationManager', () => {
});

it('should invert Remove operation', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down Expand Up @@ -170,7 +178,9 @@ describe('CollaborationManager', () => {
});

it('should revert only one operation if stack length is 1', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down Expand Up @@ -211,7 +221,9 @@ describe('CollaborationManager', () => {
});

it('should revert back to original state after undo and redo operations', () => {
const model = new EditorJSModel({
const model = new EditorJSModel();

model.initializeDocument({
blocks: [ {
name: 'paragraph',
data: {
Expand Down
23 changes: 20 additions & 3 deletions packages/collaboration-manager/src/Transformer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IndexBuilder } from '@editorjs/model';
import { Operation, OperationType } from './Operation.js';

/**
Expand All @@ -10,19 +11,35 @@ export class Transformer {
* @param operation - operation to inverse
*/
public static inverse(operation: Operation): Operation {
const index = operation.index;

switch (operation.type) {
case OperationType.Insert:
return new Operation(OperationType.Delete, operation.index, {

const textRange = index.textRange;

if (textRange == undefined) {
throw new Error('Unsupported index');

Check warning on line 22 in packages/collaboration-manager/src/Transformer.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 23 in packages/collaboration-manager/src/Transformer.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

const [ textRangeStart ] = textRange;

const newIndex = new IndexBuilder()
.from(index)
.addTextRange([textRangeStart, textRangeStart + operation.data.newValue.length])
.build();

return new Operation(OperationType.Delete, newIndex, {
prevValue: operation.data.newValue,
newValue: operation.data.prevValue,
});
case OperationType.Delete:
return new Operation(OperationType.Insert, operation.index, {
return new Operation(OperationType.Insert, index, {
prevValue: operation.data.newValue,
newValue: operation.data.prevValue,
});
case OperationType.Modify:
return new Operation(OperationType.Modify, operation.index, {
return new Operation(OperationType.Modify, index, {
prevValue: operation.data.newValue,
newValue: operation.data.prevValue,
});

Check warning on line 45 in packages/collaboration-manager/src/Transformer.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 45 in packages/collaboration-manager/src/Transformer.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
Expand Down
5 changes: 5 additions & 0 deletions packages/collaboration-manager/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
],
"exclude": [
"src/**/*.spec.ts"
],
"references": [
{
"path": "../model/tsconfig.build.json"
}
]
}

2 comments on commit 929d996

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for ./packages/model

St.
Category Percentage Covered / Total
🟢 Statements 100% 753/753
🟢 Branches 99.5% 201/202
🟢 Functions 98.37% 181/184
🟢 Lines 100% 725/725

Test suite run success

389 tests passing in 24 suites.

Report generated by 🧪jest coverage report action from 929d996

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements 86.11% 62/72
🟡 Branches 62.5% 15/24
🟢 Functions 100% 10/10
🟢 Lines 86.11% 62/72

Test suite run success

6 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 929d996

Please sign in to comment.