|
| 1 | +import type {Locator, Page} from '@playwright/test'; |
| 2 | + |
| 3 | +export class MemoryViewer { |
| 4 | + readonly container: Locator; |
| 5 | + readonly progressContainer: Locator; |
| 6 | + readonly allocatorSegment: Locator; |
| 7 | + readonly otherSegment: Locator; |
| 8 | + readonly text: Locator; |
| 9 | + readonly popup: Locator; |
| 10 | + readonly definitionList: Locator; |
| 11 | + |
| 12 | + constructor(page: Page) { |
| 13 | + const paginatedTable = page.locator('.ydb-paginated-table__table'); |
| 14 | + this.container = paginatedTable.locator('tbody tr').nth(0).locator('.memory-viewer'); |
| 15 | + this.progressContainer = this.container.locator('.memory-viewer__progress-container'); |
| 16 | + this.allocatorSegment = this.progressContainer.locator( |
| 17 | + '.memory-viewer__segment_type_AllocatorCachesMemory', |
| 18 | + ); |
| 19 | + this.otherSegment = this.progressContainer.locator('.memory-viewer__segment_type_Other'); |
| 20 | + this.text = this.progressContainer.locator('.memory-viewer__text'); |
| 21 | + |
| 22 | + // Popup elements |
| 23 | + this.popup = page.locator('.g-popup.g-popup_open'); |
| 24 | + this.definitionList = this.popup.locator('.g-definition-list'); |
| 25 | + } |
| 26 | + |
| 27 | + async getStatus() { |
| 28 | + const classList = await this.container.getAttribute('class'); |
| 29 | + if (classList?.includes('memory-viewer_status_good')) { |
| 30 | + return 'good'; |
| 31 | + } |
| 32 | + return 'unknown'; |
| 33 | + } |
| 34 | + |
| 35 | + async getTheme() { |
| 36 | + const classList = await this.container.getAttribute('class'); |
| 37 | + if (classList?.includes('memory-viewer_theme_system')) { |
| 38 | + return 'system'; |
| 39 | + } |
| 40 | + return 'unknown'; |
| 41 | + } |
| 42 | + |
| 43 | + async getAllocatorSegmentWidth() { |
| 44 | + return this.allocatorSegment.evaluate((el) => el.style.width); |
| 45 | + } |
| 46 | + |
| 47 | + async getOtherSegmentWidth() { |
| 48 | + return this.otherSegment.evaluate((el) => el.style.width); |
| 49 | + } |
| 50 | + |
| 51 | + async getOtherSegmentOffset() { |
| 52 | + return this.otherSegment.evaluate((el) => el.style.left); |
| 53 | + } |
| 54 | + |
| 55 | + async getText() { |
| 56 | + return this.text.innerText(); |
| 57 | + } |
| 58 | + |
| 59 | + async getItemValue(name: string) { |
| 60 | + const item = this.getDefinitionItem(name); |
| 61 | + return item.locator('.g-definition-list__definition').innerText(); |
| 62 | + } |
| 63 | + |
| 64 | + async getProgressValue(name: string) { |
| 65 | + const item = this.getDefinitionItem(name); |
| 66 | + const progressViewer = item.locator('.progress-viewer'); |
| 67 | + const line = progressViewer.locator('.progress-viewer__line'); |
| 68 | + const text = progressViewer.locator('.progress-viewer__text'); |
| 69 | + |
| 70 | + return { |
| 71 | + width: await line.evaluate((el) => el.style.width), |
| 72 | + text: await text.innerText(), |
| 73 | + status: await this.getProgressStatus(progressViewer), |
| 74 | + }; |
| 75 | + } |
| 76 | + |
| 77 | + async getSharedCacheInfo() { |
| 78 | + return this.getProgressValue('Shared Cache'); |
| 79 | + } |
| 80 | + |
| 81 | + async getQueryExecutionInfo() { |
| 82 | + return this.getProgressValue('Query Execution'); |
| 83 | + } |
| 84 | + |
| 85 | + async getMemTableInfo() { |
| 86 | + return this.getProgressValue('MemTable'); |
| 87 | + } |
| 88 | + |
| 89 | + async getAllocatorCachesInfo() { |
| 90 | + return this.getItemValue('Allocator Caches'); |
| 91 | + } |
| 92 | + |
| 93 | + async getOtherInfo() { |
| 94 | + return this.getItemValue('Other'); |
| 95 | + } |
| 96 | + |
| 97 | + async getUsageInfo() { |
| 98 | + return this.getItemValue('Usage'); |
| 99 | + } |
| 100 | + |
| 101 | + async getSoftLimitInfo() { |
| 102 | + return this.getItemValue('Soft Limit'); |
| 103 | + } |
| 104 | + |
| 105 | + async getHardLimitInfo() { |
| 106 | + return this.getItemValue('Hard Limit'); |
| 107 | + } |
| 108 | + |
| 109 | + async hover() { |
| 110 | + await this.container.hover(); |
| 111 | + } |
| 112 | + |
| 113 | + // Private methods |
| 114 | + private getDefinitionItem(name: string) { |
| 115 | + return this.definitionList.locator('.g-definition-list__item').filter({hasText: name}); |
| 116 | + } |
| 117 | + |
| 118 | + private async getProgressStatus(progressViewer: Locator) { |
| 119 | + const classList = await progressViewer.getAttribute('class'); |
| 120 | + if (classList?.includes('progress-viewer_status_good')) { |
| 121 | + return 'good'; |
| 122 | + } |
| 123 | + return 'unknown'; |
| 124 | + } |
| 125 | +} |
0 commit comments