Skip to content

Commit

Permalink
One last try of this
Browse files Browse the repository at this point in the history
  • Loading branch information
Surge747 committed Oct 23, 2024
1 parent 9c7235c commit cef2854
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// rich-text-editor.component.spec.ts

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RichTextEditorComponent } from './rich-text-editor.component';

Expand Down Expand Up @@ -135,11 +133,11 @@ describe('RichTextEditorComponent', () => {

if (getContentCallback) {
getContentCallback();
}

await new Promise((resolve) => setTimeout(resolve, 0));
await new Promise((resolve) => setTimeout(resolve, 0));

Check failure on line 138 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Return values from promise executor functions cannot be read

Check failure on line 138 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Return values from promise executor functions cannot be read

expect(component.characterCount).toBe(1000);
}
expect(component.characterCount).toBe(1000);
});

it('should prevent keypress when character limit is reached', () => {
Expand All @@ -154,8 +152,9 @@ describe('RichTextEditorComponent', () => {

if (keypressCallback) {
keypressCallback(mockEvent);
expect(mockEvent.preventDefault).toHaveBeenCalled();
}

expect(mockEvent.preventDefault).toHaveBeenCalled();
});

it('should handle paste event and truncate content if necessary', async () => {
Expand All @@ -174,41 +173,41 @@ describe('RichTextEditorComponent', () => {

if (pasteCallback) {
pasteCallback(mockPasteEvent);
}

await new Promise((resolve) => setTimeout(resolve, 0));

Check failure on line 178 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Return values from promise executor functions cannot be read

Check failure on line 178 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Return values from promise executor functions cannot be read

expect(mockPasteEvent.preventDefault).toHaveBeenCalled();

await new Promise((resolve) => setTimeout(resolve, 0));

expect(mockPasteEvent.preventDefault).toHaveBeenCalled();

const contentBeforePaste = 'Existing content';
const contentAfterPaste = 'Existing contentPastedText';
let firstDifferentIndex = 0;
while (
firstDifferentIndex < contentBeforePaste.length
&& contentBeforePaste[firstDifferentIndex] === contentAfterPaste[firstDifferentIndex]
) {
firstDifferentIndex += 1;
}
const contentBeforeFirstDifferentIndex = contentBeforePaste.substring(0, firstDifferentIndex);
const contentAfterFirstDifferentIndex = contentBeforePaste.substring(firstDifferentIndex);
const lengthExceed =
mockEditor.plugins.wordcount.body.getCharacterCount()
- component.RICH_TEXT_EDITOR_MAX_CHARACTER_LENGTH;
const pasteContentLength = contentAfterPaste.length - contentBeforePaste.length;
const pasteContent = contentAfterPaste.substring(
firstDifferentIndex,
firstDifferentIndex + pasteContentLength,
);
const truncatedPastedText = pasteContent.substring(0, pasteContentLength - lengthExceed);
const finalContent =
contentBeforeFirstDifferentIndex + truncatedPastedText + contentAfterFirstDifferentIndex;

expect(mockEditor.setContent).toHaveBeenCalledWith(finalContent);
expect(mockEditor.selection.getRng).toHaveBeenCalled();
expect(mockEditor.dom.createRng).toHaveBeenCalled();
expect(mockEditor.selection.setRng).toHaveBeenCalledWith(mockRange);
expect(mockRange.setStart).toHaveBeenCalled();
expect(mockRange.collapse).toHaveBeenCalled();
const contentBeforePaste = 'Existing content';
const contentAfterPaste = 'Existing contentPastedText';
let firstDifferentIndex = 0;
while (
firstDifferentIndex < contentBeforePaste.length
&& contentBeforePaste[firstDifferentIndex] === contentAfterPaste[firstDifferentIndex]
) {
firstDifferentIndex += 1;
}
const contentBeforeFirstDifferentIndex = contentBeforePaste.substring(0, firstDifferentIndex);
const contentAfterFirstDifferentIndex = contentBeforePaste.substring(firstDifferentIndex);
const lengthExceed =
mockEditor.plugins.wordcount.body.getCharacterCount()
- component.RICH_TEXT_EDITOR_MAX_CHARACTER_LENGTH;
const pasteContentLength = contentAfterPaste.length - contentBeforePaste.length;
const pasteContent = contentAfterPaste.substring(
firstDifferentIndex,
firstDifferentIndex + pasteContentLength,
);
const truncatedPastedText = pasteContent.substring(0, pasteContentLength - lengthExceed);
const finalContent =
contentBeforeFirstDifferentIndex + truncatedPastedText + contentAfterFirstDifferentIndex;

expect(mockEditor.setContent).toHaveBeenCalledWith(finalContent);
expect(mockEditor.selection.getRng).toHaveBeenCalled();
expect(mockEditor.dom.createRng).toHaveBeenCalled();
expect(mockEditor.selection.setRng).toHaveBeenCalledWith(mockRange);
expect(mockRange.setStart).toHaveBeenCalled();
expect(mockRange.collapse).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -243,4 +242,4 @@ describe('RichTextEditorComponent', () => {
expect(component.render).toBeFalsy();
});
});
});
});

Check failure on line 245 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Newline required at end of file but not found

Check failure on line 245 in src/web/app/components/rich-text-editor/rich-text-editor.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Newline required at end of file but not found
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Angular imports
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Pipe, PipeTransform } from '@angular/core';
import {
ComponentFixture,
fakeAsync,
TestBed,
tick,
waitForAsync,
} from '@angular/core/testing';
import { Pipe, PipeTransform } from '@angular/core';
import { RouterTestingModule } from '@angular/router/testing';

// Third-party imports
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

// Application imports
import { SessionsTableColumn, SessionsTableRowModel } from './sessions-table-model';
import { SessionsTableModule } from './sessions-table.module';

Check failure on line 18 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`./sessions-table.module` import should occur after import of `./sessions-table.component`

Check failure on line 18 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`./sessions-table.module` import should occur after import of `./sessions-table.component`
import { SessionsTableComponent } from './sessions-table.component';
import { SessionsTableColumn, SessionsTableRowModel } from './sessions-table-model';
import { TeammatesRouterModule } from '../teammates-router/teammates-router.module';

Check failure on line 20 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`../teammates-router/teammates-router.module` import should occur after import of `../../../types/api-output`

Check failure on line 20 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`../teammates-router/teammates-router.module` import should occur after import of `../../../types/api-output`
import { SimpleModalService } from '../../../services/simple-modal.service';
import { CopySessionModalComponent } from '../copy-session-modal/copy-session-modal.component';

Check failure on line 22 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`../copy-session-modal/copy-session-modal.component` import should occur after import of `../../../types/api-output`

Check failure on line 22 in src/web/app/components/sessions-table/sessions-table.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`../copy-session-modal/copy-session-modal.component` import should occur after import of `../../../types/api-output`
Expand Down Expand Up @@ -213,4 +213,4 @@ describe('SessionsTableComponent', () => {
sessionToCopyRowIndex: 0,
});
}));
});
});

0 comments on commit cef2854

Please sign in to comment.