|
| 1 | +import { Locator, Page } from "playwright"; |
| 2 | +import BasePage from "../../infra/ui/basePage"; |
| 3 | +import { delay } from "../utils"; |
| 4 | + |
| 5 | +export default class CodeGraph extends BasePage { |
| 6 | + /* NavBar Locators*/ |
| 7 | + private get falkorDBLogo(): Locator { |
| 8 | + return this.page.locator("//*[img[@alt='FalkorDB']]") |
| 9 | + } |
| 10 | + |
| 11 | + private get navBaritem(): (navItem: string) => Locator { |
| 12 | + return (navItem: string) => this.page.locator(`//a[p[text() = '${navItem}']]`); |
| 13 | + } |
| 14 | + |
| 15 | + private get createNewProjectBtn(): Locator { |
| 16 | + return this.page.getByRole('button', { name: 'Create new project' }); |
| 17 | + } |
| 18 | + |
| 19 | + private get createNewProjectDialog(): Locator { |
| 20 | + return this.page.locator("//div[@role='dialog']") |
| 21 | + } |
| 22 | + |
| 23 | + /* CodeGraph Locators*/ |
| 24 | + private get comboBoxbtn(): Locator { |
| 25 | + return this.page.locator("//button[@role='combobox']") |
| 26 | + } |
| 27 | + |
| 28 | + private get selectGraphInComboBox(): (graph: string) => Locator { |
| 29 | + return (graph: string) => this.page.locator(`//div[@role='presentation']//div[@role='option'][${graph}]`); |
| 30 | + } |
| 31 | + |
| 32 | + private get lastElementInChat(): Locator { |
| 33 | + return this.page.locator("//main[@data-name='main-chat']/*[last()]/p"); |
| 34 | + } |
| 35 | + |
| 36 | + /* Chat Locators */ |
| 37 | + private get showPathBtn(): Locator { |
| 38 | + return this.page.locator("//button[contains(@class, 'Tip')]"); |
| 39 | + } |
| 40 | + |
| 41 | + private get askquestionInput(): Locator { |
| 42 | + return this.page.locator("//input[contains(@placeholder, 'Ask your question')]"); |
| 43 | + } |
| 44 | + |
| 45 | + private get askquestionBtn(): Locator { |
| 46 | + return this.page.locator("//input[contains(@placeholder, 'Ask your question')]/following::button[1]"); |
| 47 | + } |
| 48 | + |
| 49 | + private get lightbulbBtn(): Locator { |
| 50 | + return this.page.locator("//button[@data-name='lightbulb']"); |
| 51 | + } |
| 52 | + |
| 53 | + private get lastChatElementButtonCount(): Locator { |
| 54 | + return this.page.locator("//main[@data-name='main-chat']/*[last()]/button"); |
| 55 | + } |
| 56 | + |
| 57 | + private get chatContainer(): Locator { |
| 58 | + return this.page.locator("//main[@data-name='main-chat']"); |
| 59 | + } |
| 60 | + |
| 61 | + private get previousQuestionLoadingImage(): Locator { |
| 62 | + return this.page.locator("//main[@data-name='main-chat']/*[last()-2]//img[@alt='Waiting for response']") |
| 63 | + } |
| 64 | + |
| 65 | + private get selectInputForShowPath(): (inputNum: string) => Locator { |
| 66 | + return (inputNum: string) => this.page.locator(`(//main[@data-name='main-chat']//input)[${inputNum}]`); |
| 67 | + } |
| 68 | + |
| 69 | + private get locateNodeInLastChatPath(): (node: string) => Locator { |
| 70 | + return (node: string) => this.page.locator(`//main[@data-name='main-chat']/*[last()]//span[contains(text(), '${node}')]`); |
| 71 | + } |
| 72 | + |
| 73 | + private get selectFirstPathOption(): (inputNum: string) => Locator { |
| 74 | + return (inputNum: string) => this.page.locator(`(//main[@data-name='main-chat']//input)[1]/following::div[${inputNum}]//button[1]`); |
| 75 | + } |
| 76 | + |
| 77 | + private get notificationNoPathFound(): Locator { |
| 78 | + return this.page.locator("//div[@role='region']//ol//li"); |
| 79 | + } |
| 80 | + |
| 81 | + /* NavBar functionality */ |
| 82 | + async clickOnFalkorDbLogo(): Promise<Page> { |
| 83 | + await this.page.waitForLoadState('networkidle'); |
| 84 | + const [newPage] = await Promise.all([ |
| 85 | + this.page.waitForEvent('popup'), |
| 86 | + this.falkorDBLogo.click(), |
| 87 | + ]); |
| 88 | + return newPage |
| 89 | + } |
| 90 | + |
| 91 | + async getNavBarItem(navItem : string): Promise<Page> { |
| 92 | + await this.page.waitForLoadState('networkidle'); |
| 93 | + const [newPage] = await Promise.all([ |
| 94 | + this.page.waitForEvent('popup'), |
| 95 | + this.navBaritem(navItem).click(), |
| 96 | + ]); |
| 97 | + return newPage |
| 98 | + } |
| 99 | + |
| 100 | + async clickCreateNewProjectBtn(): Promise<void> { |
| 101 | + await this.createNewProjectBtn.click(); |
| 102 | + } |
| 103 | + |
| 104 | + async isCreateNewProjectDialog(): Promise<boolean> { |
| 105 | + return await this.createNewProjectDialog.isVisible(); |
| 106 | + } |
| 107 | + |
| 108 | + /* Chat functionality */ |
| 109 | + async clickOnshowPathBtn(): Promise<void> { |
| 110 | + await this.showPathBtn.click(); |
| 111 | + } |
| 112 | + |
| 113 | + async clickAskquestionBtn(): Promise<void> { |
| 114 | + await this.askquestionBtn.click(); |
| 115 | + } |
| 116 | + |
| 117 | + async sendMessage(message: string) { |
| 118 | + await this.askquestionInput.isEnabled(); |
| 119 | + await this.askquestionInput.fill(message); |
| 120 | + await this.askquestionBtn.click(); |
| 121 | + } |
| 122 | + |
| 123 | + async clickOnLightBulbBtn(): Promise<void> { |
| 124 | + await this.lightbulbBtn.click(); |
| 125 | + } |
| 126 | + |
| 127 | + async getTextInLastChatElement(): Promise<string | null>{ |
| 128 | + return await this.lastElementInChat.textContent(); |
| 129 | + } |
| 130 | + |
| 131 | + async getLastChatElementButtonCount(): Promise<number | null>{ |
| 132 | + return await this.lastChatElementButtonCount.count(); |
| 133 | + } |
| 134 | + |
| 135 | + async scrollToTop() { |
| 136 | + await this.chatContainer.evaluate((chat) => { |
| 137 | + chat.scrollTop = 0; |
| 138 | + }); |
| 139 | + } |
| 140 | + |
| 141 | + async getScrollMetrics() { |
| 142 | + const scrollTop = await this.chatContainer.evaluate((el) => el.scrollTop); |
| 143 | + const scrollHeight = await this.chatContainer.evaluate((el) => el.scrollHeight); |
| 144 | + const clientHeight = await this.chatContainer.evaluate((el) => el.clientHeight); |
| 145 | + return { scrollTop, scrollHeight, clientHeight }; |
| 146 | + } |
| 147 | + |
| 148 | + async isAtBottom(): Promise<boolean> { |
| 149 | + const { scrollTop, scrollHeight, clientHeight } = await this.getScrollMetrics(); |
| 150 | + return Math.abs(scrollTop + clientHeight - scrollHeight) < 1; |
| 151 | + } |
| 152 | + |
| 153 | + async getpreviousQuestionLoadingImage(): Promise<boolean> { |
| 154 | + return this.previousQuestionLoadingImage.isVisible(); |
| 155 | + } |
| 156 | + |
| 157 | + async insertInputForShowPath(inputNum: string, node: string): Promise<void> { |
| 158 | + await this.selectInputForShowPath(inputNum).fill(node); |
| 159 | + await this.selectFirstPathOption(inputNum).click(); |
| 160 | + } |
| 161 | + |
| 162 | + async isNodeVisibleInLastChatPath(node: string): Promise<boolean> { |
| 163 | + return await this.locateNodeInLastChatPath(node).isVisible(); |
| 164 | + } |
| 165 | + |
| 166 | + async isNotificationNoPathFound(): Promise<boolean> { |
| 167 | + return await this.notificationNoPathFound.isVisible(); |
| 168 | + } |
| 169 | + |
| 170 | + /* CodeGraph functionality */ |
| 171 | + async selectGraph(graph: string): Promise<void> { |
| 172 | + await this.comboBoxbtn.click(); |
| 173 | + await this.selectGraphInComboBox(graph).waitFor({ state : 'visible'}) |
| 174 | + await this.selectGraphInComboBox(graph).click(); |
| 175 | + } |
| 176 | +} |
0 commit comments