Skip to content

Commit 66df087

Browse files
committed
regroup helper in utils file
1 parent aaa4639 commit 66df087

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

tests/integration/playwright/src/utils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { expect, Locator } from "@playwright/test";
2+
13
export const getUrl = (path: string) => {
24
return `http://127.0.0.1:8080/${path}`;
35
};
@@ -118,3 +120,29 @@ export const checkClick = async (page: any, locator: any) => {
118120
}
119121
return !error;
120122
};
123+
124+
export async function checkColor(element, cssProperty, rgbColors) {
125+
await expect(element).toHaveCSS(cssProperty, `rgb(${rgbColors.red}, ${rgbColors.green}, ${rgbColors.blue})`);
126+
}
127+
128+
export function asRGB(red, green, blue) {
129+
return { red, green, blue };
130+
}
131+
132+
export async function getCSSProperty(loc: Locator, variable: string, asNumber = false): Promise<string | number> {
133+
const property = await loc.evaluate((element, variable) =>
134+
window.getComputedStyle(element).getPropertyValue(variable),
135+
variable
136+
);
137+
if (asNumber) {
138+
return parseFloat(property);
139+
} else {
140+
return property;
141+
}
142+
}
143+
144+
145+
export async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
146+
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
147+
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
148+
}

tests/integration/playwright/tests/revealjs-themes.spec.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
import { test, expect, Locator } from '@playwright/test';
2-
3-
async function getCSSProperty(loc: Locator, variable: string, asNumber = false): Promise<string | number> {
4-
const property = await loc.evaluate((element, variable) =>
5-
window.getComputedStyle(element).getPropertyValue(variable),
6-
variable
7-
);
8-
if (asNumber) {
9-
return parseFloat(property);
10-
} else {
11-
return property;
12-
}
13-
}
14-
15-
async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
16-
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
17-
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
18-
}
2+
import { asRGB, checkColor, checkFontSizeIdentical, getCSSProperty } from '../src/utils';
193

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

32-
async function checkColor(element, cssProperty, rgbColors) {
33-
await expect(element).toHaveCSS(cssProperty, `rgb(${rgbColors.red}, ${rgbColors.green}, ${rgbColors.blue})`);
34-
}
35-
36-
function asRGB(red, green, blue) {
37-
return { red, green, blue };
38-
}
39-
40-
4116

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

0 commit comments

Comments
 (0)