@@ -3,7 +3,8 @@ import {expect, test} from '@playwright/test';
33import { QUERY_MODES } from '../../../../src/utils/query' ;
44import { tenantName } from '../../../utils/constants' ;
55import { TenantPage , VISIBILITY_TIMEOUT } from '../TenantPage' ;
6- import { QueryEditor } from '../queryEditor/models/QueryEditor' ;
6+ import { QueryEditor , QueryTabs } from '../queryEditor/models/QueryEditor' ;
7+ import { UnsavedChangesModal } from '../queryEditor/models/UnsavedChangesModal' ;
78
89import executeQueryWithKeybinding from './utils' ;
910
@@ -23,23 +24,22 @@ test.describe('Query History', () => {
2324 queryEditor = new QueryEditor ( page ) ;
2425 } ) ;
2526
26- test ( 'New query appears in history after execution' , async ( { page } ) => {
27+ test ( 'New query appears in history after execution' , async ( ) => {
2728 const testQuery = 'SELECT 1 AS test_column;' ;
2829
2930 // Execute the query
3031 await queryEditor . run ( testQuery , QUERY_MODES . script ) ;
3132
32- // Navigate to the history tab
33- await page . click ( 'text= History' ) ;
33+ // Navigate to the history tab using existing navigation method
34+ await queryEditor . queryTabs . selectTab ( QueryTabs . History ) ;
3435
3536 // Check if the query appears in the history
36- const historyTable = page . locator ( '.ydb-queries-history table' ) ;
37- await expect ( historyTable . locator ( '.yql-highlighter' , { hasText : testQuery } ) ) . toBeVisible ( {
38- timeout : VISIBILITY_TIMEOUT ,
39- } ) ;
37+ await queryEditor . historyQueries . isVisible ( ) ;
38+ const queryRow = await queryEditor . historyQueries . getQueryRow ( testQuery ) ;
39+ await expect ( queryRow ) . toBeVisible ( { timeout : VISIBILITY_TIMEOUT } ) ;
4040 } ) ;
4141
42- test ( 'Multiple queries appear in correct order in history' , async ( { page } ) => {
42+ test ( 'Multiple queries appear in correct order in history' , async ( ) => {
4343 const queries = [
4444 'SELECT 1 AS first_query;' ,
4545 'SELECT 2 AS second_query;' ,
@@ -51,17 +51,19 @@ test.describe('Query History', () => {
5151 await queryEditor . run ( query , QUERY_MODES . script ) ;
5252 }
5353
54- // Navigate to the history tab
55- await page . click ( 'text= History' ) ;
54+ // Navigate to the history tab using existing navigation method
55+ await queryEditor . queryTabs . selectTab ( QueryTabs . History ) ;
5656
5757 // Check if queries appear in reverse order (most recent first)
58- const historyTable = page . locator ( '.ydb-queries-history table' ) ;
59- const rows = historyTable . locator ( 'tbody tr' ) ;
60-
61- await expect ( rows ) . toHaveCount ( queries . length ) ;
58+ await queryEditor . historyQueries . isVisible ( ) ;
6259
6360 for ( let i = 0 ; i < queries . length ; i ++ ) {
64- await expect ( rows . nth ( i ) ) . toContainText ( queries [ queries . length - 1 - i ] ) ;
61+ const queryRow = await queryEditor . historyQueries . getQueryRow (
62+ queries [ queries . length - 1 - i ] ,
63+ ) ;
64+ await expect ( queryRow ) . toBeVisible ( ) ;
65+ const queryText = await queryEditor . historyQueries . getQueryText ( i ) ;
66+ expect ( queryText ) . toContain ( queries [ queries . length - 1 - i ] ) ;
6567 }
6668 } ) ;
6769
@@ -77,14 +79,40 @@ test.describe('Query History', () => {
7779 // Use the keybinding to execute the query
7880 await executeQueryWithKeybinding ( page , browserName ) ;
7981
80- // Wait for the query to be executed
81- await page . waitForSelector ( '.ydb-query-result-sets-viewer__result' , { timeout : 10000 } ) ;
82+ // Wait for query results
83+ await queryEditor . resultTable . isVisible ( ) ;
8284
83- // Navigate to the history tab
84- await page . click ( 'text= History' ) ;
85+ // Navigate to the history tab using existing navigation method
86+ await queryEditor . queryTabs . selectTab ( QueryTabs . History ) ;
8587
8688 // Check if the query appears in the history
87- const historyTable = page . locator ( '.ydb-queries-history table' ) ;
88- await expect ( historyTable . locator ( '.yql-highlighter' , { hasText : testQuery } ) ) . toBeVisible ( ) ;
89+ await queryEditor . historyQueries . isVisible ( ) ;
90+ const queryRow = await queryEditor . historyQueries . getQueryRow ( testQuery ) ;
91+ await expect ( queryRow ) . toBeVisible ( ) ;
92+ } ) ;
93+
94+ test ( 'Can run query from history' , async ( { page} ) => {
95+ const testQuery = 'SELECT 42 AS history_run_test;' ;
96+ const unsavedChangesModal = new UnsavedChangesModal ( page ) ;
97+
98+ // Execute the query first time
99+ await queryEditor . run ( testQuery , QUERY_MODES . script ) ;
100+
101+ // Navigate to the history tab using existing navigation method
102+ await queryEditor . queryTabs . selectTab ( QueryTabs . History ) ;
103+
104+ // Select query from history to load it into editor
105+ await queryEditor . historyQueries . selectQuery ( testQuery ) ;
106+
107+ // Handle unsaved changes modal by clicking "Don't save"
108+ await unsavedChangesModal . clickDontSave ( ) ;
109+
110+ // Run the query using the editor
111+ await queryEditor . clickRunButton ( ) ;
112+
113+ // Verify query was executed by checking results
114+ await queryEditor . resultTable . isVisible ( ) ;
115+ const value = await queryEditor . resultTable . getCellValue ( 1 , 2 ) ;
116+ expect ( value ) . toBe ( '42' ) ;
89117 } ) ;
90118} ) ;
0 commit comments