Skip to content

Commit 32fa4ce

Browse files
add hast field ttl test
1 parent 9533420 commit 32fa4ce

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

tests/e2e/pageObjects/browser-page.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export class BrowserPage extends InstancePage {
9494
saveButton = Selector('[data-testid=save-btn]');
9595
bulkActionsButton = Selector('[data-testid=btn-bulk-actions]');
9696
editHashButton = Selector('[data-testid^=hash_edit-btn-]');
97+
editHashFieldTtlButton = Selector('[data-testid^=hash-ttl_edit-btn-]', { timeout: 500 });
9798
editZsetButton = Selector('[data-testid^=zset_edit-btn-]');
9899
editListButton = Selector('[data-testid^=list_edit-btn-]');
99100
cancelStreamGroupBtn = Selector('[data-testid=cancel-stream-groups-btn]');
@@ -161,6 +162,7 @@ export class BrowserPage extends InstancePage {
161162
hashFieldValueInput = Selector('[data-testid=field-value]');
162163
hashFieldNameInput = Selector('[data-testid=field-name]');
163164
hashFieldValueEditor = Selector('[data-testid^=hash_value-editor]');
165+
hashTtlFieldInput = Selector('[data-testid=hash-ttl]');
164166
listKeyElementInput = Selector('[data-testid=element]');
165167
listKeyElementEditorInput = Selector('[data-testid^=list_value-editor-]');
166168
stringKeyValueInput = Selector('[data-testid=string-value]');
@@ -265,6 +267,10 @@ export class BrowserPage extends InstancePage {
265267
noReadySearchDialogTitle = Selector('[data-testid=welcome-page-title]');
266268
closeDialogButton = Selector('[class*=euiModal__closeIcon]');
267269

270+
//Get Hash key field ttl value
271+
//for Redis databases 7.4 and higher
272+
getHashTtlFieldInput = (fieldName: string): Selector => (Selector(`[data-testid=hash-ttl_content-value-${fieldName}]`));
273+
268274
/**
269275
* Common part for Add any new key
270276
* @param keyName The name of the key
@@ -399,8 +405,9 @@ export class BrowserPage extends InstancePage {
399405
* @param TTL The Time to live value of the key
400406
* @param field The field name of the key
401407
* @param value The value of the key
408+
* @param ttl The ttl of the field for Redis databases 7.4 and higher
402409
*/
403-
async addHashKey(keyName: string, TTL = ' ', field = ' ', value = ' '): Promise<void> {
410+
async addHashKey(keyName: string, TTL = ' ', field = ' ', value = ' ', ttl = ''): Promise<void> {
404411
if (await this.Toast.toastCloseButton.exists) {
405412
await t.click(this.Toast.toastCloseButton);
406413
}
@@ -415,6 +422,9 @@ export class BrowserPage extends InstancePage {
415422
await t.typeText(this.keyTTLInput, TTL, { replace: true, paste: true });
416423
await t.typeText(this.hashFieldNameInput, field, { replace: true, paste: true });
417424
await t.typeText(this.hashFieldValueInput, value, { replace: true, paste: true });
425+
if(ttl !== ''){
426+
await t.typeText(this.hashTtlFieldInput, ttl, { replace: true, paste: true });
427+
}
418428
await t.click(this.addKeyButton);
419429
}
420430

@@ -634,14 +644,18 @@ export class BrowserPage extends InstancePage {
634644
* Add field to hash key
635645
* @param keyFieldValue The value of the hash field
636646
* @param keyValue The hash value
647+
* @param tll The hash field ttl value for Redis databases 7.4 and higher
637648
*/
638-
async addFieldToHash(keyFieldValue: string, keyValue: string): Promise<void> {
649+
async addFieldToHash(keyFieldValue: string, keyValue: string, ttl = ''): Promise<void> {
639650
if (await this.Toast.toastCloseButton.exists) {
640651
await t.click(this.Toast.toastCloseButton);
641652
}
642653
await t.click(this.addKeyValueItemsButton);
643654
await t.typeText(this.hashFieldInput, keyFieldValue, { replace: true, paste: true });
644655
await t.typeText(this.hashValueInput, keyValue, { replace: true, paste: true });
656+
if(ttl !== ' '){
657+
await t.typeText(this.hashTtlFieldInput, ttl, { replace: true, paste: true });
658+
}
645659
await t.click(this.saveHashFieldButton);
646660
}
647661

@@ -657,6 +671,19 @@ export class BrowserPage extends InstancePage {
657671
.click(this.applyButton);
658672
}
659673

674+
/**
675+
* Edit Hash field ttl value
676+
* @param fieldName The field name
677+
* @param tll The hash field ttl value for Redis databases 7.4 and higher
678+
*/
679+
async editHashFieldTtlValue(fieldName: string, ttl: string): Promise<void> {
680+
await t
681+
.hover(this.getHashTtlFieldInput(fieldName))
682+
.click(this.editHashFieldTtlButton)
683+
.typeText(this.inlineItemEditor, ttl, { replace: true, paste: true })
684+
.click(this.applyButton);
685+
}
686+
660687
//Get Hash key value from details
661688
async getHashKeyValue(): Promise<string> {
662689
return this.hashFieldValue.textContent;

tests/e2e/tests/web/smoke/browser/verify-key-details.e2e.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,48 @@ test('Verify that user can see JSON Key details', async t => {
119119
await t.expect(keyTTLValue).match(expectedTTL, 'The JSON Key TTL is incorrect');
120120
await t.expect(keyBadge).contains('JSON', 'The JSON Key Badge is incorrect');
121121
});
122+
//the test is skipped until redis databases 7.4 is not added to docker
123+
test
124+
.before(async() => {
125+
// await databaseHelper.acceptLicenseTermsAndAddDatabaseApi();
126+
})
127+
.after(async() => {
128+
// Clear and delete database
129+
// await apiKeyRequests.deleteKeyByNameApi(keyName, );
130+
// await databaseAPIRequests.deleteStandaloneDatabaseApi();
131+
})
132+
.skip('Verify that user can set ttl for Hash fields', async t => {
133+
keyName = Common.generateWord(10);
134+
const keyName2 = Common.generateWord(10);
135+
const field1 = 'Field1WithTtl';
136+
const field2 = 'Field2WithTtl';
137+
await browserPage.addHashKey(keyName, ' ', field1, 'value', keyTTL);
138+
139+
//verify that user can create key with ttl for the has field
140+
let ttlFieldValue = await browserPage.getHashTtlFieldInput(field1).textContent;
141+
await t.expect(ttlFieldValue).match(expectedTTL, 'the field ttl is not set');
142+
143+
// verify that ttl can have empty value
144+
await browserPage.editHashFieldTtlValue(field1, ' ');
145+
ttlFieldValue = await browserPage.getHashTtlFieldInput(field1).textContent;
146+
await t.expect(ttlFieldValue).eql('No Limit', 'the field ttl can not be removed');
147+
148+
//verify that ttl field value can be set
149+
await browserPage.addFieldToHash(field2, 'value', keyTTL);
150+
ttlFieldValue = await browserPage.getHashTtlFieldInput(field2).textContent;
151+
await t.expect(ttlFieldValue).match(expectedTTL, 'the field ttl is not set');
152+
153+
//verify that field is removed after ttl field is expired
154+
await browserPage.editHashFieldTtlValue(field1, '1');
155+
await t.wait(1000);
156+
await t.click(browserPage.refreshKeyButton);
157+
const result = browserPage.hashFieldsList.count;
158+
await t.expect(result).eql(1, 'the field was not removed');
159+
160+
//verify that the key is removed if key has 1 field and ttl field is expired
161+
await browserPage.addHashKey(keyName2, ' ', field1);
162+
await browserPage.editHashFieldTtlValue(field1, '1');
163+
await t.click(browserPage.refreshKeysButton);
164+
165+
await t.expect(browserPage.getKeySelectorByName(keyName2).exists).notOk('key is not removed when the field ttl is expired');
166+
});

0 commit comments

Comments
 (0)