11/*
2- * Verify that styles and content will cascade.
2+ * Verify that content will cascade.
33 */
44
55import { test , expect } from '@playwright/test' ;
@@ -8,32 +8,54 @@ import { cssToHtml } from '../src/index';
88const css = `
99a {
1010 content: 'https://example.com/';
11- border-radius: 5px;
1211}
1312a {
1413 content: 'https://example.com/page';
15- border-radius: 10px;
14+ }
15+ .more p {}
16+ .more p span {
17+ content: 'A';
18+ }
19+ .more p span {
20+ content: 'B';
1621}
1722` ;
1823
1924test ( 'Cascading' , async ( { page } ) => {
20- await page . addScriptTag ( { path : './dist/Generator.script.js' } ) ;
21-
22- const result = await page . evaluate ( async ( css ) => {
23- document . body = await cssToHtml ( css ) ;
24- const styleElement = document . createElement ( 'style' ) ;
25- styleElement . innerText = css ;
26- document . head . append ( styleElement ) ;
27-
28- const element = document . body . querySelector ( 'a' ) ;
29- return element
30- && element . href === 'https://example.com/page'
31- && element . innerHTML === ''
32- && window . getComputedStyle ( element ) . borderRadius === '10px'
33- && element . previousSibling === null
34- && element . nextSibling === null ;
35- } , css ) ;
36-
37- expect ( result ) . toBeDefined ( ) ;
38- expect ( result ) . toBe ( true ) ;
25+ await page . goto ( 'http://localhost:5173/' ) ;
26+ const body = await page . evaluate ( async ( css ) => { document . body = await cssToHtml ( css ) ; return document . body . outerHTML ; } , css ) ;
27+
28+ // The body should have exactly two direct children.
29+ const bodyDirectChildren = page . locator ( 'body > *' ) ;
30+ expect ( await bodyDirectChildren . count ( ) ) . toBe ( 2 ) ;
31+
32+ // There should be exactly one anchor element.
33+ const anchor = page . locator ( 'a' ) ;
34+ expect ( await anchor . count ( ) ) . toBe ( 1 ) ;
35+ const anchorElement = await anchor . elementHandle ( ) ;
36+ expect ( anchorElement ) . toBeTruthy ( ) ;
37+
38+ // The anchor's href attribute should be populated.
39+ const anchorHref = await anchorElement ?. getAttribute ( 'href' ) ;
40+ expect ( anchorHref ) . toBe ( 'https://example.com/page' ) ;
41+
42+ // The anchor should not have any text content.
43+ const anchorContent = await anchorElement ?. innerHTML ( ) ;
44+ expect ( anchorContent ) . toBe ( '' ) ;
45+
46+ // The element with class `.more` should follow the anchor.
47+ const more = page . locator ( 'a + .more' ) ;
48+ expect ( await more . count ( ) ) . toBe ( 1 ) ;
49+ const moreElement = await more . elementHandle ( ) ;
50+ expect ( moreElement ) . toBeTruthy ( ) ;
51+
52+ // There should be exactly one span element.
53+ const span = page . locator ( 'span' ) ;
54+ expect ( await span . count ( ) ) . toBe ( 1 ) ;
55+ const spanElement = await span . elementHandle ( ) ;
56+ expect ( spanElement ) . toBeTruthy ( ) ;
57+
58+ // The span should have specific text content.
59+ const spanContent = await spanElement ?. innerHTML ( ) ;
60+ expect ( spanContent ) . toBe ( 'B' ) ;
3961} ) ;
0 commit comments