-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test should render codemirror-dotrain
- Loading branch information
1 parent
12344a3
commit 969c82d
Showing
2 changed files
with
74 additions
and
17 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
packages/ui-components/src/__tests__/CodeMirrorDotrain.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { render, waitFor } from '@testing-library/svelte'; | ||
import { CodeMirrorDotrain } from '@rainlanguage/ui-components'; | ||
import { RawRainlangExtension } from 'codemirror-rainlang'; // Direct import | ||
import { writable } from 'svelte/store'; | ||
|
||
// Mock dependencies | ||
vi.mock('codemirror-rainlang', () => ({ | ||
RawRainlangExtension: vi.fn(() => ({ | ||
plugin: vi.fn(), | ||
hover: vi.fn(), | ||
completion: vi.fn(), | ||
language: vi.fn(), | ||
diagnostics: vi.fn() | ||
})) | ||
})); | ||
|
||
vi.mock('@codemirror/lint', () => ({ | ||
openLintPanel: vi.fn() | ||
})); | ||
|
||
vi.mock('svelte-codemirror-editor', async () => { | ||
const mockCodeMirror = (await import('../lib/__mocks__/MockComponent.svelte')).default; | ||
return { default: mockCodeMirror }; | ||
}); | ||
|
||
describe('CodeMirrorDotrain', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render codemirror-dotrain', async () => { | ||
const testValue = 'initial dotrain value'; | ||
const rainlangExtensionMock = new RawRainlangExtension({ | ||
hover: async () => null, | ||
completion: async () => null, | ||
diagnostics: async () => [] | ||
}); | ||
|
||
const screen = render(CodeMirrorDotrain, { | ||
props: { | ||
rainlangText: testValue, | ||
disabled: false, | ||
styles: {}, | ||
rainlangExtension: rainlangExtensionMock, | ||
codeMirrorTheme: writable({}) | ||
} | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('codemirror-dotrain')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters