@@ -3,50 +3,137 @@ import { waitForLoadingDone } from './video';
33
44export const LLM_TIMEOUT = 30000 ;
55
6- export async function sendMessage ( page : Page , text : string ) : Promise < void > {
7- const chatInput = page . locator ( '[data-testid="chat-input"]:visible' ) . first ( ) ;
6+ export const getChatInput = ( page : Page ) =>
7+ page . locator ( '[data-testid="chat-input"]:visible' ) . first ( ) ;
8+
9+ export const sendMessage = async ( page : Page , text : string ) => {
10+ const chatInput = getChatInput ( page ) ;
811 await chatInput . fill ( text ) ;
912 await chatInput . press ( 'Enter' ) ;
1013 await waitForLoadingDone ( page , LLM_TIMEOUT ) ;
11- }
14+ } ;
1215
13- export async function expectChatMessageCount ( page : Page , count : number ) : Promise < void > {
16+ export const expectChatMessageCount = async ( page : Page , count : number ) = > {
1417 await expect ( page . locator ( '[data-testid="message-container"]:visible' ) ) . toHaveCount ( count ) ;
15- }
18+ } ;
1619
17- export async function expectChatContainsMessage ( page : Page , text : string ) : Promise < void > {
20+ export const expectChatContainsMessage = async ( page : Page , text : string ) = > {
1821 await expect (
1922 page . locator ( '[data-testid="message-container"]:visible' ) . filter ( { hasText : text } ) . first ( )
2023 ) . toBeVisible ( ) ;
21- }
24+ } ;
2225
23- export async function expectLastChatMessageContains ( page : Page , text : string | RegExp ) : Promise < void > {
26+ export const expectLastChatMessageContains = async ( page : Page , text : string | RegExp ) = > {
2427 await expect ( page . locator ( '[data-testid="message-container"]:visible' ) . last ( ) ) . toContainText ( text ) ;
25- }
28+ } ;
29+
30+ export const getToolCalls = ( page : Page ) =>
31+ page . locator ( '.goose-message-tool' ) ;
32+
33+ export const expectToolCallCount = async ( page : Page , count : number ) => {
34+ await expect ( getToolCalls ( page ) ) . toHaveCount ( count ) ;
35+ } ;
36+
37+ export const expectToolCallContainsText = async ( page : Page , position : number , expectedText : string | RegExp ) => {
38+ const toolCall = getToolCalls ( page ) . nth ( position - 1 ) ;
39+ await expect ( toolCall ) . toBeVisible ( ) ;
40+ const tooltipTrigger = toolCall . locator ( 'button.group.w-full span.cursor-pointer' ) . first ( ) ;
41+ await expect ( tooltipTrigger ) . toBeVisible ( ) ;
42+ await tooltipTrigger . hover ( ) ;
43+ await expect ( page . getByTestId ( 'tooltip-wrapper-content' ) . first ( ) ) . toContainText ( expectedText ) ;
44+ } ;
45+
46+ export const getLastAssistantMessageText = async ( page : Page ) => {
47+ return ( await page . locator ( '.goose-message' ) . last ( ) . textContent ( ) ) ?? '' ;
48+ } ;
2649
27- export async function goToHome ( page : Page ) : Promise < void > {
50+ export const goToHome = async ( page : Page ) = > {
2851 await page . getByTestId ( 'sidebar-home-button' ) . click ( ) ;
29- }
52+ } ;
3053
31- export async function expectSessionCount ( page : Page , count : number ) : Promise < void > {
54+ export const expectSessionCount = async ( page : Page , count : number ) = > {
3255 await expect ( page . getByTestId ( 'session-history-card' ) ) . toHaveCount ( count ) ;
33- }
56+ } ;
3457
35- export async function goToChatHistory ( page : Page ) : Promise < void > {
58+ export const clickSidebarChat = async ( page : Page ) => {
59+ await page . getByTestId ( 'sidebar-chat-button' ) . click ( ) ;
60+ } ;
61+
62+ export const goToChatHistory = async ( page : Page ) => {
3663 const showAll = page . getByTestId ( 'chat-show-all' ) . first ( ) ;
3764 if ( ! ( await showAll . isVisible ( ) . catch ( ( ) => false ) ) ) {
38- await page . getByTestId ( 'sidebar-chat-button' ) . click ( ) ;
65+ await clickSidebarChat ( page ) ;
3966 }
4067 await expect ( showAll ) . toBeVisible ( ) ;
4168 await showAll . click ( ) ;
4269 await expect ( page . getByRole ( 'heading' , { name : 'Chat history' } ) ) . toBeVisible ( ) ;
43- }
70+ } ;
4471
45- export async function openSession ( page : Page , position : number ) : Promise < void > {
72+ export const openSession = async ( page : Page , position : number ) = > {
4673 await page . getByTestId ( 'session-history-card' ) . nth ( position - 1 ) . click ( ) ;
47- }
74+ } ;
75+
76+ export const startNewChat = async ( page : Page ) => {
77+ const newChatButton = page . getByRole ( 'button' , { name : 'New Chat' } ) . first ( ) ;
78+ if ( ! ( await newChatButton . isVisible ( ) . catch ( ( ) => false ) ) ) {
79+ await clickSidebarChat ( page ) ;
80+ }
81+ await newChatButton . click ( ) ;
82+ } ;
83+
84+ export const goToExtensions = async ( page : Page ) => {
85+ await page . getByTestId ( 'sidebar-extensions-button' ) . click ( ) ;
86+ } ;
87+
88+ export const expectExtensionIsEnabled = async ( page : Page , extensionId : string ) => {
89+ await expect ( page . locator ( `#extension-${ extensionId } ` ) ) . toBeVisible ( ) ;
90+ await expect (
91+ page . locator ( `#extension-${ extensionId } button[role="switch"][data-state="checked"]` )
92+ ) . toBeVisible ( ) ;
93+ } ;
94+
95+ export const createCustomExtension = async ( page : Page , opts : { name : string ; description : string ; command : string } ) => {
96+ await page . getByRole ( 'button' , { name : 'Add custom extension' } ) . click ( ) ;
97+ await page . getByPlaceholder ( 'Enter extension name...' ) . fill ( opts . name ) ;
98+ await page . getByPlaceholder ( 'Optional description...' ) . fill ( opts . description ) ;
99+ await page . getByPlaceholder ( 'e.g. npx -y @modelcontextprotocol/my-extension <filepath>' ) . fill ( opts . command ) ;
100+ await page . getByTestId ( 'extension-submit-btn' ) . click ( ) ;
101+ } ;
102+
103+ export const expectCostIsZero = async ( page : Page ) => {
104+ const costTrigger = page . getByTestId ( 'bottom-menu-cost-trigger' ) . first ( ) ;
105+ const costTooltip = page . getByTestId ( 'bottom-menu-cost-tooltip' ) . first ( ) ;
106+ await expect ( costTrigger ) . toContainText ( '0.0000' ) ;
107+ await costTrigger . hover ( ) ;
108+ await expect ( costTooltip ) . toContainText (
109+ 'Input: 0 tokens ($0.000000) | Output: 0 tokens ($0.000000)'
110+ ) ;
111+ } ;
112+
113+ export const expectCostIsNonZero = async ( page : Page ) => {
114+ const costTrigger = page . getByTestId ( 'bottom-menu-cost-trigger' ) . first ( ) ;
115+ const costTooltip = page . getByTestId ( 'bottom-menu-cost-tooltip' ) . first ( ) ;
116+ await costTrigger . hover ( ) ;
117+ await expect ( costTrigger ) . not . toContainText ( '0.0000' ) ;
118+ await expect ( costTooltip ) . not . toContainText (
119+ 'Input: 0 tokens ($0.000000) | Output: 0 tokens ($0.000000)'
120+ ) ;
121+ } ;
122+
123+ export const changeWorkingDirectory = async ( page : Page ) => {
124+ const workingDirButton = page . locator ( '[data-testid="bottom-menu-dir-switcher"]:visible' ) . first ( ) ;
125+ await expect ( workingDirButton ) . toBeVisible ( ) ;
126+ const oldWorkingDir = ( await workingDirButton . textContent ( ) ) ?. trim ( ) ?? '' ;
127+ await workingDirButton . click ( ) ;
128+ if ( oldWorkingDir ) {
129+ await expect ( workingDirButton ) . not . toContainText ( oldWorkingDir ) ;
130+ }
131+ const updatedWorkingDir = ( await workingDirButton . textContent ( ) ) ?. trim ( ) ?? '' ;
132+ expect ( updatedWorkingDir . length ) . toBeGreaterThan ( 0 ) ;
133+ return updatedWorkingDir ;
134+ } ;
48135
49- export async function openSettingsAppTab ( page : Page ) : Promise < void > {
136+ export const openSettingsAppTab = async ( page : Page ) = > {
50137 await page . getByTestId ( 'sidebar-settings-button' ) . click ( ) ;
51138 await page . getByTestId ( 'settings-app-tab' ) . click ( ) ;
52- }
139+ } ;
0 commit comments