Skip to content

Commit dfca2d2

Browse files
committed
test: verify edit operation for hash key value in browsers module
* 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 76052ac commit dfca2d2

File tree

2 files changed

+300
-0
lines changed

2 files changed

+300
-0
lines changed

tests/playwright/pageObjects/browser-page.ts

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,4 +1600,121 @@ export class BrowserPage extends BasePage {
16001600
await this.verifyKeyTTL(expectedTTL)
16011601
await this.closeKeyDetailsAndVerify()
16021602
}
1603+
1604+
async waitForKeyLengthToUpdate(expectedLength: string): Promise<void> {
1605+
await expect
1606+
.poll(async () => {
1607+
const keyLength = await this.getKeyLength()
1608+
return keyLength
1609+
})
1610+
.toBe(expectedLength)
1611+
}
1612+
1613+
async waitForHashDetailsToBeVisible(): Promise<void> {
1614+
await expect(this.page.getByTestId('hash-details')).toBeVisible()
1615+
}
1616+
1617+
async verifyHashFieldValueContains(
1618+
fieldName: string,
1619+
expectedValue: string,
1620+
): Promise<void> {
1621+
await expect
1622+
.poll(async () => {
1623+
const pageContent = await this.page
1624+
.getByTestId('hash-details')
1625+
.textContent()
1626+
return pageContent?.includes(expectedValue) || false
1627+
})
1628+
.toBe(true)
1629+
}
1630+
1631+
async verifyHashFieldValueNotContains(
1632+
fieldName: string,
1633+
unwantedValue: string,
1634+
): Promise<void> {
1635+
const hashDetailsContent = await this.page
1636+
.getByTestId('hash-details')
1637+
.textContent()
1638+
expect(hashDetailsContent).not.toContain(unwantedValue)
1639+
}
1640+
1641+
async waitForHashFieldToBeVisible(fieldName: string): Promise<void> {
1642+
await expect(
1643+
this.page.locator(`[data-testid="hash-field-${fieldName}"]`),
1644+
).toBeVisible()
1645+
await expect(
1646+
this.page.locator(
1647+
`[data-testid="hash_content-value-${fieldName}"]`,
1648+
),
1649+
).toBeVisible()
1650+
}
1651+
1652+
async getHashFieldValueElement(fieldName: string) {
1653+
return this.page.locator(
1654+
`[data-testid="hash_content-value-${fieldName}"]`,
1655+
)
1656+
}
1657+
1658+
async editHashFieldValue(
1659+
fieldName: string,
1660+
newValue: string,
1661+
): Promise<void> {
1662+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
1663+
await fieldValueElement.hover()
1664+
await this.page
1665+
.locator(`[data-testid^="hash_edit-btn-${fieldName}"]`)
1666+
.click()
1667+
1668+
const editorLocator = this.page.locator('textarea').first()
1669+
await expect(editorLocator).toBeVisible()
1670+
await editorLocator.clear()
1671+
await editorLocator.fill(newValue)
1672+
await this.applyButton.click()
1673+
}
1674+
1675+
async cancelHashFieldEdit(
1676+
fieldName: string,
1677+
newValue: string,
1678+
): Promise<void> {
1679+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
1680+
await fieldValueElement.hover()
1681+
await this.page
1682+
.locator(`[data-testid^="hash_edit-btn-${fieldName}"]`)
1683+
.click()
1684+
1685+
const editorLocator = this.page.locator('textarea').first()
1686+
await expect(editorLocator).toBeVisible()
1687+
await editorLocator.clear()
1688+
await editorLocator.fill(newValue)
1689+
1690+
// Cancel using Escape key
1691+
await this.page.keyboard.press('Escape')
1692+
await expect(editorLocator).not.toBeVisible()
1693+
}
1694+
1695+
async removeHashField(fieldName: string): Promise<void> {
1696+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
1697+
await fieldValueElement.hover()
1698+
await this.page
1699+
.locator(`[data-testid="remove-hash-button-${fieldName}-icon"]`)
1700+
.click()
1701+
await this.page
1702+
.locator(`[data-testid^="remove-hash-button-${fieldName}"]`)
1703+
.getByText('Remove')
1704+
.click()
1705+
}
1706+
1707+
async verifyHashFieldValue(
1708+
fieldName: string,
1709+
expectedValue: string,
1710+
): Promise<void> {
1711+
const fieldValueElement = await this.getHashFieldValueElement(fieldName)
1712+
await expect(fieldValueElement).toContainText(expectedValue)
1713+
}
1714+
1715+
async verifyHashFieldNotVisible(fieldName: string): Promise<void> {
1716+
await expect(
1717+
this.page.locator(`[data-testid="hash-field-${fieldName}"]`),
1718+
).not.toBeVisible()
1719+
}
16031720
}
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)