Skip to content

Commit 1ba16df

Browse files
committed
chore: add tests
1 parent 968ea62 commit 1ba16df

File tree

5 files changed

+156
-3
lines changed

5 files changed

+156
-3
lines changed

src/components/FixedHeightQuery/FixedHeightQuery.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.kv-fixed-height-query {
1+
.ydb-fixed-height-query {
22
position: relative;
33

44
overflow: hidden;

src/components/FixedHeightQuery/FixedHeightQuery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {YDBSyntaxHighlighter} from '../SyntaxHighlighter/YDBSyntaxHighlighter';
55

66
import './FixedHeightQuery.scss';
77

8-
const b = cn('kv-fixed-height-query');
8+
const b = cn('ydb-fixed-height-query');
99

1010
const FIXED_PADDING = 8;
1111
const LINE_HEIGHT = 20;

src/containers/Tenant/Diagnostics/TopQueries/TopQueriesData.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export const TopQueriesData = ({
9999
() => ({
100100
...TOP_QUERIES_TABLE_SETTINGS,
101101
dynamicInnerRef: reactListRef,
102-
// Using 'uniform' type - react-list automatically calculates size from first item
103102
}),
104103
[],
105104
);

tests/suites/tenant/diagnostics/Diagnostics.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ export class Table {
120120
});
121121
return true;
122122
}
123+
124+
async clickRow(row: number) {
125+
const rowElement = this.table.locator(`tr.data-table__row:nth-child(${row})`);
126+
await rowElement.click();
127+
}
128+
129+
async getRowPosition(row: number) {
130+
const rowElement = this.table.locator(`tr.data-table__row:nth-child(${row})`);
131+
return await rowElement.boundingBox();
132+
}
133+
134+
async isRowVisible(row: number) {
135+
const rowElement = this.table.locator(`tr.data-table__row:nth-child(${row})`);
136+
const boundingBox = await rowElement.boundingBox();
137+
if (!boundingBox) {
138+
return false;
139+
}
140+
141+
const viewportHeight = await rowElement.page().evaluate(() => window.innerHeight);
142+
return boundingBox.y >= 0 && boundingBox.y + boundingBox.height <= viewportHeight;
143+
}
123144
}
124145

