feat(ui/alerts): MustacheEditor component (CM6 shell with completion + linter)
Wires the mustache-completion source and mustache-linter into a CodeMirror 6 EditorView. Accepts kind (filters variables) and reducedContext (env-only for connection URLs). singleLine prevents newlines for URL/header fields. Host ref syncs when the parent replaces value (promotion prefill).
This commit is contained in:
34
ui/src/components/MustacheEditor/MustacheEditor.test.tsx
Normal file
34
ui/src/components/MustacheEditor/MustacheEditor.test.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { MustacheEditor } from './MustacheEditor';
|
||||
|
||||
describe('MustacheEditor', () => {
|
||||
it('renders the initial value', () => {
|
||||
render(
|
||||
<MustacheEditor
|
||||
value="Hello {{rule.name}}"
|
||||
onChange={() => {}}
|
||||
kind="ROUTE_METRIC"
|
||||
label="Title template"
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByText(/Hello/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders a textbox and does not call onChange before user interaction', () => {
|
||||
const onChange = vi.fn();
|
||||
render(
|
||||
<MustacheEditor
|
||||
value=""
|
||||
onChange={onChange}
|
||||
kind="ROUTE_METRIC"
|
||||
label="Title template"
|
||||
/>,
|
||||
);
|
||||
const editor = screen.getByRole('textbox', { name: 'Title template' });
|
||||
expect(editor).toBeInTheDocument();
|
||||
// CM6 fires onChange via transactions, not DOM input events; without a real
|
||||
// user interaction the callback must remain untouched.
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user