@@ -61,4 +61,62 @@ describe("pat-content-mirror", () => {
6161        expect ( mirror2 . textContent ) . toBe ( "this is a test text 2." ) ; 
6262    } ) ; 
6363
64+     it ( "works with multiple content mirrors, placeholders and form resets." ,  async  ( )  =>  { 
65+         document . body . innerHTML  =  ` 
66+             <form> 
67+                 <p class="mirror-1"> 
68+                     <span class="text"> 
69+                         <em class="placeholder"></em> 
70+                     </span> 
71+                 </p> 
72+                 <textarea 
73+                     class="txt-1 pat-content-mirror" 
74+                     data-pat-content-mirror="target:.mirror-1 .text" 
75+                     placeholder="placeholder 1"></textarea> 
76+ 
77+                 <p class="mirror-2"> 
78+                     <span class="text"> 
79+                         <em class="placeholder"></em> 
80+                     </span> 
81+                 </p> 
82+                 <textarea 
83+                     class="txt-2 pat-content-mirror" 
84+                     data-pat-content-mirror="target:.mirror-2 .text" 
85+                     placeholder="placeholder 2"></textarea> 
86+ 
87+                 <button type="reset">Reset</button> 
88+             </form> 
89+         ` ; 
90+ 
91+         const  txt1  =  document . querySelector ( ".txt-1" ) ; 
92+         const  txt2  =  document . querySelector ( ".txt-2" ) ; 
93+ 
94+         const  mirror1  =  document . querySelector ( ".mirror-1 .text" ) ; 
95+         const  mirror2  =  document . querySelector ( ".mirror-2 .text" ) ; 
96+ 
97+         const  instance1  =  new  Pattern ( txt1 ) ; 
98+         const  instance2  =  new  Pattern ( txt2 ) ; 
99+ 
100+         await  events . await_pattern_init ( instance1 ) ; 
101+         await  events . await_pattern_init ( instance2 ) ; 
102+ 
103+         expect ( mirror1 . textContent . trim ( ) ) . toBe ( "placeholder 1" ) ; 
104+         expect ( mirror2 . textContent . trim ( ) ) . toBe ( "placeholder 2" ) ; 
105+ 
106+         txt1 . value  =  "this is a test text 1." ; 
107+         txt2 . value  =  "this is a test text 2." ; 
108+ 
109+         txt1 . dispatchEvent ( new  Event ( "input" ) ) ; 
110+         txt2 . dispatchEvent ( new  Event ( "input" ) ) ; 
111+ 
112+         expect ( mirror1 . textContent ) . toBe ( "this is a test text 1." ) ; 
113+         expect ( mirror2 . textContent ) . toBe ( "this is a test text 2." ) ; 
114+ 
115+         const  button  =  document . querySelector ( "button" ) ; 
116+         button . click ( ) ; 
117+ 
118+         expect ( mirror1 . textContent . trim ( ) ) . toBe ( "placeholder 1" ) ; 
119+         expect ( mirror2 . textContent ) . toBe ( "placeholder 2" ) ; 
120+     } ) ; 
121+ 
64122} ) ; 
0 commit comments