11import { 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
44async 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
1717test ( '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
4040test ( '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
10663test ( 'Callouts can be customized using SCSS variables' , async ( { page } ) => {
0 commit comments