experiments in a post-browser web
10
fork

Configure Feed

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

test(cmd): add comprehensive URL detection tests for command panel

Tests cover all URL detection scenarios:
- Domain without protocol (youtube.com) → normalized to https://
- http:// URLs → opened as-is
- https:// URLs → opened as-is
- localhost with port → normalized to https://localhost:port
- Non-URL text → not detected as URL (negative test)

Tests verify:
- URL detection regex works correctly
- Window opens after URL is detected
- URL is properly normalized before opening
- cmd panel closes after opening URL
- Non-URLs don't trigger URL opening

Related to fix in rpmrxoow (URL detection regression from command refactor)

+211
+211
tests/desktop/smoke.spec.ts
··· 539 539 // Ensure the API is ready 540 540 await waitForAppReady(sharedBgWindow); 541 541 }); 542 + 543 + test('cmd panel detects and opens domain without protocol (youtube.com)', async () => { 544 + await waitForExtensionsReady(sharedBgWindow, 15000); 545 + 546 + // Open cmd panel 547 + const openResult = await sharedBgWindow.evaluate(async () => { 548 + return await (window as any).app.window.open('peek://ext/cmd/panel.html', { 549 + modal: true, 550 + width: 600, 551 + height: 50, 552 + frame: false, 553 + transparent: true, 554 + alwaysOnTop: true, 555 + center: true 556 + }); 557 + }); 558 + expect(openResult.success).toBe(true); 559 + 560 + const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 561 + await cmdWindow.waitForSelector('input', { timeout: 5000 }); 562 + 563 + // Get initial window count 564 + const initialWindows = await sharedApp.windowCount(); 565 + 566 + // Type a domain without protocol 567 + await cmdWindow.fill('input', 'example.com'); 568 + await cmdWindow.keyboard.press('Enter'); 569 + 570 + // Wait for window to close (cmd panel closes after opening URL) 571 + await sleep(500); 572 + 573 + // Verify a new window was opened 574 + const finalWindows = await sharedApp.windowCount(); 575 + expect(finalWindows).toBeGreaterThan(initialWindows - 1); // -1 for closed cmd panel 576 + 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'); 582 + 583 + // Clean up 584 + await newWindow.close(); 585 + }); 586 + 587 + test('cmd panel opens URL with http protocol', async () => { 588 + await waitForExtensionsReady(sharedBgWindow, 15000); 589 + 590 + // Open cmd panel 591 + const openResult = await sharedBgWindow.evaluate(async () => { 592 + return await (window as any).app.window.open('peek://ext/cmd/panel.html', { 593 + modal: true, 594 + width: 600, 595 + height: 50, 596 + frame: false, 597 + transparent: true, 598 + alwaysOnTop: true, 599 + center: true 600 + }); 601 + }); 602 + expect(openResult.success).toBe(true); 603 + 604 + const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 605 + await cmdWindow.waitForSelector('input', { timeout: 5000 }); 606 + 607 + // Type URL with http protocol 608 + await cmdWindow.fill('input', 'http://example.com'); 609 + await cmdWindow.keyboard.press('Enter'); 610 + 611 + // Wait for window to open 612 + await sleep(500); 613 + 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'); 619 + 620 + // Clean up 621 + await newWindow.close(); 622 + }); 623 + 624 + test('cmd panel opens URL with https protocol', async () => { 625 + await waitForExtensionsReady(sharedBgWindow, 15000); 626 + 627 + // Open cmd panel 628 + const openResult = await sharedBgWindow.evaluate(async () => { 629 + return await (window as any).app.window.open('peek://ext/cmd/panel.html', { 630 + modal: true, 631 + width: 600, 632 + height: 50, 633 + frame: false, 634 + transparent: true, 635 + alwaysOnTop: true, 636 + center: true 637 + }); 638 + }); 639 + expect(openResult.success).toBe(true); 640 + 641 + const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 642 + await cmdWindow.waitForSelector('input', { timeout: 5000 }); 643 + 644 + // Type URL with https protocol 645 + await cmdWindow.fill('input', 'https://example.com'); 646 + await cmdWindow.keyboard.press('Enter'); 647 + 648 + // Wait for window to open 649 + await sleep(500); 650 + 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'); 656 + 657 + // Clean up 658 + await newWindow.close(); 659 + }); 660 + 661 + test('cmd panel opens localhost URLs', async () => { 662 + await waitForExtensionsReady(sharedBgWindow, 15000); 663 + 664 + // Open cmd panel 665 + const openResult = await sharedBgWindow.evaluate(async () => { 666 + return await (window as any).app.window.open('peek://ext/cmd/panel.html', { 667 + modal: true, 668 + width: 600, 669 + height: 50, 670 + frame: false, 671 + transparent: true, 672 + alwaysOnTop: true, 673 + center: true 674 + }); 675 + }); 676 + expect(openResult.success).toBe(true); 677 + 678 + const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 679 + await cmdWindow.waitForSelector('input', { timeout: 5000 }); 680 + 681 + // Type localhost with port 682 + await cmdWindow.fill('input', 'localhost:3000'); 683 + await cmdWindow.keyboard.press('Enter'); 684 + 685 + // Wait for window to open 686 + await sleep(500); 687 + 688 + // Verify window opened with normalized URL 689 + const windows = await sharedBgWindow.evaluate(async () => { 690 + return await (window as any).app.window.list(); 691 + }); 692 + 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')) 696 + ); 697 + expect(localhostWindow).toBeTruthy(); 698 + 699 + // Clean up - close by window ID 700 + if (localhostWindow) { 701 + await sharedBgWindow.evaluate(async (id: number) => { 702 + await (window as any).app.window.close(id); 703 + }, localhostWindow.id); 704 + } 705 + }); 706 + 707 + test('cmd panel does not treat non-URL text as URL', async () => { 708 + await waitForExtensionsReady(sharedBgWindow, 15000); 709 + 710 + // Open cmd panel 711 + const openResult = await sharedBgWindow.evaluate(async () => { 712 + return await (window as any).app.window.open('peek://ext/cmd/panel.html', { 713 + modal: true, 714 + width: 600, 715 + height: 50, 716 + frame: false, 717 + transparent: true, 718 + alwaysOnTop: true, 719 + center: true 720 + }); 721 + }); 722 + expect(openResult.success).toBe(true); 723 + 724 + const cmdWindow = await sharedApp.getWindow('cmd/panel.html', 5000); 725 + await cmdWindow.waitForSelector('input', { timeout: 5000 }); 726 + 727 + // Get initial window count 728 + const initialWindows = await sharedApp.windowCount(); 729 + 730 + // Type non-URL text (no dots, no protocol) 731 + await cmdWindow.fill('input', 'notaurl'); 732 + await cmdWindow.keyboard.press('Enter'); 733 + 734 + // Wait a moment 735 + await sleep(500); 736 + 737 + // Verify no new window was opened (or cmd panel tried to execute command) 738 + const finalWindows = await sharedApp.windowCount(); 739 + // Window count should be same or less (cmd panel might close) 740 + expect(finalWindows).toBeLessThanOrEqual(initialWindows); 741 + 742 + // Close cmd panel if still open 743 + if (openResult.id) { 744 + await sharedBgWindow.evaluate(async (id: number) => { 745 + try { 746 + await (window as any).app.window.close(id); 747 + } catch (e) { 748 + // Already closed 749 + } 750 + }, openResult.id); 751 + } 752 + }); 542 753 }); 543 754 544 755 // ============================================================================