@@ -12,6 +12,7 @@ import { assertContextCommands, assertQuickActions } from './assert'
1212import { registerAuthHook , using } from 'aws-core-vscode/test'
1313import { loginToIdC } from './utils/setup'
1414import { webviewConstants } from 'aws-core-vscode/amazonq'
15+ import { waitUntil } from 'aws-core-vscode/shared'
1516
1617describe ( 'Amazon Q Chat' , function ( ) {
1718 let framework : qTestingFramework
@@ -31,11 +32,26 @@ describe('Amazon Q Chat', function () {
3132 } )
3233
3334 // jscpd:ignore-start
34- beforeEach ( ( ) => {
35+ beforeEach ( async ( ) => {
3536 // Make sure you're logged in before every test
3637 registerAuthHook ( 'amazonq-test-account' )
3738 framework = new qTestingFramework ( 'cwc' , true , [ ] )
3839 tab = framework . createTab ( )
40+
41+ /**
42+ * Since sending messages to the UI is asynchronous, race conditions can occur
43+ * where the event is set but not fully loaded. Instead of checking the store directly,
44+ * we now use the tab title as a proxy to determine when the tab is fully ready
45+ */
46+ await waitUntil (
47+ async ( ) => {
48+ return tab . getStore ( ) . tabTitle === 'Chat'
49+ } ,
50+ {
51+ interval : 50 ,
52+ timeout : 2000 ,
53+ }
54+ )
3955 store = tab . getStore ( )
4056 } )
4157
@@ -48,6 +64,7 @@ describe('Amazon Q Chat', function () {
4864 'prompt input placeholder' : store . promptInputPlaceholder ,
4965 'quick actions' : JSON . stringify ( store . quickActionCommands ) ,
5066 'context commands' : JSON . stringify ( store . contextCommands ) ,
67+ 'tab count' : framework . getTabs ( ) . length ,
5168 } )
5269 }
5370 framework . removeTab ( tab . tabID )
0 commit comments