125146
export enum QueriesSwitch {

tests/suites/tenant/diagnostics/tabs/queries.test.ts

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,137 @@ test.describe('Diagnostics Queries tab', async () => {
179179
// Verify the view was updated back
180180
expect(await diagnostics.getSelectedQueryPeriod()).toBe(QueryPeriod.PerHour);
181181
});
182+
183+
test('FixedHeightQuery maintains consistent height and proper scrolling behavior', async ({
184+
page,
185+
}) => {
186+
const pageQueryParams = {
187+
schema: tenantName,
188+
database: tenantName,
189+
tenantPage: 'diagnostics',
190+
diagnosticsTab: 'topQueries',
191+
};
192+
const tenantPage = new TenantPage(page);
193+
await tenantPage.goto(pageQueryParams);
194+
195+
const diagnostics = new Diagnostics(page);
196+
await expect(diagnostics.table.isVisible()).resolves.toBe(true);
197+
198+
// Verify we have enough rows to test scrolling
199+
const rowCount = await diagnostics.table.getRowCount();
200+
if (rowCount > 5) {
201+
// Test scrolling behavior: click on a row that might not be fully visible
202+
const targetRowIndex = Math.min(rowCount, 8); // Target a row further down
203+
204+
// Click on the target row to test scrolling
205+
await diagnostics.table.clickRow(targetRowIndex);
206+
207+
// Wait for any scrolling animation
208+
await page.waitForTimeout(500);
209+
210+
// Verify the row is now visible in the viewport
211+
const isVisible = await diagnostics.table.isRowVisible(targetRowIndex);
212+
expect(isVisible).toBe(true);
213+
}
214+
});
215+
216+
test('FixedHeightQuery components have consistent height across different query lengths', async ({
217+
page,
218+
}) => {
219+
const pageQueryParams = {
220+
schema: tenantName,
221+
database: tenantName,
222+
tenantPage: 'diagnostics',
223+
diagnosticsTab: 'topQueries',
224+
};
225+
const tenantPage = new TenantPage(page);
226+
await tenantPage.goto(pageQueryParams);
227+
228+
const diagnostics = new Diagnostics(page);
229+
await expect(diagnostics.table.isVisible()).resolves.toBe(true);
230+
231+
// Check that FixedHeightQuery components have the expected fixed height
232+
const fixedHeightElements = page.locator('.ydb-fixed-height-query');
233+
const elementCount = await fixedHeightElements.count();
234+
235+
if (elementCount > 1) {
236+
// Check that all FixedHeightQuery components have the same height
237+
const heights = [];
238+
for (let i = 0; i < Math.min(elementCount, 5); i++) {
239+
const element = fixedHeightElements.nth(i);
240+
const height = await element.evaluate((el) => {
241+
return window.getComputedStyle(el).height;
242+
});
243+
heights.push(height);
244+
}
245+
246+
// All heights should be the same (88px for 4 lines)
247+
const firstHeight = heights[0];
248+
expect(firstHeight).toBe('88px');
249+
250+
for (const height of heights) {
251+
expect(height).toBe(firstHeight);
252+
}
253+
}
254+
});
255+
256+
test.only('Scroll to row, get shareable link, navigate to URL and verify row is scrolled into view', async ({
257+
page,
258+
}) => {
259+
const pageQueryParams = {
260+
schema: tenantName,
261+
database: tenantName,
262+
tenantPage: 'diagnostics',
263+
diagnosticsTab: 'topQueries',
264+
};
265+
const tenantPage = new TenantPage(page);
266+
await tenantPage.goto(pageQueryParams);
267+
268+
const diagnostics = new Diagnostics(page);
269+
await expect(diagnostics.table.isVisible()).resolves.toBe(true);
270+
271+
// Get the number of rows and select a row that requires scrolling
272+
const rowCount = await diagnostics.table.getRowCount();
273+
if (rowCount > 5) {
274+
const targetRowIndex = Math.min(rowCount, 8); // Target a row further down
275+
276+
// Click on the target row to open the drawer
277+
await diagnostics.table.clickRow(targetRowIndex);
278+
279+
// Wait for drawer to open
280+
await page.waitForTimeout(500);
281+
282+
// Find and click the copy link button in the drawer
283+
const copyLinkButton = page.locator('.ydb-copy-link-button__icon').first();
284+
await expect(copyLinkButton).toBeVisible();
285+
await copyLinkButton.click();
286+
287+
// Get the copied URL from clipboard
288+
const clipboardText = await page.evaluate(() => navigator.clipboard.readText());
289+
expect(clipboardText).toBeTruthy();
290+
expect(clipboardText).toContain('/tenant');
291+
292+
// Navigate to the copied URL
293+
await page.goto(clipboardText);
294+
await page.waitForTimeout(1000);
295+
296+
// Verify the table is visible and the target row is scrolled into view
297+
await expect(diagnostics.table.isVisible()).resolves.toBe(true);
298+
299+
// Check that the target row is visible in the viewport
300+
const isRowVisible = await diagnostics.table.isRowVisible(targetRowIndex);
301+
expect(isRowVisible).toBe(true);
302+
303+
// Verify the row is highlighted/selected (if applicable)
304+
const rowElement = page.locator(`tr.data-table__row:nth-child(${targetRowIndex})`);
305+
const hasActiveClass = await rowElement.evaluate((el: HTMLElement) => {
306+
return (
307+
el.classList.contains('kv-top-queries__row_active') ||
308+
el.classList.contains('active') ||
309+
el.getAttribute('aria-selected') === 'true'
310+
);
311+
});
312+
expect(hasActiveClass).toBe(true);
313+
}
314+
});
182315
});

0 commit comments

Comments
 (0)