-
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.
Merge pull request #1070 from rainlanguage/1069-migrate-codemirror-co…
…mponents-into-ui-components Move CodeMirror component in ui-components
- Loading branch information
Showing
7 changed files
with
131 additions
and
42 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
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,72 @@ | ||
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'; | ||
|
||
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(); | ||
}); | ||
}); | ||
|
||
it('should render codemirror-dotrain component with correct initial value', 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({}) | ||
} | ||
}); | ||
expect(screen.component.$$.ctx[0]).toBe(testValue); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/ui-components/src/lib/components/CodeMirrorDotrain.svelte
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,37 @@ | ||
<script lang="ts"> | ||
import CodeMirror from 'svelte-codemirror-editor'; | ||
import { RawRainlangExtension } from 'codemirror-rainlang'; | ||
import { openLintPanel } from '@codemirror/lint'; | ||
export let rainlangText: string | undefined = undefined; | ||
export let disabled = false; | ||
export let styles = {}; | ||
export let rainlangExtension: RawRainlangExtension; | ||
export let codeMirrorTheme; | ||
</script> | ||
|
||
<div data-testid="codemirror-dotrain"> | ||
<CodeMirror | ||
value={rainlangText || ''} | ||
extensions={[rainlangExtension]} | ||
theme={codeMirrorTheme} | ||
readonly={disabled} | ||
useTab={true} | ||
tabSize={2} | ||
styles={{ | ||
'&': { | ||
width: '100%' | ||
}, | ||
...styles | ||
}} | ||
on:ready={(e) => { | ||
openLintPanel(e.detail); | ||
}} | ||
/> | ||
</div> | ||
|
||
<style global> | ||
:global(.ͼ1 .cm-panel.cm-panel-lint ul [aria-selected]) { | ||
background-color: inherit; | ||
} | ||
</style> |
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
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
This file was deleted.
Oops, something went wrong.
Empty file.
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