CodeEditor: Fix broken styles (#88495)
* fix: remove erroneous container * fix: update selector * fix: pass data attrs via `wrapperProps` * fix: ensure `toBeInTheDocument` checks have unique markup
This commit is contained in:
@@ -527,7 +527,7 @@ export const Components = {
|
|||||||
container: 'data-testid Code editor container',
|
container: 'data-testid Code editor container',
|
||||||
},
|
},
|
||||||
ReactMonacoEditor: {
|
ReactMonacoEditor: {
|
||||||
container: 'data-testid ReactMonacoEditor container',
|
editorLazy: 'data-testid ReactMonacoEditor editorLazy',
|
||||||
},
|
},
|
||||||
DashboardImportPage: {
|
DashboardImportPage: {
|
||||||
textarea: 'data-testid-import-dashboard-textarea',
|
textarea: 'data-testid-import-dashboard-textarea',
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import type { ReactMonacoEditorProps } from './types';
|
|||||||
* @internal
|
* @internal
|
||||||
* Experimental export
|
* Experimental export
|
||||||
**/
|
**/
|
||||||
const MonacoEditorLazy = (props: ReactMonacoEditorProps) => {
|
export const ReactMonacoEditorLazy = (props: ReactMonacoEditorProps) => {
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const { loading, error, dependency } = useAsyncDependency(
|
const { loading, error, dependency } = useAsyncDependency(
|
||||||
import(/* webpackChunkName: "react-monaco-editor" */ './ReactMonacoEditor')
|
import(/* webpackChunkName: "react-monaco-editor" */ './ReactMonacoEditor')
|
||||||
@@ -31,13 +31,21 @@ const MonacoEditorLazy = (props: ReactMonacoEditorProps) => {
|
|||||||
<ErrorWithStack
|
<ErrorWithStack
|
||||||
title="React Monaco Editor failed to load"
|
title="React Monaco Editor failed to load"
|
||||||
error={error}
|
error={error}
|
||||||
errorInfo={{ componentStack: error?.stack || '' }}
|
errorInfo={{ componentStack: error?.stack ?? '' }}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReactMonacoEditor = dependency.ReactMonacoEditor;
|
const ReactMonacoEditor = dependency.ReactMonacoEditor;
|
||||||
return <ReactMonacoEditor {...props} loading={props.loading ?? null} />;
|
return (
|
||||||
|
<ReactMonacoEditor
|
||||||
|
{...props}
|
||||||
|
loading={props.loading ?? null}
|
||||||
|
wrapperProps={{
|
||||||
|
'data-testid': selectors.components.ReactMonacoEditor.editorLazy,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => {
|
const getStyles = (theme: GrafanaTheme2) => {
|
||||||
@@ -48,18 +56,3 @@ const getStyles = (theme: GrafanaTheme2) => {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const withContainer = <P extends object>(Component: React.ComponentType<P>): React.ComponentType<P> => {
|
|
||||||
const WithContainer = (props: P) => (
|
|
||||||
// allow tests to easily determine if the code editor has rendered in any of its three states (loading, error, or ready)
|
|
||||||
<div data-testid={selectors.components.ReactMonacoEditor.container}>
|
|
||||||
<Component {...props} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
WithContainer.displayName = Component.displayName;
|
|
||||||
|
|
||||||
return WithContainer;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ReactMonacoEditorLazy = withContainer(MonacoEditorLazy);
|
|
||||||
|
|||||||
+1
-1
@@ -27,7 +27,7 @@ describe('MonacoFieldWrapper', () => {
|
|||||||
renderComponent();
|
renderComponent();
|
||||||
|
|
||||||
await waitFor(async () => {
|
await waitFor(async () => {
|
||||||
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.container);
|
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.editorLazy);
|
||||||
expect(monacoEditor).toBeInTheDocument();
|
expect(monacoEditor).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ describe('MonacoQueryField', () => {
|
|||||||
test('Renders with no errors', async () => {
|
test('Renders with no errors', async () => {
|
||||||
renderComponent();
|
renderComponent();
|
||||||
|
|
||||||
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.container);
|
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.editorLazy);
|
||||||
expect(monacoEditor).toBeInTheDocument();
|
expect(monacoEditor).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+2
-2
@@ -34,7 +34,7 @@ describe('LokiQueryCodeEditor', () => {
|
|||||||
props.showExplain = true;
|
props.showExplain = true;
|
||||||
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
|
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
|
||||||
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
|
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
|
||||||
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.container);
|
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.editorLazy);
|
||||||
expect(monacoEditor).toBeInTheDocument();
|
expect(monacoEditor).toBeInTheDocument();
|
||||||
expect(screen.getByText(EXPLAIN_LABEL_FILTER_CONTENT)).toBeInTheDocument();
|
expect(screen.getByText(EXPLAIN_LABEL_FILTER_CONTENT)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
@@ -43,7 +43,7 @@ describe('LokiQueryCodeEditor', () => {
|
|||||||
const props = createDefaultProps();
|
const props = createDefaultProps();
|
||||||
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
|
props.datasource.metadataRequest = jest.fn().mockResolvedValue([]);
|
||||||
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
|
render(<LokiQueryCodeEditor {...props} query={defaultQuery} />);
|
||||||
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.container);
|
const monacoEditor = await screen.findByTestId(selectors.components.ReactMonacoEditor.editorLazy);
|
||||||
expect(monacoEditor).toBeInTheDocument();
|
expect(monacoEditor).toBeInTheDocument();
|
||||||
expect(screen.queryByText(EXPLAIN_LABEL_FILTER_CONTENT)).not.toBeInTheDocument();
|
expect(screen.queryByText(EXPLAIN_LABEL_FILTER_CONTENT)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user