experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(tests): deterministic param mode tests, correct addItem API calls

+48 -60
+48 -60
tests/desktop/smoke.spec.ts
··· 151 151 expect(addResult.success).toBe(true); 152 152 const noteId = addResult.data?.id; 153 153 154 + // Set up editor:open event capture BEFORE opening the cmd panel 155 + await sharedBgWindow.evaluate(() => { 156 + (window as any).__editorOpenCaptured = []; 157 + (window as any).__editorOpenUnsub = (window as any).app.subscribe('editor:open', (data: any) => { 158 + (window as any).__editorOpenCaptured.push(data); 159 + }, (window as any).app.scopes.GLOBAL); 160 + }); 161 + 154 162 // Open cmd panel 155 163 const openResult = await sharedBgWindow.evaluate(async () => { 156 164 return await (window as any).app.window.open('peek://ext/cmd/panel.html', { ··· 171 179 await cmdWindow.waitForSelector('input', { timeout: 5000 }); 172 180 await waitForPanelCommandsLoaded(cmdWindow, 10000); 173 181 174 - // Type "edit" and press Tab to trigger param mode 175 - await cmdWindow.fill('input', 'edit'); 176 - // Press ArrowDown first to show results, then Tab to complete 177 - await cmdWindow.keyboard.press('ArrowDown'); 178 - await waitForCommandResults(cmdWindow, 1, 10000); 179 - await cmdWindow.keyboard.press('Tab'); 180 - 181 - // Verify param mode is active - the panel should show autocomplete suggestions 182 - // The input should now be "edit " (with trailing space) 183 - const paramModeActive = await cmdWindow.waitForFunction( 184 - () => { 185 - const state = (window as any)._cmdState; 186 - return state && state.paramMode === true && state.paramCommand === 'edit'; 187 - }, 188 - undefined, 189 - { timeout: 5000 } 190 - ); 191 - expect(paramModeActive).toBeTruthy(); 182 + // Type "edit " (with space) to commit to the edit command and enter param mode 183 + // (Tab would cycle to 'editor' since both "edit" and "editor" match) 184 + await cmdWindow.fill('input', 'edit '); 192 185 193 - // Wait for param suggestions to populate (autocomplete list of notes) 186 + // Wait for param mode and suggestions to populate 194 187 await cmdWindow.waitForFunction( 195 188 () => { 196 189 const state = (window as any)._cmdState; 197 - return state && state.paramSuggestions && state.paramSuggestions.length > 0; 190 + return state && state.paramMode === true && state.paramCommand === 'edit' 191 + && state.paramSuggestions && state.paramSuggestions.length > 0; 198 192 }, 199 193 undefined, 200 - { timeout: 5000 } 194 + { timeout: 10000 } 201 195 ); 202 196 203 197 // Verify results are visible with suggestion items 204 198 await waitForResultsWithContent(cmdWindow, 5000); 205 199 206 - // Listen for editor:open event before selecting the suggestion 207 - const editorOpenPromise = sharedBgWindow.evaluate(async () => { 208 - return new Promise<any>((resolve) => { 209 - const unsub = (window as any).app.subscribe('editor:open', (data: any) => { 210 - unsub(); 211 - resolve(data); 212 - }, (window as any).app.scopes.GLOBAL); 213 - // Timeout after 10s 214 - setTimeout(() => { 215 - unsub(); 216 - resolve(null); 217 - }, 10000); 218 - }); 219 - }); 220 - 221 200 // Press Enter to accept the first suggestion 222 - // This should route through execute() and open the editor 201 + // This executes the edit command, publishes editor:open, and closes the panel 223 202 await cmdWindow.keyboard.press('Enter'); 224 203 225 - // Verify editor:open was published (the command executed properly) 226 - const editorOpenData = await editorOpenPromise; 204 + // Verify editor:open was published by polling the captured events 205 + await sharedBgWindow.waitForFunction(() => { 206 + return (window as any).__editorOpenCaptured && (window as any).__editorOpenCaptured.length > 0; 207 + }, undefined, { timeout: 10000 }); 208 + 209 + const editorOpenData = await sharedBgWindow.evaluate(() => { 210 + return (window as any).__editorOpenCaptured[0]; 211 + }); 227 212 expect(editorOpenData).toBeTruthy(); 213 + 214 + // Clean up event listener 215 + await sharedBgWindow.evaluate(() => { 216 + if ((window as any).__editorOpenUnsub) { 217 + (window as any).__editorOpenUnsub(); 218 + } 219 + delete (window as any).__editorOpenCaptured; 220 + delete (window as any).__editorOpenUnsub; 221 + }); 228 222 229 223 // Close cmd window if still open 230 224 try { ··· 3148 3142 test('Tab in param mode fills text, does NOT execute', async () => { 3149 3143 // Create a test note so param mode has suggestions 3150 3144 const createResult = await bgWindow.evaluate(async () => { 3151 - return await (window as any).app.datastore.addItem({ 3152 - type: 'text', 3145 + return await (window as any).app.datastore.addItem('text', { 3153 3146 content: '# Tab Test Note\nThis is a note for testing Tab in param mode.' 3154 3147 }); 3155 3148 }); ··· 3176 3169 await cmdWindow.waitForSelector('input', { timeout: 5000 }); 3177 3170 await waitForPanelCommandsLoaded(cmdWindow); 3178 3171 3179 - // Type 'edit' and Tab to enter param mode 3180 - await cmdWindow.fill('input', 'edit'); 3181 - await cmdWindow.keyboard.press('ArrowDown'); 3182 - await waitForCommandResults(cmdWindow, 1, 10000); 3183 - await cmdWindow.keyboard.press('Tab'); 3172 + // Type 'edit ' (with space) to commit to the edit command and enter param mode 3173 + // (Tab would cycle to 'editor' since both match 'edit') 3174 + await cmdWindow.fill('input', 'edit '); 3184 3175 3185 - // Verify param mode is active 3186 - const paramModeActive = await cmdWindow.evaluate(() => { 3187 - return (window as any)._cmdState.paramMode === true; 3188 - }); 3189 - expect(paramModeActive).toBe(true); 3176 + // Wait for param mode to activate 3177 + await cmdWindow.waitForFunction(() => { 3178 + const s = (window as any)._cmdState; 3179 + return s.paramMode === true && s.paramCommand === 'edit'; 3180 + }, { timeout: 5000 }); 3190 3181 3191 3182 // Wait for param suggestions to load (items query) 3192 3183 await cmdWindow.waitForFunction(() => { ··· 3223 3214 test('Enter in param mode executes with correct itemId', async () => { 3224 3215 // Create a test note 3225 3216 const createResult = await bgWindow.evaluate(async () => { 3226 - return await (window as any).app.datastore.addItem({ 3227 - type: 'text', 3217 + return await (window as any).app.datastore.addItem('text', { 3228 3218 content: '# Enter Test Note\nThis is a note for testing Enter in param mode.' 3229 3219 }); 3230 3220 }); ··· 3259 3249 await cmdWindow.waitForSelector('input', { timeout: 5000 }); 3260 3250 await waitForPanelCommandsLoaded(cmdWindow); 3261 3251 3262 - // Type 'edit' and Tab to enter param mode 3263 - await cmdWindow.fill('input', 'edit'); 3264 - await cmdWindow.keyboard.press('ArrowDown'); 3265 - await waitForCommandResults(cmdWindow, 1, 10000); 3266 - await cmdWindow.keyboard.press('Tab'); 3252 + // Type 'edit ' (with space) to commit to the edit command and enter param mode 3253 + await cmdWindow.fill('input', 'edit '); 3267 3254 3268 - // Wait for param suggestions to load 3255 + // Wait for param mode and suggestions to load 3269 3256 await cmdWindow.waitForFunction(() => { 3270 - return (window as any)._cmdState.paramSuggestions.length > 0; 3257 + const s = (window as any)._cmdState; 3258 + return s.paramMode === true && s.paramCommand === 'edit' && s.paramSuggestions.length > 0; 3271 3259 }, { timeout: 10000 }); 3272 3260 3273 3261 // Find the index of our test note in suggestions