experiments in a post-browser web
10
fork

Configure Feed

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

fix(test): correct URL detection tests to match app behavior

Fixes for URL opening tests:
- Use api.window.list() instead of non-existent windowCount()
- Check for URL in wrapped page loader format (peek://app/page/index.html?url=...)
- Allow for URL-encoded versions (%3A%2F%2F)
- Increase wait times to 1000ms for window opens
- Fix negative test to check windows list properly

Tests now properly verify:
- Domains without protocol normalize to https://
- http:// and https:// protocols preserved
- localhost URLs work
- Non-URL text isn't opened as URL

+75 -41
+75 -41
tests/desktop/smoke.spec.ts
··· 560 560 const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 561 561 await cmdWindow.waitForSelector('input', { timeout: 5000 }); 562 562 563 - // Get initial window count 564 - const initialWindows = await sharedApp.windowCount(); 565 - 566 563 // Type a domain without protocol 567 564 await cmdWindow.fill('input', 'example.com'); 568 565 await cmdWindow.keyboard.press('Enter'); 569 566 570 - // Wait for window to close (cmd panel closes after opening URL) 571 - await sleep(500); 567 + // Wait for window to open 568 + await sleep(1000); 572 569 573 - // Verify a new window was opened 574 - const finalWindows = await sharedApp.windowCount(); 575 - expect(finalWindows).toBeGreaterThan(initialWindows - 1); // -1 for closed cmd panel 570 + // Verify URL was opened (check window list for the URL) 571 + const windowList = await sharedBgWindow.evaluate(async () => { 572 + return await (window as any).app.window.list(); 573 + }); 576 574 577 - // Verify URL was normalized to https:// 578 - const newWindow = await sharedApp.getWindow('example.com', 5000); 579 - expect(newWindow).toBeTruthy(); 580 - const url = newWindow.url(); 581 - expect(url).toContain('https://example.com'); 575 + expect(windowList.success).toBe(true); 576 + // URL should be wrapped in page loader with https:// protocol 577 + const exampleWindow = windowList.windows?.find((w: any) => 578 + w.url && (w.url.includes('https://example.com') || w.url.includes('https%3A%2F%2Fexample.com')) 579 + ); 580 + expect(exampleWindow).toBeTruthy(); 582 581 583 582 // Clean up 584 - await newWindow.close(); 583 + if (exampleWindow) { 584 + await sharedBgWindow.evaluate(async (id: number) => { 585 + await (window as any).app.window.close(id); 586 + }, exampleWindow.id); 587 + } 585 588 }); 586 589 587 590 test('cmd panel opens URL with http protocol', async () => { ··· 609 612 await cmdWindow.keyboard.press('Enter'); 610 613 611 614 // Wait for window to open 612 - await sleep(500); 615 + await sleep(1000); 616 + 617 + // Verify URL was opened (should preserve http://) 618 + const windowList = await sharedBgWindow.evaluate(async () => { 619 + return await (window as any).app.window.list(); 620 + }); 613 621 614 - // Verify window opened with correct URL 615 - const newWindow = await sharedApp.getWindow('example.com', 5000); 616 - expect(newWindow).toBeTruthy(); 617 - const url = newWindow.url(); 618 - expect(url).toContain('http://example.com'); 622 + expect(windowList.success).toBe(true); 623 + const httpWindow = windowList.windows?.find((w: any) => 624 + w.url && (w.url.includes('http://example.com') || w.url.includes('http%3A%2F%2Fexample.com')) 625 + ); 626 + expect(httpWindow).toBeTruthy(); 619 627 620 628 // Clean up 621 - await newWindow.close(); 629 + if (httpWindow) { 630 + await sharedBgWindow.evaluate(async (id: number) => { 631 + await (window as any).app.window.close(id); 632 + }, httpWindow.id); 633 + } 622 634 }); 623 635 624 636 test('cmd panel opens URL with https protocol', async () => { ··· 646 658 await cmdWindow.keyboard.press('Enter'); 647 659 648 660 // Wait for window to open 649 - await sleep(500); 661 + await sleep(1000); 650 662 651 - // Verify window opened 652 - const newWindow = await sharedApp.getWindow('example.com', 5000); 653 - expect(newWindow).toBeTruthy(); 654 - const url = newWindow.url(); 655 - expect(url).toContain('https://example.com'); 663 + // Verify URL was opened 664 + const windowList = await sharedBgWindow.evaluate(async () => { 665 + return await (window as any).app.window.list(); 666 + }); 667 + 668 + expect(windowList.success).toBe(true); 669 + const httpsWindow = windowList.windows?.find((w: any) => 670 + w.url && (w.url.includes('https://example.com') || w.url.includes('https%3A%2F%2Fexample.com')) 671 + ); 672 + expect(httpsWindow).toBeTruthy(); 656 673 657 674 // Clean up 658 - await newWindow.close(); 675 + if (httpsWindow) { 676 + await sharedBgWindow.evaluate(async (id: number) => { 677 + await (window as any).app.window.close(id); 678 + }, httpsWindow.id); 679 + } 659 680 }); 660 681 661 682 test('cmd panel opens localhost URLs', async () => { ··· 683 704 await cmdWindow.keyboard.press('Enter'); 684 705 685 706 // Wait for window to open 686 - await sleep(500); 707 + await sleep(1000); 687 708 688 - // Verify window opened with normalized URL 689 - const windows = await sharedBgWindow.evaluate(async () => { 709 + // Verify URL was opened (normalized to https://localhost:3000) 710 + const windowList = await sharedBgWindow.evaluate(async () => { 690 711 return await (window as any).app.window.list(); 691 712 }); 692 713 693 - // Check that a window with localhost URL was created 694 - const localhostWindow = windows.data?.find((w: any) => 695 - w.url && (w.url.includes('localhost:3000') || w.url.includes('https://localhost:3000')) 714 + expect(windowList.success).toBe(true); 715 + const localhostWindow = windowList.windows?.find((w: any) => 716 + w.url && (w.url.includes('localhost:3000') || w.url.includes('localhost%3A3000')) 696 717 ); 697 718 expect(localhostWindow).toBeTruthy(); 698 719 699 - // Clean up - close by window ID 720 + // Clean up 700 721 if (localhostWindow) { 701 722 await sharedBgWindow.evaluate(async (id: number) => { 702 723 await (window as any).app.window.close(id); ··· 724 745 const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 725 746 await cmdWindow.waitForSelector('input', { timeout: 5000 }); 726 747 727 - // Get initial window count 728 - const initialWindows = await sharedApp.windowCount(); 748 + // Get initial window list 749 + const initialList = await sharedBgWindow.evaluate(async () => { 750 + return await (window as any).app.window.list(); 751 + }); 752 + const initialCount = initialList.windows?.length || 0; 729 753 730 754 // Type non-URL text (no dots, no protocol) 731 755 await cmdWindow.fill('input', 'notaurl'); 732 756 await cmdWindow.keyboard.press('Enter'); 733 757 734 758 // Wait a moment 735 - await sleep(500); 759 + await sleep(1000); 760 + 761 + // Verify no new URL window was opened 762 + const finalList = await sharedBgWindow.evaluate(async () => { 763 + return await (window as any).app.window.list(); 764 + }); 765 + const finalCount = finalList.windows?.length || 0; 736 766 737 - // Verify no new window was opened (or cmd panel tried to execute command) 738 - const finalWindows = await sharedApp.windowCount(); 767 + // Check that 'notaurl' was NOT opened as a URL 768 + const notaurlWindow = finalList.windows?.find((w: any) => 769 + w.url && w.url.includes('notaurl') 770 + ); 771 + expect(notaurlWindow).toBeFalsy(); 772 + 739 773 // Window count should be same or less (cmd panel might close) 740 - expect(finalWindows).toBeLessThanOrEqual(initialWindows); 774 + expect(finalCount).toBeLessThanOrEqual(initialCount); 741 775 742 776 // Close cmd panel if still open 743 777 if (openResult.id) {