@@ -47,18 +47,6 @@ async function getStoredHashValue(page: Page): Promise<string> {
4747 } , storageKey ) ;
4848}
4949
50- async function replaceEditorValue ( page : Page , value : string ) {
51- const codeEditor = page
52- . getByRole ( "region" , { name : "Code Editor Panel" } )
53- . getByRole ( "textbox" )
54- . nth ( 1 ) ;
55-
56- await codeEditor . click ( ) ;
57- await codeEditor . press ( "ControlOrMeta+KeyA" ) ;
58- await codeEditor . press ( "Backspace" ) ;
59- await codeEditor . pressSequentially ( value ) ;
60- }
61-
6250//-----------------------------------------------------------------------------
6351// Tests
6452//-----------------------------------------------------------------------------
@@ -70,8 +58,12 @@ test("should persist unicode code safely in the URL hash", async ({ page }) => {
7058 await page . goto ( "/" ) ;
7159
7260 const unicodeCode = 'const \u03C0 = "\u{1F600}";' ;
61+ const codeEditor = page . getByRole ( "textbox" , {
62+ name : "Code Editor" ,
63+ exact : true ,
64+ } ) ;
7365
74- await replaceEditorValue ( page , unicodeCode ) ;
66+ await codeEditor . fill ( unicodeCode ) ;
7567
7668 await expect . poll ( ( ) => getPersistedJavaScriptCode ( page ) ) . toBe ( unicodeCode ) ;
7769 await expect . poll ( ( ) => getStoredHashValue ( page ) ) . toContain ( "v2." ) ;
@@ -83,7 +75,7 @@ test("should persist unicode code safely in the URL hash", async ({ page }) => {
8375 } , storageKey ) ;
8476 await page . goto ( `/${ persistedHash } ` ) ;
8577
86- await expect ( page . locator ( ".cm-content" ) ) . toContainText ( unicodeCode ) ;
78+ await expect ( codeEditor ) . toContainText ( unicodeCode ) ;
8779} ) ;
8880
8981test ( "should still load state from legacy hash links" , async ( { page } ) => {
@@ -93,8 +85,12 @@ test("should still load state from legacy hash links", async ({ page }) => {
9385 await page . goto ( "/" ) ;
9486
9587 const legacyCode = "console.log('legacy hash');" ;
88+ const codeEditor = page . getByRole ( "textbox" , {
89+ name : "Code Editor" ,
90+ exact : true ,
91+ } ) ;
9692
97- await replaceEditorValue ( page , legacyCode ) ;
93+ await codeEditor . fill ( legacyCode ) ;
9894
9995 await expect . poll ( ( ) => getPersistedJavaScriptCode ( page ) ) . toBe ( legacyCode ) ;
10096
@@ -114,7 +110,7 @@ test("should still load state from legacy hash links", async ({ page }) => {
114110 } , storageKey ) ;
115111 await page . goto ( `/#${ legacyHash } ` ) ;
116112
117- await expect ( page . locator ( ".cm-content" ) ) . toContainText ( legacyCode ) ;
113+ await expect ( codeEditor ) . toContainText ( legacyCode ) ;
118114} ) ;
119115
120116test ( "should fall back to localStorage when a v2 hash is malformed" , async ( {
@@ -126,8 +122,12 @@ test("should fall back to localStorage when a v2 hash is malformed", async ({
126122 await page . goto ( "/" ) ;
127123
128124 const fallbackCode = "console.log('localStorage fallback');" ;
125+ const codeEditor = page . getByRole ( "textbox" , {
126+ name : "Code Editor" ,
127+ exact : true ,
128+ } ) ;
129129
130- await replaceEditorValue ( page , fallbackCode ) ;
130+ await codeEditor . fill ( fallbackCode ) ;
131131
132132 await expect
133133 . poll ( ( ) => getPersistedJavaScriptCode ( page ) )
@@ -161,5 +161,5 @@ test("should fall back to localStorage when a v2 hash is malformed", async ({
161161 ) ;
162162 await page . goto ( `/#${ malformedHash } ` ) ;
163163
164- await expect ( page . locator ( ".cm-content" ) ) . toContainText ( fallbackCode ) ;
164+ await expect ( codeEditor ) . toContainText ( fallbackCode ) ;
165165} ) ;
0 commit comments