+ {theme => theme-palette-mode-{theme.palette.mode}
}
+ ,
+ );
+
+ expect(screen.getByText('theme-palette-mode-light')).toBeInTheDocument();
+ });
+});
diff --git a/plugins/bui-themer/src/components/BuiThemerPage/MuiThemeExtractor.tsx b/plugins/bui-themer/src/components/BuiThemerPage/MuiThemeExtractor.tsx
index b935720b9e..4cad158f53 100644
--- a/plugins/bui-themer/src/components/BuiThemerPage/MuiThemeExtractor.tsx
+++ b/plugins/bui-themer/src/components/BuiThemerPage/MuiThemeExtractor.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { AppTheme } from '@backstage/core-plugin-api';
import { Theme, useTheme } from '@mui/material/styles';
@@ -36,7 +36,14 @@ export function MuiThemeExtractor(props: {
);
}
-function MuiThemeExtractorInner(props: { setTheme: (theme: Theme) => void }) {
- props.setTheme(useTheme());
+function MuiThemeExtractorInner({
+ setTheme,
+}: {
+ setTheme: (theme: Theme) => void;
+}) {
+ const theme = useTheme();
+ useEffect(() => {
+ setTheme(theme);
+ }, [theme, setTheme]);
return null;
}
diff --git a/plugins/bui-themer/src/components/BuiThemerPage/ThemeContent.test.tsx b/plugins/bui-themer/src/components/BuiThemerPage/ThemeContent.test.tsx
new file mode 100644
index 0000000000..720c46d12d
--- /dev/null
+++ b/plugins/bui-themer/src/components/BuiThemerPage/ThemeContent.test.tsx
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2025 The Backstage Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { screen, fireEvent } from '@testing-library/react';
+import '@testing-library/jest-dom';
+import { ThemeContent } from './ThemeContent';
+import { createTheme } from '@mui/material/styles';
+import { renderInTestApp } from '@backstage/test-utils';
+
+jest.mock('./convertMuiToBuiTheme', () => ({
+ convertMuiToBuiTheme: () => ({
+ css: ':root { --bui-color: #000; }',
+ styleObject: { '--bui-color': '#000' },
+ }),
+}));
+
+describe('ThemeContent', () => {
+ const muiTheme = createTheme();
+
+ beforeAll(() => {
+ Object.defineProperty(window, 'matchMedia', {
+ writable: true,
+ value: jest.fn().mockImplementation(query => ({
+ matches: false,
+ media: query,
+ onchange: null,
+ addListener: jest.fn(),
+ removeListener: jest.fn(),
+ addEventListener: jest.fn(),
+ removeEventListener: jest.fn(),
+ dispatchEvent: jest.fn(),
+ })),
+ });
+ });
+
+ it('renders title, variant and tabs', async () => {
+ await renderInTestApp(
+