|
1 | 1 | /* eslint-disable @typescript-eslint/lines-between-class-members */
|
2 |
| -import { Locator, Page } from '@playwright/test' |
| 2 | +import { expect, Locator, Page } from '@playwright/test' |
3 | 3 |
|
| 4 | +import { |
| 5 | + SampleDataContent, |
| 6 | + SampleDataType, |
| 7 | + SearchIndexType, |
| 8 | +} from 'uiSrc/pages/vector-search/create-index/types' |
| 9 | +import { |
| 10 | + indexDataContent, |
| 11 | + indexType as indexTypesData, |
| 12 | + sampleDatasetOptions, |
| 13 | +} from 'uiSrc/pages/vector-search/create-index/steps/config' |
4 | 14 | import { BasePage } from '../../base-page'
|
| 15 | +import { Toast } from '../../components/common/toast' |
5 | 16 |
|
6 | 17 | export class CreateIndexPage extends BasePage {
|
| 18 | + private toast: Toast |
| 19 | + |
7 | 20 | // CONTAINERS
|
8 | 21 | public readonly vectorSearchPage: Locator
|
9 | 22 | public readonly createIndexPage: Locator
|
10 | 23 | public readonly wizardTitle: Locator
|
11 | 24 |
|
| 25 | + // STEP 1 CONTAINERS |
| 26 | + public readonly step1Container: Locator |
| 27 | + public readonly step1IndexTypeContainer: Locator |
| 28 | + public readonly step1SampleDatasetContainer: Locator |
| 29 | + public readonly step1DataContentContainer: Locator |
| 30 | + public readonly step1NextButton: Locator |
| 31 | + |
| 32 | + // STEP 2 CONTAINERS |
| 33 | + public readonly step2Container: Locator |
| 34 | + public readonly step2CommandPreviewDrawer: Locator |
| 35 | + public readonly step2OpenCommandPreviewButton: Locator |
| 36 | + public readonly step2CloseCommandPreviewButton: Locator |
| 37 | + public readonly step2CreateIndexButton: Locator |
| 38 | + |
12 | 39 | constructor(page: Page) {
|
13 | 40 | super(page)
|
14 | 41 | this.page = page
|
| 42 | + this.toast = new Toast(page) |
15 | 43 |
|
16 | 44 | // CONTAINERS
|
17 | 45 | this.vectorSearchPage = page.getByTestId('vector-search-page')
|
18 | 46 | this.createIndexPage = page.getByTestId(
|
19 | 47 | 'vector-search--create-index-page',
|
20 | 48 | )
|
21 | 49 | this.wizardTitle = page.getByText('New vector search')
|
| 50 | + |
| 51 | + // STEP 1 CONTAINERS |
| 52 | + this.step1Container = page.getByTestId('create-index-step1') |
| 53 | + this.step1IndexTypeContainer = page.getByTestId('step-data--index-type') |
| 54 | + this.step1SampleDatasetContainer = page.getByTestId( |
| 55 | + 'step-data--sample-dataset', |
| 56 | + ) |
| 57 | + this.step1DataContentContainer = page.getByTestId( |
| 58 | + 'step-data--data-content', |
| 59 | + ) |
| 60 | + this.step1NextButton = page.getByText('Proceed to index') |
| 61 | + |
| 62 | + // STEP 2 CONTAINERS |
| 63 | + this.step2Container = page.getByTestId('create-index-step2') |
| 64 | + this.step2OpenCommandPreviewButton = page.getByText('Command preview') |
| 65 | + this.step2CommandPreviewDrawer = page.getByTestId( |
| 66 | + 'preview-command-drawer', |
| 67 | + ) |
| 68 | + this.step2CloseCommandPreviewButton = |
| 69 | + this.step2CommandPreviewDrawer.getByText('Close') |
| 70 | + this.step2CreateIndexButton = page.getByRole('button', { |
| 71 | + name: 'Create index', |
| 72 | + }) |
22 | 73 | }
|
23 | 74 |
|
24 | 75 | async verifyCreateIndexPageLoaded(): Promise<void> {
|
25 | 76 | await this.waitForLocatorVisible(this.createIndexPage)
|
26 | 77 | await this.waitForLocatorVisible(this.wizardTitle)
|
| 78 | + await this.waitForLocatorVisible(this.step1Container) |
| 79 | + } |
| 80 | + |
| 81 | + async step1SelectIndexType(indexType: SearchIndexType): Promise<void> { |
| 82 | + await this.waitForLocatorVisible(this.step1IndexTypeContainer) |
| 83 | + |
| 84 | + const indexTypeData = indexTypesData.find( |
| 85 | + (type) => type.value === indexType, |
| 86 | + ) |
| 87 | + if (!indexTypeData) { |
| 88 | + throw new Error(`Index type ${indexType} not found`) |
| 89 | + } |
| 90 | + |
| 91 | + const indexTypeElement = this.step1IndexTypeContainer.getByText( |
| 92 | + indexTypeData.label!, |
| 93 | + ) |
| 94 | + |
| 95 | + await this.waitForLocatorVisible(indexTypeElement) |
| 96 | + await indexTypeElement.click() |
| 97 | + } |
| 98 | + |
| 99 | + async step1SelectSampleDataset( |
| 100 | + sampleDataset: SampleDataType, |
| 101 | + ): Promise<void> { |
| 102 | + await this.waitForLocatorVisible(this.step1SampleDatasetContainer) |
| 103 | + |
| 104 | + const sampleDatasetData = sampleDatasetOptions.find( |
| 105 | + (dataset) => dataset.value === sampleDataset, |
| 106 | + ) |
| 107 | + if (!sampleDatasetData) { |
| 108 | + throw new Error(`Sample dataset ${sampleDataset} not found`) |
| 109 | + } |
| 110 | + |
| 111 | + const sampleDatasetElement = this.step1SampleDatasetContainer.getByText( |
| 112 | + sampleDatasetData.label!, |
| 113 | + ) |
| 114 | + |
| 115 | + await this.waitForLocatorVisible(sampleDatasetElement) |
| 116 | + await sampleDatasetElement.click() |
| 117 | + } |
| 118 | + |
| 119 | + async step1SelectDataContent( |
| 120 | + dataContent: SampleDataContent, |
| 121 | + ): Promise<void> { |
| 122 | + await this.waitForLocatorVisible(this.step1DataContentContainer) |
| 123 | + |
| 124 | + const dataContentData = indexDataContent.find( |
| 125 | + (data) => data.value === dataContent, |
| 126 | + ) |
| 127 | + if (!dataContentData) { |
| 128 | + throw new Error(`Data content ${dataContent} not found`) |
| 129 | + } |
| 130 | + |
| 131 | + const dataContentElement = this.step1DataContentContainer.getByText( |
| 132 | + dataContentData.label!, |
| 133 | + ) |
| 134 | + |
| 135 | + await this.waitForLocatorVisible(dataContentElement) |
| 136 | + await dataContentElement.click() |
| 137 | + } |
| 138 | + |
| 139 | + async step1ClickNextButton(): Promise<void> { |
| 140 | + await this.waitForLocatorVisible(this.step1NextButton) |
| 141 | + await this.step1NextButton.click() |
| 142 | + |
| 143 | + await this.waitForLocatorVisible(this.step2Container) |
| 144 | + } |
| 145 | + |
| 146 | + async step2ClickCommandPreviewButton(): Promise<void> { |
| 147 | + await this.waitForLocatorVisible(this.step2OpenCommandPreviewButton) |
| 148 | + await this.step2OpenCommandPreviewButton.click() |
| 149 | + |
| 150 | + await this.waitForLocatorVisible(this.step2CommandPreviewDrawer) |
| 151 | + } |
| 152 | + |
| 153 | + async step2ClickCloseCommandPreviewButton(): Promise<void> { |
| 154 | + await this.waitForLocatorVisible(this.step2CloseCommandPreviewButton) |
| 155 | + await this.step2CloseCommandPreviewButton.click() |
| 156 | + |
| 157 | + await this.waitForLocatorVisible(this.step2Container) |
| 158 | + } |
| 159 | + |
| 160 | + async step2ClickCreateIndexButton(): Promise<void> { |
| 161 | + await this.waitForLocatorVisible(this.step2CreateIndexButton) |
| 162 | + await this.step2CreateIndexButton.click() |
| 163 | + |
| 164 | + // Verify we're back on the vector search page |
| 165 | + await this.waitForLocatorVisible(this.vectorSearchPage) |
| 166 | + |
| 167 | + // Check for success toast (optional - may not appear for this action) |
| 168 | + await this.verifySuccessToast('Index has been created') |
| 169 | + } |
| 170 | + |
| 171 | + async verifySuccessToast( |
| 172 | + expectedMessage: string, |
| 173 | + timeout = 2000, |
| 174 | + ): Promise<void> { |
| 175 | + try { |
| 176 | + await this.waitForLocatorVisible(this.toast.toastSuccess, timeout) |
| 177 | + await expect(this.toast.toastBody).toContainText(expectedMessage) |
| 178 | + await this.toast.closeToast() |
| 179 | + } catch { |
| 180 | + // No toast appeared - this is acceptable for some actions |
| 181 | + // Success is typically verified by other means (navigation, etc.) |
| 182 | + } |
27 | 183 | }
|
28 | 184 | }
|
0 commit comments