Skip to content

Commit aa9fa40

Browse files
committed
add playwright test for dracula theme tweak regaring color-title
aims to prevent problem at next revealjs update
1 parent 3a9a494 commit aa9fa40

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: callout title in dracula theme is tweak
3+
format:
4+
revealjs:
5+
theme: dracula
6+
---
7+
8+
`dracula` theme in revealjs does use a color for `<strong>` and `<b>` element. We don't want that to apply on Callout title which are using this HTML element.
9+
So we tweaked dracula theme et this test checks that color of title is like in other themes => the same as the body color.
10+
11+
## Note
12+
13+
::: {.callout-note}
14+
15+
## Title of the callout
16+
17+
Content
18+
19+
:::

tests/integration/playwright/src/utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,26 @@ export async function getCSSProperty(loc: Locator, variable: string, asNumber =
151151
}
152152
}
153153

154+
export async function checkCSSproperty(loc1: Locator, loc2: Locator, property: string, asNumber: false | true, checkType: 'identical' | 'similar', factor: number = 1) {
155+
let loc1Property = await getCSSProperty(loc1, property, asNumber);
156+
let loc2Property = await getCSSProperty(loc2, property, asNumber);
157+
if (checkType === 'identical') {
158+
await expect(loc2).toHaveCSS(property, loc1Property as string);
159+
} else {
160+
await expect(loc1Property).toBeCloseTo(loc2Property as number * factor);
161+
}
162+
}
163+
154164
export async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
155-
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
156-
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
165+
await checkCSSproperty(loc1, loc2, 'font-size', false, 'identical');
157166
}
158167

159168
export async function checkFontSizeSimilar(loc1: Locator, loc2: Locator, factor: number = 1) {
160-
const loc1FontSize = await getCSSProperty(loc1, 'font-size', true) as number;
161-
const loc2FontSize = await getCSSProperty(loc2, 'font-size', true) as number;
162-
await expect(loc1FontSize).toBeCloseTo(loc2FontSize * factor);
169+
await checkCSSproperty(loc1, loc2, 'font-size', true, 'similar', factor);
170+
}
171+
172+
export async function checkColorIdentical(loc1: Locator, loc2: Locator, property: string) {
173+
await checkCSSproperty(loc1, loc2, property, false, 'identical');
163174
}
164175

165176
export async function checkBorderProperties(element: Locator, side: string, color: RGBColor, width: string) {

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, Locator } from '@playwright/test';
2-
import { asRGB, checkColor, checkFontSizeIdentical, checkFontSizeSimilar, getCSSProperty, RGBColor } from '../src/utils';
2+
import { asRGB, checkColor, checkColorIdentical, checkFontSizeSimilar, getCSSProperty, RGBColor } from '../src/utils';
33

44
async function getRevealMainFontSize(page: any): Promise<number> {
55
return await getCSSProperty(page.locator('body'), "--r-main-font-size", true) as number;
@@ -71,4 +71,11 @@ test('Callouts can be customized using SCSS variables', async ({ page }) => {
7171
await checkCustom(page.locator('div.callout-warning'), '10px', asRGB(173, 216, 230));
7272
await checkCustom(page.locator('div.callout-important'), '10px', asRGB(128, 128, 128));
7373
await checkCustom(page.locator('div.callout-caution'), '10px', asRGB(0, 128, 0));
74+
});
75+
76+
test('Callout title color in dracula theme is correctly tweaked to use same as body color', async ({ page }) => {
77+
await page.goto('./revealjs/callouts/dracula-theme-tweaks.html#/note');
78+
const calloutTitleLoc = page.getByText('Title of the callout', { exact: true });
79+
const calloutContentLoc = page.getByText('Content', { exact: true });
80+
await checkColorIdentical(calloutTitleLoc, calloutContentLoc, 'color');
7481
});

0 commit comments

Comments
 (0)