Skip to content

Commit

Permalink
test: make testConfiguration.ts more general
Browse files Browse the repository at this point in the history
  • Loading branch information
max-umain committed Jan 20, 2025
1 parent 3852406 commit 5dd86ed
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/core/src/utils/testConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const testConfigurations = {
},
],
};

export const setupPage = async (page, config, componentTestPath, componentName) => {
await page.goto(componentTestPath);

Expand All @@ -50,18 +51,27 @@ export const setupPage = async (page, config, componentTestPath, componentName)
await page.evaluate(({ className, backgroundColor }) => {
document.body.classList.add(className);

const currentStyle = document.body.getAttribute('style');

document.body.setAttribute(
'style',
`background-color: ${backgroundColor}; padding-top: 20px; padding-bottom: 20px;`,
`${currentStyle}; background-color: ${backgroundColor}; padding-top: 20px; padding-bottom: 20px;`,
);
}, evaluateData);

if (config.modeVariant) {
const elementLocator = page.locator(componentName);
await expect(elementLocator).toHaveCount(1);
await elementLocator.evaluate((element, modeVariant) => {
element.setAttribute('mode-variant', modeVariant);
}, config.modeVariant);

const count = await elementLocator.count();
await expect(count).toBeGreaterThanOrEqual(1);

const elements = await elementLocator.all();

elements.forEach(async (element) => {
await element.evaluate((elem, modeVariant) => {
elem.setAttribute('mode-variant', modeVariant);
}, config.modeVariant);
});
}
};

Expand Down

0 comments on commit 5dd86ed

Please sign in to comment.