Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions e2e/specs/themes.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { openEditCardsDialog } from '../utils/edit-cards';
import { enterEditMode, openHarness } from '../utils/harness';
import { type Page, expect, test } from '@playwright/test';

const NON_DEFAULT_HORIZON_THEMES = [
'sap_horizon_dark',
'sap_horizon_hcb',
'sap_horizon_hcw',
] as const;

type OpenUI5ThemingStub = {
__mfpSwitchTheme: (theme: string) => void;
};

async function stubOpenUI5(page: Page): Promise<void> {
await page.addInitScript(() => {
let currentTheme = 'sap_horizon';
const appliedHandlers: (() => void)[] = [];
const modules: Record<string, unknown> = {
'sap/ui/core/Theming': {
getTheme: () => currentTheme,
attachApplied: (handler: () => void) => appliedHandlers.push(handler),
},
'sap/base/i18n/Localization': {
getLanguageTag: () => 'en',
attachChange: () => undefined,
},
};
(window as unknown as { sap: unknown }).sap = {
ui: {
require: (deps: string[], callback: (module: unknown) => void) =>
callback(modules[deps[0]]),
},
};
(window as unknown as OpenUI5ThemingStub).__mfpSwitchTheme = (theme) => {
currentTheme = theme;
appliedHandlers.forEach((handler) => handler());
};
});
}

function sapBackgroundColor(page: Page): Promise<string> {
return page.evaluate(() =>
getComputedStyle(document.documentElement).getPropertyValue(
'--sapBackgroundColor',
),
);
}

test.describe('Themes', () => {
for (const theme of NON_DEFAULT_HORIZON_THEMES) {
test(`switching to ${theme} registers the theme for every UI5 package`, async ({
page,
}) => {
const themeErrors: string[] = [];
page.on('console', (message) => {
if (
message.type() === 'error' &&
message.text().includes('not registered for package')
) {
themeErrors.push(message.text());
}
});
await stubOpenUI5(page);
await openHarness(page);
const defaultBackground = await sapBackgroundColor(page);

await page.evaluate(
(themeName) =>
(window as unknown as OpenUI5ThemingStub).__mfpSwitchTheme(themeName),
theme,
);
await expect
.poll(() => sapBackgroundColor(page))
.not.toBe(defaultBackground);
await enterEditMode(page);
await openEditCardsDialog(page);

expect(themeErrors).toEqual([]);
});
}
});
1 change: 1 addition & 0 deletions projects/webcomponents-dashboard/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ vi.mock('@ui5/webcomponents-base/dist/config/Language.js', () => ({
setLanguage,
}));
vi.mock('@ui5/webcomponents-theming/dist/Assets.js', () => ({}));
vi.mock('@ui5/webcomponents/dist/generated/json-imports/Themes.js', () => ({}));

// The real declarative-ui barrel (which main.ts imports) pulls in the dashboard
// component, which imports gridstack; gridstack fails to resolve under jsdom.
Expand Down
1 change: 1 addition & 0 deletions projects/webcomponents-dashboard/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ignoreCustomElements } from '@ui5/webcomponents-base/dist/IgnoreCustomE
import { setLanguage } from '@ui5/webcomponents-base/dist/config/Language.js';
import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js';
import '@ui5/webcomponents-theming/dist/Assets.js';
import '@ui5/webcomponents/dist/generated/json-imports/Themes.js';

ignoreCustomElements('mfp');

Expand Down
7 changes: 7 additions & 0 deletions projects/webcomponents/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ vi.mock('@ui5/webcomponents-base/dist/IgnoreCustomElements.js', () => ({
ignoreCustomElements,
}));

vi.mock('@ui5/webcomponents-theming/dist/Assets.js', () => ({}));
vi.mock('@ui5/webcomponents/dist/generated/json-imports/Themes.js', () => ({}));
vi.mock(
'@ui5/webcomponents-fiori/dist/generated/json-imports/Themes.js',
() => ({}),
);

// gridstack fails to resolve under jsdom; the real declarative-ui barrel pulls
// it in transitively via the dashboard component. Stub it as the dashboard
// spec does so the barrel can load.
Expand Down
3 changes: 3 additions & 0 deletions projects/webcomponents/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
ResourceFormPatch,
} from '@openmfp/webcomponents/declarative-ui';
import { ignoreCustomElements } from '@ui5/webcomponents-base/dist/IgnoreCustomElements.js';
import '@ui5/webcomponents-fiori/dist/generated/json-imports/Themes.js';
import '@ui5/webcomponents-theming/dist/Assets.js';
import '@ui5/webcomponents/dist/generated/json-imports/Themes.js';

ignoreCustomElements('mfp');

Expand Down
Loading