Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Dec 2, 2024
1 parent ea10516 commit 34c27a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class PostingMarkdownEditorComponent implements OnInit, ControlValueAcces

const editor = this.markdownEditor.monacoEditor;
if (editor) {
editor.onDidChangeModelContent((event: { changes: string | any[] }) => {
editor.onDidChangeModelContent((event: monaco.editor.IModelContentChangedEvent) => {
const position = editor.getPosition();
if (!position) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,15 @@ describe('PostingsMarkdownEditor', () => {

expect(handleActionClickSpy).toHaveBeenCalledWith(expect.any(MouseEvent), bulletedListAction);
});

it('should handle invalid line content gracefully', () => {
const mockModel = {
getLineContent: jest.fn().mockReturnValue(''),
} as unknown as monaco.editor.ITextModel;
const mockPosition = { lineNumber: 1 } as monaco.Position;
const handleActionClickSpy = jest.spyOn(component.markdownEditor, 'handleActionClick');

(component as any).handleKeyDown(mockModel, mockPosition.lineNumber);
expect(handleActionClickSpy).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,18 @@ describe('MonacoEditorComponent', () => {
const lineContent = comp.getLineContent(2);
expect(lineContent).toBe('static void main() {');
});

it('should handle invalid line numbers in getLineContent', () => {
fixture.detectChanges();
comp.setText(multiLineText);

// Invalid line numbers
expect(() => comp.getLineContent(0)).toThrow();
expect(() => comp.getLineContent(-1)).toThrow();
expect(() => comp.getLineContent(999)).toThrow();

// Empty line
comp.setText('line1\n\nline3');
expect(comp.getLineContent(2)).toBe('');
});
});

0 comments on commit 34c27a0

Please sign in to comment.