Skip to content

Commit b6584f6

Browse files
committed
Adapt tests to new rules for code font size
1 parent 7813820 commit b6584f6

File tree

3 files changed

+30
-67
lines changed

3 files changed

+30
-67
lines changed

tests/docs/playwright/revealjs/code-font-size.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Every test is a call to `testthat::test_that()` function.
2323

2424
- And inside a list : `1+1`
2525

26-
## Highlited Cell
26+
## Highlighted Cell
2727

2828
````{.python}
2929
1 + 1

tests/integration/playwright/src/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,10 @@ export async function getCSSProperty(loc: Locator, variable: string, asNumber =
151151
export async function checkFontSizeIdentical(loc1: Locator, loc2: Locator) {
152152
const loc1FontSize = await getCSSProperty(loc1, 'font-size', false) as string;
153153
await expect(loc2).toHaveCSS('font-size', loc1FontSize);
154+
}
155+
156+
export async function checkFontSizeSimilar(loc1: Locator, loc2: Locator, factor: number = 1) {
157+
const loc1FontSize = await getCSSProperty(loc1, 'font-size', true) as number;
158+
const loc2FontSize = await getCSSProperty(loc2, 'font-size', true) as number;
159+
await expect(loc1FontSize).toBeCloseTo(loc2FontSize * factor);
154160
}

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

Lines changed: 23 additions & 66 deletions
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, getCSSProperty, RGBColor } from '../src/utils';
2+
import { asRGB, checkColor, checkFontSizeIdentical, 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;
@@ -16,25 +16,25 @@ async function getRevealCodeInlineFontSize(page: any): Promise<number> {
1616

1717
test('Code font size in callouts and smaller slide is scaled down', async ({ page }) => {
1818
await page.goto('./revealjs/code-font-size.html');
19-
await page.locator('body').press('ArrowRight');
2019
// Get smaller slide scale factor
2120
const calloutsFontSize = await getCSSProperty(page.locator('#callouts div.callout'), "font-size", true) as number;
2221
const mainFontSize = await getRevealMainFontSize(page);
2322
const scaleFactor = calloutsFontSize / mainFontSize;
2423
expect(scaleFactor).toBeLessThan(1);
24+
// Get non smaller size
25+
const codeBlockFontSizeDefault = await getCSSProperty(page.locator('#highlighted-cell pre'), "font-size", true) as number;
26+
const codeInlineFontSizeDefault = await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), "font-size", true) as number;
2527
// Font size in callout for inline code should be scaled smaller than default inline code
28+
expect(await getCSSProperty(page.locator('#callouts').getByText('testthat::test_that()'), "font-size", true)).toBeCloseTo(codeInlineFontSizeDefault * scaleFactor);
29+
// Font size for code block in callout should be scaled smaller that default code block
30+
expect(await getCSSProperty(page.locator('#callouts .callout pre code'), 'font-size', true)).toBeCloseTo(codeBlockFontSizeDefault * scaleFactor);
31+
// Font size in callout for inline code should be samely size as text than by default
2632
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
27-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
28-
expect(await getCSSProperty(page.locator('#callouts').getByText('testthat::test_that()'), 'font-size', true)).toBeCloseTo(computedInlineFontSize);
29-
// Font size in callout for inline code should be same size as text by default
30-
await checkFontSizeIdentical(
31-
page.locator('#callouts').getByText('Every test is a call to'),
32-
page.locator('#callouts').getByText('testthat::test_that()')
33+
await checkFontSizeSimilar(
34+
page.locator('#callouts').getByText('testthat::test_that()'),
35+
page.locator('#callouts').getByText('Every test is a call to'),
36+
codeInlineFontSize
3337
);
34-
// Font size for code block in callout should be scaled smaller that default code block
35-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
36-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
37-
expect(await getCSSProperty(page.locator('#callouts .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
3838
});
3939

4040
test('Code font size in smaller slide is scaled down', async ({ page }) => {
@@ -44,63 +44,20 @@ test('Code font size in smaller slide is scaled down', async ({ page }) => {
4444
const mainFontSize = await getRevealMainFontSize(page);
4545
const scaleFactor = smallerFontSize / mainFontSize;
4646
expect(scaleFactor).toBeLessThan(1);
47-
// Code Font size in smaller slide for inline code should be scaled smaller than default inline code
48-
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
49-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
50-
expect(
51-
await getCSSProperty(
52-
page.locator('#smaller-slide p').filter({ hasText: 'Some inline code' }).getByRole('code'),
53-
'font-size', true
54-
)
55-
).toBeCloseTo(computedInlineFontSize);
56-
// Font size for code block in callout should be scaled smaller that default code block
57-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
58-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
59-
expect(await getCSSProperty(page.locator('#smaller-slide pre').getByRole('code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
60-
});
61-
62-
test('Code font size in callouts in smaller slide is scaled down twice', async ({ page }) => {
63-
await page.goto('./revealjs/code-font-size.html#/smaller-slide2');
64-
// Get smaller slide scale factor
65-
const smallerFontSize = await getCSSProperty(page.locator('#smaller-slide2').getByText('And block code:', { exact: true }), "font-size", true) as number;
66-
const mainFontSize = await getRevealMainFontSize(page);
67-
const scaleFactor = smallerFontSize / mainFontSize;
68-
expect(scaleFactor).toBeLessThan(1);
47+
// Get non smaller size
48+
const codeBlockFontSizeDefault = await getCSSProperty(page.locator('#highlighted-cell pre'), "font-size", true) as number;
49+
const codeInlineFontSizeDefault = await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), "font-size", true) as number;
6950
// Font size in callout for inline code should be scaled smaller than default inline code
70-
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
71-
const computedInlineFontSize = scaleFactor * codeInlineFontSize;
72-
expect(await getCSSProperty(page.locator('#smaller-slide2').getByText('1 + 1'), 'font-size', true)).toBeCloseTo(computedInlineFontSize);
73-
// Font size in callout for inline code should be same size as text by default
74-
await checkFontSizeIdentical(
75-
page.locator('#smaller-slide2').getByText('Some inline code'),
76-
page.locator('#smaller-slide2').getByText('1 + 1')
77-
);
51+
expect(await getCSSProperty(page.locator('#smaller-slide p').filter({ hasText: 'Some inline code' }).getByRole('code'), "font-size", true)).toBeCloseTo(codeInlineFontSizeDefault * scaleFactor);
7852
// Font size for code block in callout should be scaled smaller that default code block
79-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page)
80-
const computedBlockFontSize = scaleFactor * codeBlockFontSize;
81-
expect(await getCSSProperty(page.locator('#smaller-slide2 .callout pre code'), 'font-size', true)).toBeCloseTo(computedBlockFontSize);
82-
});
83-
84-
test('Code font size is correctly set', async ({ page }) => {
85-
await page.goto('./revealjs/code-font-size.html');
86-
await page.locator('body').press('ArrowRight');
87-
await page.locator('body').press('ArrowRight');
53+
expect(await getCSSProperty(page.locator('#smaller-slide pre').getByRole('code'), 'font-size', true)).toBeCloseTo(codeBlockFontSizeDefault * scaleFactor);
54+
// Font size in callout for inline code should be samely size as text than by default
8855
const codeInlineFontSize = await getRevealCodeInlineFontSize(page);
89-
expect(
90-
await getCSSProperty(page.locator('#no-callout-inline').getByText('testthat::test_that()'), 'font-size', true)
91-
).toBeCloseTo(codeInlineFontSize);
92-
expect(
93-
await getCSSProperty(page.getByText('1+1', { exact: true }), 'font-size', true)
94-
).toBeCloseTo(codeInlineFontSize);
95-
await page.locator('body').press('ArrowRight');
96-
const codeBlockFontSize = await getRevealCodeBlockFontSize(page);
97-
expect(
98-
await getCSSProperty(page.locator("#highlited-cell div.sourceCode pre code"), 'font-size', true)
99-
).toBeCloseTo(codeBlockFontSize);
100-
await page.locator('body').press('ArrowRight');
101-
expect(
102-
await getCSSProperty(page.locator("#non-highligted pre code"), 'font-size', true)
103-
).toBeCloseTo(codeBlockFontSize);
56+
await checkFontSizeSimilar(
57+
page.locator('#smaller-slide2').getByText('+ 1'),
58+
page.locator('#smaller-slide2').getByText('Some inline code'),
59+
codeInlineFontSize
60+
);
10461
});
10562

10663
test('Callouts can be customized using SCSS variables', async ({ page }) => {

0 commit comments

Comments
 (0)