Skip to content

Commit a32b350

Browse files
authored
RI-6570 Verify edit hash keys operations for in the browsers module (#4734)
* added e2e test to verify whether the edit key value functionality is working fine for the hash type in the browser module re #RI-6570
1 parent 4800cec commit a32b350

File tree

2 files changed

+285
-1
lines changed

2 files changed

+285
-1
lines changed

tests/playwright/pageObjects/browser-page.ts

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,8 +2176,95 @@ export class BrowserPage extends BasePage {
21762176
await this.page
21772177
.locator(`[data-testid="set-remove-btn-${member}-icon"]`)
21782178
.click()
2179+
await this.page.locator(`[data-testid^="set-remove-btn-${member}"]`)
2180+
}
2181+
2182+
async waitForHashDetailsToBeVisible(): Promise<void> {
2183+
await expect(this.page.getByTestId('hash-details')).toBeVisible()
2184+
}
2185+
2186+
async verifyHashFieldValueContains(
2187+
fieldName: string,
2188+
expectedValue: string,
2189+
): Promise<void> {
2190+
const fieldValueElement = this.page.locator(
2191+
`[data-testid="hash_content-value-${fieldName}"]`,
2192+
)
2193+
await expect(fieldValueElement).toContainText(expectedValue)
2194+
}
2195+
2196+
async verifyHashFieldValueNotContains(
2197+
fieldName: string,
2198+
unwantedValue: string,
2199+
): Promise<void> {
2200+
const fieldValueElement = this.page.locator(
2201+
`[data-testid="hash_content-value-${fieldName}"]`,
2202+
)
2203+
await expect(fieldValueElement).not.toContainText(unwantedValue)
2204+
}
2205+
2206+
async waitForHashFieldToBeVisible(fieldName: string): Promise<void> {
2207+
await expect(
2208+
this.page.locator(`[data-testid="hash-field-${fieldName}"]`),
2209+
).toBeVisible()
2210+
await expect(
2211+
this.page.locator(
2212+
`[data-testid="hash_content-value-${fieldName}"]`,
2213+
),
2214+
).toBeVisible()
2215+
}
2216+
2217+
async getHashFieldValueElement(fieldName: string) {
2218+
return this.page.locator(
2219+
`[data-testid="hash_content-value-${fieldName}"]`,
2220+
)
2221+
}
2222+
2223+
async editHashFieldValue(
2224+
fieldName: string,
2225+
newValue: string,
2226+
): Promise<void> {
2227+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
2228+
await fieldValueElement.hover()
21792229
await this.page
2180-
.locator(`[data-testid^="set-remove-btn-${member}"]`)
2230+
.locator(`[data-testid^="hash_edit-btn-${fieldName}"]`)
2231+
.click()
2232+
2233+
const editorLocator = this.page.locator('textarea').first()
2234+
await expect(editorLocator).toBeVisible()
2235+
await editorLocator.clear()
2236+
await editorLocator.fill(newValue)
2237+
await this.applyButton.click()
2238+
}
2239+
2240+
async cancelHashFieldEdit(
2241+
fieldName: string,
2242+
newValue: string,
2243+
): Promise<void> {
2244+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
2245+
await fieldValueElement.hover()
2246+
await this.page
2247+
.locator(`[data-testid^="hash_edit-btn-${fieldName}"]`)
2248+
.click()
2249+
2250+
const editorLocator = this.page.locator('textarea').first()
2251+
await expect(editorLocator).toBeVisible()
2252+
await editorLocator.clear()
2253+
await editorLocator.fill(newValue)
2254+
2255+
// Cancel using Escape key
2256+
await this.page.keyboard.press('Escape')
2257+
await expect(editorLocator).not.toBeVisible()
2258+
}
2259+
2260+
async removeHashField(fieldName: string): Promise<void> {
2261+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
2262+
await fieldValueElement.hover()
2263+
await this.page
2264+
.locator(`[data-testid="remove-hash-button-${fieldName}-icon"]`)
2265+
.click()
2266+
await this.page
2267+
.locator(`[data-testid^="remove-hash-button-${fieldName}"]`)
21812268
.getByText('Remove')
21822269
.click()
21832270
}
@@ -2341,4 +2428,18 @@ export class BrowserPage extends BasePage {
23412428
}
23422429
}
23432430
}
2431+
2432+
async verifyHashFieldValue(
2433+
fieldName: string,
2434+
expectedValue: string,
2435+
): Promise<void> {
2436+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
2437+
await expect(fieldValueElement).toContainText(expectedValue)
2438+
}
2439+
2440+
async verifyHashFieldNotVisible(fieldName: string): Promise<void> {
2441+
await expect(
2442+
this.page.locator(`[data-testid="hash-field-${fieldName}"]`),
2443+
).not.toBeVisible()
2444+
}
23442445
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
import { faker } from '@faker-js/faker'
2+
3+
import { BrowserPage } from '../../../pageObjects/browser-page'
4+
import { test, expect } from '../../../fixtures/test'
5+
import { ossStandaloneConfig } from '../../../helpers/conf'
6+
import {
7+
addStandaloneInstanceAndNavigateToIt,
8+
navigateToStandaloneInstance,
9+
} from '../../../helpers/utils'
10+
11+
test.describe('Browser - Edit Key Operations - Hash Key Editing', () => {
12+
let browserPage: BrowserPage
13+
let keyName: string
14+
let cleanupInstance: () => Promise<void>
15+
16+
test.beforeEach(async ({ page, api: { databaseService } }) => {
17+
browserPage = new BrowserPage(page)
18+
keyName = faker.string.alphanumeric(10)
19+
cleanupInstance = await addStandaloneInstanceAndNavigateToIt(
20+
page,
21+
databaseService,
22+
)
23+
24+
await navigateToStandaloneInstance(page)
25+
})
26+
27+
test.afterEach(async ({ api: { keyService } }) => {
28+
// Clean up: delete the key if it exists
29+
try {
30+
await keyService.deleteKeyByNameApi(
31+
keyName,
32+
ossStandaloneConfig.databaseName,
33+
)
34+
} catch (error) {
35+
// Key might already be deleted in test, ignore error
36+
}
37+
38+
await cleanupInstance()
39+
})
40+
41+
test('should edit hash field value successfully', async ({
42+
api: { keyService },
43+
}) => {
44+
// Arrange: Create a hash key with a field
45+
const fieldName = faker.string.alphanumeric(8)
46+
const originalValue = faker.lorem.words(3)
47+
const newValue = faker.lorem.words(4)
48+
49+
await keyService.addHashKeyApi(
50+
{
51+
keyName,
52+
fields: [{ field: fieldName, value: originalValue }],
53+
},
54+
ossStandaloneConfig,
55+
)
56+
57+
// Open key details and wait for hash to load
58+
await browserPage.searchByKeyName(keyName)
59+
await browserPage.openKeyDetailsByKeyName(keyName)
60+
61+
// Wait for field to be visible and verify original value
62+
await browserPage.waitForHashFieldToBeVisible(fieldName)
63+
await browserPage.verifyHashFieldValue(fieldName, originalValue)
64+
65+
// Edit the hash field value
66+
await browserPage.editHashFieldValue(fieldName, newValue)
67+
68+
// Verify the value was updated
69+
await browserPage.verifyHashFieldValue(fieldName, newValue)
70+
})
71+
72+
test('should cancel hash field value edit operation', async ({
73+
api: { keyService },
74+
}) => {
75+
// Arrange: Create a hash key with a field
76+
const fieldName = faker.string.alphanumeric(8)
77+
const originalValue = faker.lorem.words(3)
78+
const attemptedNewValue = faker.lorem.words(4)
79+
80+
await keyService.addHashKeyApi(
81+
{
82+
keyName,
83+
fields: [{ field: fieldName, value: originalValue }],
84+
},
85+
ossStandaloneConfig,
86+
)
87+
88+
// Open key details and wait for hash to load
89+
await browserPage.searchByKeyName(keyName)
90+
await browserPage.openKeyDetailsByKeyName(keyName)
91+
await browserPage.waitForHashDetailsToBeVisible()
92+
await browserPage.verifyHashFieldValue(fieldName, originalValue)
93+
94+
// Start editing but cancel
95+
await browserPage.cancelHashFieldEdit(fieldName, attemptedNewValue)
96+
97+
// Verify the original value is still present and attempted value is not
98+
await browserPage.verifyHashFieldValueContains(fieldName, originalValue)
99+
await browserPage.verifyHashFieldValueNotContains(
100+
fieldName,
101+
attemptedNewValue,
102+
)
103+
})
104+
105+
test('should add new field to hash key successfully', async ({
106+
api: { keyService },
107+
}) => {
108+
// Arrange: Create a hash key with one field
109+
const existingFieldName = faker.string.alphanumeric(8)
110+
const existingFieldValue = faker.lorem.words(2)
111+
const newFieldName = faker.string.alphanumeric(8)
112+
const newFieldValue = faker.lorem.words(3)
113+
114+
await keyService.addHashKeyApi(
115+
{
116+
keyName,
117+
fields: [
118+
{ field: existingFieldName, value: existingFieldValue },
119+
],
120+
},
121+
ossStandaloneConfig,
122+
)
123+
124+
// Open key details and verify initial state
125+
await browserPage.searchByKeyName(keyName)
126+
await browserPage.openKeyDetailsByKeyName(keyName)
127+
await browserPage.waitForHashDetailsToBeVisible()
128+
await browserPage.waitForKeyLengthToUpdate('1')
129+
130+
// Add a new field
131+
await browserPage.addFieldToHash(newFieldName, newFieldValue)
132+
133+
// Verify new field appears and length updates
134+
await browserPage.waitForHashFieldToBeVisible(newFieldName)
135+
await browserPage.verifyHashFieldValue(newFieldName, newFieldValue)
136+
await browserPage.waitForKeyLengthToUpdate('2')
137+
138+
// Verify existing field still exists
139+
await browserPage.verifyHashFieldValue(
140+
existingFieldName,
141+
existingFieldValue,
142+
)
143+
})
144+
145+
test('should remove hash field successfully', async ({
146+
api: { keyService },
147+
}) => {
148+
// Arrange: Create a hash key with multiple fields
149+
const field1Name = faker.string.alphanumeric(8)
150+
const field1Value = faker.lorem.words(2)
151+
const field2Name = faker.string.alphanumeric(8)
152+
const field2Value = faker.lorem.words(2)
153+
154+
await keyService.addHashKeyApi(
155+
{
156+
keyName,
157+
fields: [
158+
{ field: field1Name, value: field1Value },
159+
{ field: field2Name, value: field2Value },
160+
],
161+
},
162+
ossStandaloneConfig,
163+
)
164+
165+
// Open key details and verify initial state
166+
await browserPage.searchByKeyName(keyName)
167+
await browserPage.openKeyDetailsByKeyName(keyName)
168+
await browserPage.waitForHashDetailsToBeVisible()
169+
await browserPage.waitForKeyLengthToUpdate('2')
170+
171+
// Remove the first field
172+
await browserPage.removeHashField(field1Name)
173+
174+
// Verify field was removed and length updated
175+
await browserPage.waitForKeyLengthToUpdate('1')
176+
await browserPage.verifyHashFieldNotVisible(field1Name)
177+
178+
// Verify other field still exists and key is still open
179+
await browserPage.verifyHashFieldValue(field2Name, field2Value)
180+
const keyStillExists = await browserPage.isKeyDetailsOpen(keyName)
181+
expect(keyStillExists).toBe(true)
182+
})
183+
})

0 commit comments

Comments
 (0)