Skip to content

Commit eb8841d

Browse files
committed
test(e2e): added playwright tests for the "create index" flow
re #RI-7275
1 parent acc127c commit eb8841d

File tree

2 files changed

+213
-1
lines changed

2 files changed

+213
-1
lines changed
Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,184 @@
11
/* eslint-disable @typescript-eslint/lines-between-class-members */
2-
import { Locator, Page } from '@playwright/test'
2+
import { expect, Locator, Page } from '@playwright/test'
33

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'
414
import { BasePage } from '../../base-page'
15+
import { Toast } from '../../components/common/toast'
516

617
export class CreateIndexPage extends BasePage {
18+
private toast: Toast
19+
720
// CONTAINERS
821
public readonly vectorSearchPage: Locator
922
public readonly createIndexPage: Locator
1023
public readonly wizardTitle: Locator
1124

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+
1239
constructor(page: Page) {
1340
super(page)
1441
this.page = page
42+
this.toast = new Toast(page)
1543

1644
// CONTAINERS
1745
this.vectorSearchPage = page.getByTestId('vector-search-page')
1846
this.createIndexPage = page.getByTestId(
1947
'vector-search--create-index-page',
2048
)
2149
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+
})
2273
}
2374

2475
async verifyCreateIndexPageLoaded(): Promise<void> {
2576
await this.waitForLocatorVisible(this.createIndexPage)
2677
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+
}
27183
}
28184
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
SampleDataContent,
3+
SampleDataType,
4+
SearchIndexType,
5+
} from 'uiSrc/pages/vector-search/create-index/types'
6+
import { VectorSearchPage } from '../../pageObjects/pages/vector-search/vector-search-page'
7+
import { test } from '../../fixtures/test'
8+
import {
9+
addStandaloneInstanceAndNavigateToIt,
10+
navigateToStandaloneInstance,
11+
} from '../../helpers/utils'
12+
import { CreateIndexPage } from '../../pageObjects/pages/vector-search/create-index-page'
13+
14+
test.describe('Vector Search - Create Index', () => {
15+
let searchPage: VectorSearchPage
16+
let createIndexPage: CreateIndexPage
17+
let cleanupInstance: () => Promise<void>
18+
19+
test.beforeEach(async ({ page, api: { databaseService } }) => {
20+
searchPage = new VectorSearchPage(page)
21+
createIndexPage = new CreateIndexPage(page)
22+
cleanupInstance = await addStandaloneInstanceAndNavigateToIt(
23+
page,
24+
databaseService,
25+
)
26+
27+
await navigateToStandaloneInstance(page)
28+
await searchPage.navigateToVectorSearchPage()
29+
await searchPage.navigateToCreateIndexPage()
30+
})
31+
32+
test.afterEach(async () => {
33+
await cleanupInstance()
34+
})
35+
36+
test('should create a vector search index', async () => {
37+
// Step 1
38+
await createIndexPage.step1SelectIndexType(
39+
SearchIndexType.REDIS_QUERY_ENGINE,
40+
)
41+
await createIndexPage.step1SelectSampleDataset(
42+
SampleDataType.PRESET_DATA,
43+
)
44+
await createIndexPage.step1SelectDataContent(
45+
SampleDataContent.E_COMMERCE_DISCOVERY,
46+
)
47+
await createIndexPage.step1ClickNextButton()
48+
49+
// Step 2
50+
await createIndexPage.step2ClickCommandPreviewButton()
51+
await createIndexPage.step2ClickCloseCommandPreviewButton()
52+
await createIndexPage.step2ClickCreateIndexButton()
53+
54+
await createIndexPage.verifySuccessToast('Index has been created')
55+
})
56+
})

0 commit comments

Comments
 (0)