Skip to content

Commit 233cf46

Browse files
committed
test: verify edit operation for key name and ttl in browsers module
* added e2e test to verify whether the edit key name functionality is working fine in the browser module * also verify the ttl field and jow it can be updated or cleared re #RI-6570
1 parent 1d8e24e commit 233cf46

File tree

2 files changed

+249
-0
lines changed

2 files changed

+249
-0
lines changed

tests/playwright/pageObjects/browser-page.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,4 +1632,65 @@ export class BrowserPage extends BasePage {
16321632
// Click outside the confirmation popover to cancel deletion
16331633
await this.keyDetailsHeader.click()
16341634
}
1635+
1636+
async editKeyTTLValue(newTTL: number): Promise<void> {
1637+
await this.editKeyTTLButton.click()
1638+
await this.editKeyTTLInput.clear()
1639+
await this.editKeyTTLInput.fill(newTTL.toString())
1640+
await this.applyButton.click()
1641+
}
1642+
1643+
async removeKeyTTL(): Promise<void> {
1644+
await this.editKeyTTLButton.click()
1645+
await this.editKeyTTLInput.clear()
1646+
await this.editKeyTTLInput.fill('') // Explicitly set to empty string
1647+
// Don't fill anything - empty field means persistent (-1)
1648+
await this.applyButton.click()
1649+
1650+
// Wait for the TTL to become persistent using the existing helper
1651+
await expect
1652+
.poll(async () => {
1653+
try {
1654+
await this.verifyTTLIsPersistent()
1655+
return true
1656+
} catch {
1657+
return false
1658+
}
1659+
})
1660+
.toBe(true)
1661+
}
1662+
1663+
async waitForTTLToUpdate(expectedMinValue: number): Promise<void> {
1664+
await expect
1665+
.poll(async () => {
1666+
const currentTTL = await this.keyDetailsTTL.textContent()
1667+
const ttlMatch = currentTTL?.match(/TTL:\s*(\d+)/)
1668+
return ttlMatch ? parseInt(ttlMatch[1], 10) : 0
1669+
})
1670+
.toBeGreaterThan(expectedMinValue)
1671+
}
1672+
1673+
async verifyTTLIsWithinRange(
1674+
expectedTTL: number,
1675+
marginSeconds = 60,
1676+
): Promise<void> {
1677+
const displayedTTL = await this.keyDetailsTTL.textContent()
1678+
const ttlMatch = displayedTTL?.match(/TTL:\s*(\d+)/)
1679+
expect(ttlMatch).toBeTruthy()
1680+
1681+
const actualTTL = parseInt(ttlMatch![1], 10)
1682+
expect(actualTTL).toBeGreaterThan(expectedTTL - marginSeconds)
1683+
expect(actualTTL).toBeLessThanOrEqual(expectedTTL)
1684+
}
1685+
1686+
async verifyTTLIsPersistent(): Promise<void> {
1687+
const displayedTTL = await this.keyDetailsTTL.textContent()
1688+
expect(displayedTTL).toContain('No limit')
1689+
}
1690+
1691+
async verifyTTLIsNotPersistent(): Promise<void> {
1692+
const displayedTTL = await this.keyDetailsTTL.textContent()
1693+
expect(displayedTTL).toContain('TTL:')
1694+
expect(displayedTTL).not.toContain('No limit')
1695+
}
16351696
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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', () => {
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.describe('Key Name Editing', () => {
42+
test('should edit string key name successfully', async ({
43+
api: { keyService },
44+
}) => {
45+
// Arrange: Create a string key
46+
const keyValue = faker.lorem.words(3)
47+
const newKeyName = `${keyName}_renamed`
48+
49+
await keyService.addStringKeyApi(
50+
{ keyName, value: keyValue },
51+
ossStandaloneConfig,
52+
)
53+
54+
// Open key details
55+
await browserPage.searchByKeyName(keyName)
56+
await browserPage.openKeyDetailsByKeyName(keyName)
57+
58+
// Edit key name
59+
await browserPage.editKeyNameButton.click()
60+
await browserPage.keyNameInput.clear()
61+
await browserPage.keyNameInput.fill(newKeyName)
62+
await browserPage.applyButton.click()
63+
64+
// Verify key name was updated in the details header
65+
await expect
66+
.poll(async () => {
67+
const keyNameText =
68+
await browserPage.keyNameFormDetails.textContent()
69+
return keyNameText
70+
})
71+
.toContain(newKeyName)
72+
73+
// Wait for the key list to update and verify the new key exists
74+
await expect
75+
.poll(async () => {
76+
await browserPage.searchByKeyName(newKeyName)
77+
return browserPage.isKeyIsDisplayedInTheList(newKeyName)
78+
})
79+
.toBe(true)
80+
81+
// Verify the old key name doesn't exist in list
82+
await expect
83+
.poll(async () => {
84+
await browserPage.searchByKeyName(keyName)
85+
return browserPage.isKeyIsDisplayedInTheList(keyName)
86+
})
87+
.toBe(false)
88+
89+
// Update keyName for cleanup
90+
keyName = newKeyName
91+
})
92+
93+
test('should cancel key name edit operation', async ({
94+
api: { keyService },
95+
}) => {
96+
// Arrange: Create a string key
97+
const keyValue = faker.lorem.words(3)
98+
const originalKeyName = keyName
99+
const attemptedNewName = `${keyName}_attempted_rename`
100+
101+
await keyService.addStringKeyApi(
102+
{ keyName, value: keyValue },
103+
ossStandaloneConfig,
104+
)
105+
106+
// Open key details
107+
await browserPage.searchByKeyName(keyName)
108+
await browserPage.openKeyDetailsByKeyName(keyName)
109+
110+
// Verify original key name is displayed
111+
const displayedOriginalName =
112+
await browserPage.keyNameFormDetails.textContent()
113+
expect(displayedOriginalName).toContain(originalKeyName)
114+
115+
// Start editing but cancel
116+
await browserPage.editKeyNameButton.click()
117+
await browserPage.keyNameInput.clear()
118+
await browserPage.keyNameInput.fill(attemptedNewName)
119+
120+
// Cancel the edit by clicking outside the edit area
121+
await browserPage.keyDetailsHeader.click()
122+
123+
// Verify the original key name is still displayed (edit was cancelled)
124+
const displayedNameAfterCancel =
125+
await browserPage.keyNameFormDetails.textContent()
126+
expect(displayedNameAfterCancel).toContain(originalKeyName)
127+
expect(displayedNameAfterCancel).not.toContain(attemptedNewName)
128+
129+
// Verify the original key still exists in the list
130+
await browserPage.searchByKeyName(originalKeyName)
131+
const originalKeyExists =
132+
await browserPage.isKeyIsDisplayedInTheList(originalKeyName)
133+
expect(originalKeyExists).toBe(true)
134+
135+
// Verify the attempted new name doesn't exist
136+
await browserPage.searchByKeyName(attemptedNewName)
137+
const attemptedKeyExists =
138+
await browserPage.isKeyIsDisplayedInTheList(attemptedNewName)
139+
expect(attemptedKeyExists).toBe(false)
140+
})
141+
})
142+
143+
test.describe('TTL Editing', () => {
144+
test('should edit string key TTL successfully', async ({
145+
api: { keyService },
146+
}) => {
147+
// Arrange: Create a string key with TTL
148+
const keyValue = faker.lorem.words(3)
149+
const initialTTL = 3600 // 1 hour
150+
const newTTL = 7200 // 2 hours
151+
152+
await keyService.addStringKeyApi(
153+
{ keyName, value: keyValue, expire: initialTTL },
154+
ossStandaloneConfig,
155+
)
156+
157+
// Open key details and verify initial TTL
158+
await browserPage.openKeyDetailsAndVerify(keyName)
159+
await browserPage.verifyTTLIsNotPersistent()
160+
161+
// Edit the TTL and verify update
162+
await browserPage.editKeyTTLValue(newTTL)
163+
await browserPage.waitForTTLToUpdate(initialTTL)
164+
await browserPage.verifyTTLIsWithinRange(newTTL)
165+
})
166+
167+
test('should remove TTL from string key (set to persistent)', async ({
168+
api: { keyService },
169+
}) => {
170+
// Arrange: Create a string key with TTL
171+
const keyValue = faker.lorem.words(3)
172+
const initialTTL = 3600 // 1 hour
173+
174+
await keyService.addStringKeyApi(
175+
{ keyName, value: keyValue, expire: initialTTL },
176+
ossStandaloneConfig,
177+
)
178+
179+
// Open key details and verify initial TTL
180+
await browserPage.openKeyDetailsAndVerify(keyName)
181+
await browserPage.verifyTTLIsNotPersistent()
182+
183+
// Remove TTL and verify it becomes persistent
184+
await browserPage.removeKeyTTL()
185+
await browserPage.verifyTTLIsPersistent()
186+
})
187+
})
188+
})

0 commit comments

Comments
 (0)