Skip to content

Commit 5acdbf8

Browse files
Merge pull request #3479 from RedisInsight/e2e/feature/RI-5767_update-key-details
add hast field ttl test
2 parents 9533420 + 9238e80 commit 5acdbf8

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

tests/e2e/pageObjects/browser-page.ts

Lines changed: 29 additions & 3 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,8 @@ 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
402-
*/
403-
async addHashKey(keyName: string, TTL = ' ', field = ' ', value = ' '): Promise<void> {
408+
* @param fieldTtl The ttl of the field for Redis databases 7.4 and higher*/
409+
async addHashKey(keyName: string, TTL = ' ', field = ' ', value = ' ', fieldTtl = ''): Promise<void> {
404410
if (await this.Toast.toastCloseButton.exists) {
405411
await t.click(this.Toast.toastCloseButton);
406412
}
@@ -415,6 +421,9 @@ export class BrowserPage extends InstancePage {
415421
await t.typeText(this.keyTTLInput, TTL, { replace: true, paste: true });
416422
await t.typeText(this.hashFieldNameInput, field, { replace: true, paste: true });
417423
await t.typeText(this.hashFieldValueInput, value, { replace: true, paste: true });
424+
if(fieldTtl !== ''){
425+
await t.typeText(this.hashTtlFieldInput, fieldTtl, { replace: true, paste: true });
426+
}
418427
await t.click(this.addKeyButton);
419428
}
420429

@@ -634,14 +643,18 @@ export class BrowserPage extends InstancePage {
634643
* Add field to hash key
635644
* @param keyFieldValue The value of the hash field
636645
* @param keyValue The hash value
646+
* @param fieldTtl The hash field ttl value for Redis databases 7.4 and higher
637647
*/
638-
async addFieldToHash(keyFieldValue: string, keyValue: string): Promise<void> {
648+
async addFieldToHash(keyFieldValue: string, keyValue: string, fieldTtl = ''): Promise<void> {
639649
if (await this.Toast.toastCloseButton.exists) {
640650
await t.click(this.Toast.toastCloseButton);
641651
}
642652
await t.click(this.addKeyValueItemsButton);
643653
await t.typeText(this.hashFieldInput, keyFieldValue, { replace: true, paste: true });
644654
await t.typeText(this.hashValueInput, keyValue, { replace: true, paste: true });
655+
if(fieldTtl !== ' '){
656+
await t.typeText(this.hashTtlFieldInput, fieldTtl, { replace: true, paste: true });
657+
}
645658
await t.click(this.saveHashFieldButton);
646659
}
647660

@@ -657,6 +670,19 @@ export class BrowserPage extends InstancePage {
657670
.click(this.applyButton);
658671
}
659672

673+
/**
674+
* Edit Hash field ttl value
675+
* @param fieldName The field name
676+
* @param fieldTtl The hash field ttl value for Redis databases 7.4 and higher
677+
*/
678+
async editHashFieldTtlValue(fieldName: string, fieldTtl: string): Promise<void> {
679+
await t
680+
.hover(this.getHashTtlFieldInput(fieldName))
681+
.click(this.editHashFieldTtlButton)
682+
.typeText(this.inlineItemEditor, fieldTtl, { replace: true, paste: true })
683+
.click(this.applyButton);
684+
}
685+
660686
//Get Hash key value from details
661687
async getHashKeyValue(): Promise<string> {
662688
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)