Skip to content

Commit

Permalink
regroup helper in utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv committed Nov 6, 2024
1 parent aaa4639 commit 66df087
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
28 changes: 28 additions & 0 deletions tests/integration/playwright/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, Locator } from "@playwright/test";

export const getUrl = (path: string) => {
return `http://127.0.0.1:8080/${path}`;
};
Expand Down Expand Up @@ -118,3 +120,29 @@ export const checkClick = async (page: any, locator: any) => {
}
return !error;
};

export async function checkColor(element, cssProperty, rgbColors) {
await expect(element).toHaveCSS(cssProperty, `rgb(${rgbColors.red}, ${rgbColors.green}, ${rgbColors.blue})`);
}

export function asRGB(red, green, blue) {
return { red, green, blue };
}

export async function getCSSProperty(loc: Locator, variable: string, asNumber = false): Promise<string | number> {
const property = await loc.evaluate((element, variable) =>
window.getComputedStyle(element).getPropertyValue(variable),
variable
);
if (asNumber) {
return parseFloat(property);
} else {
return property;
}
}


export async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
}
27 changes: 1 addition & 26 deletions tests/integration/playwright/tests/revealjs-themes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
import { test, expect, Locator } from '@playwright/test';

async function getCSSProperty(loc: Locator, variable: string, asNumber = false): Promise<string | number> {
const property = await loc.evaluate((element, variable) =>
window.getComputedStyle(element).getPropertyValue(variable),
variable
);
if (asNumber) {
return parseFloat(property);
} else {
return property;
}
}

async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
}
import { asRGB, checkColor, checkFontSizeIdentical, getCSSProperty } from '../src/utils';

async function getRevealMainFontSize(page: any): Promise<number> {
return await getCSSProperty(page.locator('body'), "--r-main-font-size", true) as number;
Expand All @@ -29,15 +13,6 @@ async function getRevealCodeInlineFontSize(page: any): Promise<number> {
return await getCSSProperty(page.locator('body'), "--r-inline-code-font-size", true) as number;
}

async function checkColor(element, cssProperty, rgbColors) {
await expect(element).toHaveCSS(cssProperty, `rgb(${rgbColors.red}, ${rgbColors.green}, ${rgbColors.blue})`);
}

function asRGB(red, green, blue) {
return { red, green, blue };
}



test('Code font size in callouts and smaller slide is scaled down', async ({ page }) => {
await page.goto('./revealjs/code-font-size.html');
Expand Down

0 comments on commit 66df087

Please sign in to comment.