11import { injectRuffleAndWait , openTest , playAndMonitor } from "../../utils.js" ;
2- import { use , expect } from "chai" ;
3- import chaiHtml from "chai-html" ;
4- import fs from "fs" ;
5-
6- use ( chaiHtml ) ;
2+ import { expect } from "chai" ;
73
84describe ( "Document embeds" , ( ) => {
95 it ( "loads the test" , async ( ) => {
106 await openTest ( browser , `polyfill/document_embeds` ) ;
117 } ) ;
128
139 it ( "Accesses the right number of elements with ruffle" , async ( ) => {
10+ async function countDocumentEmbeds ( ) {
11+ return await browser . execute ( ( ) => {
12+ return document . embeds ?. length ?? 0 ;
13+ } ) ;
14+ }
15+
16+ async function removeEl ( selector : string ) {
17+ const el = await $ ( selector ) ;
18+ await browser . execute ( ( element ) => {
19+ element . remove ( ) ;
20+ } , el ) ;
21+ }
22+
1423 await injectRuffleAndWait ( browser ) ;
1524 await playAndMonitor (
1625 browser ,
@@ -24,32 +33,10 @@ describe("Document embeds", () => {
2433 browser ,
2534 await browser . $ ( "#test-container" ) . $ ( "ruffle-embed#emb3" ) ,
2635 ) ;
27- await browser . execute ( ( ) => {
28- function countDocumentEmbeds ( ) {
29- const output = document . getElementById ( "output" ) ;
30- const els = document . embeds ;
31- const len = document . createElement ( "li" ) ;
32- if ( els && "length" in els && els . length ) {
33- len . textContent = `There are ${ els . length } embeds for document.embeds` ;
34- }
35-
36- output ?. appendChild ( len ) ;
37- }
38-
39- countDocumentEmbeds ( ) ;
40- const emb1 = document . getElementById ( "emb1" ) ;
41- if ( emb1 ) {
42- emb1 . remove ( ) ;
43- }
44- countDocumentEmbeds ( ) ;
45- } ) ;
46- const actual = await browser
47- . $ ( "#output" )
48- . getHTML ( { includeSelectorTag : false , pierceShadowRoot : false } ) ;
49- const expected = fs . readFileSync (
50- `${ import . meta. dirname } /expected.html` ,
51- "utf8" ,
52- ) ;
53- expect ( actual ) . html . to . equal ( expected ) ;
36+ const embeds1 = await countDocumentEmbeds ( ) ;
37+ expect ( embeds1 ) . to . equal ( 3 ) ;
38+ await removeEl ( "#emb1" ) ;
39+ const embeds2 = await countDocumentEmbeds ( ) ;
40+ expect ( embeds2 ) . to . equal ( 2 ) ;
5441 } ) ;
5542} ) ;
0 commit comments