11import { expect } from '@playwright/test'
2- import * as mockServer from '../fixtures/mock-server'
32import {
43 chatInputMentions ,
54 clickEditorTab ,
@@ -10,7 +9,7 @@ import {
109 selectLineRangeInEditorTab ,
1110 sidebarSignin ,
1211} from './common'
13- import { type DotcomUrlOverride , executeCommandInPalette , test } from './helpers'
12+ import { executeCommandInPalette , test } from './helpers'
1413
1514test . skip ( 'chat keyboard shortcuts for sidebar chat' , async ( { page, sidebar } ) => {
1615 await page . bringToFront ( )
@@ -54,71 +53,68 @@ test.skip('re-opening chat adds selection', async ({ page, sidebar }) => {
5453 await expect ( chatInputMentions ( lastChatInput ) ) . toHaveText ( / ^ b u z z .t s : 2 - 4 $ / )
5554} )
5655
57- test . extend < DotcomUrlOverride > ( { dotcomUrl : mockServer . SERVER_URL } ) (
58- 'chat mode keyboard shortcut respects permissions' ,
59- async ( { page, sidebar } ) => {
60- await sidebarSignin ( page , sidebar )
61- const chatFrame = getChatSidebarPanel ( page )
62- const chatInput = getChatInputs ( chatFrame ) . last ( )
63-
64- // Get the initial mode (should be "Chat" by default)
65- await chatFrame . getByLabel ( 'switch-mode' ) . click ( )
56+ test ( 'chat mode keyboard shortcut respects permissions' , async ( { page, sidebar } ) => {
57+ await sidebarSignin ( page , sidebar )
58+ const chatFrame = getChatSidebarPanel ( page )
59+ const chatInput = getChatInputs ( chatFrame ) . last ( )
60+
61+ // Get the initial mode (should be "Chat" by default)
62+ await chatFrame . getByLabel ( 'switch-mode' ) . click ( )
63+
64+ // Escape to close the mode selector
65+ await page . keyboard . press ( 'Escape' )
66+
67+ // Try to cycle through modes using keyboard shortcut
68+ await page . keyboard . press ( process . platform === 'darwin' ? 'Meta+.' : 'Control+.' )
69+
70+ // Wait a moment for any state changes
71+ await page . waitForTimeout ( 500 )
72+
73+ // Check if the mode changed based on user permissions
74+ // For dotcom users, it should stay as "Chat"
75+ const modeSelectorButton = chatFrame . getByLabel ( 'switch-mode' )
76+ await modeSelectorButton . click ( )
77+ // Select the first option in the dropdown
78+ await chatFrame . getByRole ( 'option' , { name : 'Chat' } ) . click ( )
79+ await expect ( modeSelectorButton ) . toHaveText ( 'Chat' )
80+
81+ // Get the current mode after shortcut
82+ const newMode = await modeSelectorButton . textContent ( )
83+
84+ // Check which options are available and not disabled in the dropdown
85+ const availableOptions = await page . locator ( '.tw-command-item:not([disabled])' ) . count ( )
86+
87+ // If there are multiple available options, the keyboard shortcut should have changed the mode
88+ if ( availableOptions > 1 ) {
89+ // The mode should have changed from the default "Chat"
90+ expect ( newMode ) . not . toBe ( 'Chat' )
91+ } else {
92+ // If only one option is available, the mode should still be "Chat"
93+ expect ( newMode ) . toBe ( 'Chat' )
94+ }
6695
67- // Escape to close the mode selector
68- await page . keyboard . press ( 'Escape' )
96+ // Close the dropdown
97+ await page . keyboard . press ( 'Escape' )
6998
70- // Try to cycle through modes using keyboard shortcut
99+ let currentMode = await modeSelectorButton . textContent ( )
100+ // Try cycling through modes multiple times to ensure we don't get stuck
101+ for ( let i = 0 ; i < 3 ; i ++ ) {
71102 await page . keyboard . press ( process . platform === 'darwin' ? 'Meta+.' : 'Control+.' )
72-
73- // Wait a moment for any state changes
74- await page . waitForTimeout ( 500 )
75-
76- // Check if the mode changed based on user permissions
77- // For dotcom users, it should stay as "Chat"
78- const modeSelectorButton = chatFrame . getByLabel ( 'switch-mode' )
79- await modeSelectorButton . click ( )
80- // Select the first option in the dropdown
81- await chatFrame . getByRole ( 'option' , { name : 'Chat' } ) . click ( )
82- await expect ( modeSelectorButton ) . toHaveText ( 'Chat' )
83-
84- // Get the current mode after shortcut
85- const newMode = await modeSelectorButton . textContent ( )
86-
87- // Check which options are available and not disabled in the dropdown
88- const availableOptions = await page . locator ( '.tw-command-item:not([disabled])' ) . count ( )
89-
90- // If there are multiple available options, the keyboard shortcut should have changed the mode
91- if ( availableOptions > 1 ) {
92- // The mode should have changed from the default "Chat"
93- expect ( newMode ) . not . toBe ( 'Chat' )
94- } else {
95- // If only one option is available, the mode should still be "Chat"
96- expect ( newMode ) . toBe ( 'Chat' )
97- }
98-
99- // Close the dropdown
100- await page . keyboard . press ( 'Escape' )
101-
102- let currentMode = await modeSelectorButton . textContent ( )
103- // Try cycling through modes multiple times to ensure we don't get stuck
104- for ( let i = 0 ; i < 3 ; i ++ ) {
105- await page . keyboard . press ( process . platform === 'darwin' ? 'Meta+.' : 'Control+.' )
106- await page . waitForTimeout ( 300 )
107- const nextMode = await modeSelectorButton . textContent ( )
108- expect ( currentMode ) . not . toBe ( nextMode )
109- currentMode = nextMode
110- }
111-
112- // Move back to Chat mode
113- await modeSelectorButton . click ( )
114- await chatFrame . getByRole ( 'option' , { name : 'Chat' } ) . click ( )
115- await expect ( modeSelectorButton ) . toHaveText ( 'Chat' )
116-
117- // Verify we can still interact with the chat after cycling
118- await chatInput . fill ( 'Test message after cycling modes' )
119- await chatInput . press ( 'Enter' )
120-
121- // Verify a response is received
122- await expect ( chatFrame . getByText ( 'hello from the assistant' ) ) . toBeVisible ( )
103+ await page . waitForTimeout ( 300 )
104+ const nextMode = await modeSelectorButton . textContent ( )
105+ expect ( currentMode ) . not . toBe ( nextMode )
106+ currentMode = nextMode
123107 }
124- )
108+
109+ // Move back to Chat mode
110+ await modeSelectorButton . click ( )
111+ await chatFrame . getByRole ( 'option' , { name : 'Chat' } ) . click ( )
112+ await expect ( modeSelectorButton ) . toHaveText ( 'Chat' )
113+
114+ // Verify we can still interact with the chat after cycling
115+ await chatInput . fill ( 'Test message after cycling modes' )
116+ await chatInput . press ( 'Enter' )
117+
118+ // Verify a response is received
119+ await expect ( chatFrame . getByText ( 'hello from the assistant' ) ) . toBeVisible ( )
120+ } )
0 commit comments