Skip to content

Commit 657b3d4

Browse files
authored
Merge pull request #1044 from RedisInsight/e2e/msgpack-formatter
E2e/formatters
2 parents 72690a0 + 615cd27 commit 657b3d4

File tree

4 files changed

+191
-84
lines changed

4 files changed

+191
-84
lines changed

tests/e2e/helpers/keys.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ export const keyTypes = [
4646
* Adding keys of each type through the cli
4747
* @param keyData The key data
4848
* @param keyValue The key value
49+
* @param keyField The key field value
4950
*/
50-
export async function addKeysViaCli(keyData: KeyData, keyValue?: string): Promise<void> {
51+
export async function addKeysViaCli(keyData: KeyData, keyValue?: string, keyField?: string): Promise<void> {
5152
await t.click(cliPage.cliExpandButton);
5253
for (const { textType, keyName } of keyData) {
5354
if (textType in COMMANDS_TO_CREATE_KEY) {
54-
await t.typeText(cliPage.cliCommandInput, COMMANDS_TO_CREATE_KEY[textType](keyName, keyValue), { paste: true });
55+
textType === 'Hash' || textType === 'Stream'
56+
? await t.typeText(cliPage.cliCommandInput, COMMANDS_TO_CREATE_KEY[textType](keyName, keyValue, keyField), { paste: true })
57+
: await t.typeText(cliPage.cliCommandInput, COMMANDS_TO_CREATE_KEY[textType](keyName, keyValue), { paste: true });
5558
await t.pressKey('enter');
5659
}
5760
}

tests/e2e/pageObjects/browser-page.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export class BrowserPage {
163163
databaseNames = Selector('[data-testid^=db_name_]');
164164
hashFieldsList = Selector('[data-testid^=hash-field-] span');
165165
hashValuesList = Selector('[data-testid^=hash-field-value-] span');
166+
hashField = Selector('[data-testid^=hash-field-]').nth(0);
166167
hashFieldValue = Selector('[data-testid^=hash-field-value-]');
167168
setMembersList = Selector('[data-testid^=set-member-value-]');
168169
zsetMembersList = Selector('[data-testid^=zset-member-value-]');
@@ -468,7 +469,9 @@ export class BrowserPage {
468469
// Scan until finding element or all keys scanned
469470
while (true) {
470471
await t.click(this.scanMoreButton);
471-
if (await this.isKeyIsDisplayedInTheList(keyName) || scannedValueText === totalKeysValue) break;
472+
if (await this.isKeyIsDisplayedInTheList(keyName) || scannedValueText === totalKeysValue) {
473+
break;
474+
}
472475
}
473476
}
474477

@@ -554,6 +557,17 @@ export class BrowserPage {
554557
await t.click(this.saveHashFieldButton);
555558
}
556559

560+
/**
561+
* Edit Hash key value from details
562+
* @param value The value of the key
563+
*/
564+
async editHashKeyValue(value: string): Promise<void> {
565+
await t
566+
.click(this.editHashButton)
567+
.typeText(this.hashFieldValueEditor, value, {replace: true, paste: true})
568+
.click(this.applyButton);
569+
}
570+
557571
/**
558572
* Search by the value in the key details
559573
* @param value The value of the search parameter
@@ -959,7 +973,7 @@ export type AddKeyArguments = {
959973
fieldValueStartWith?: string,
960974
elementStartWith?: string,
961975
memberStartWith?: string
962-
}
976+
};
963977

964978
/**
965979
* Keys Data parameters
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { Selector } from 'testcafe';
2+
import { keyLength, rte } from '../../../helpers/constants';
3+
import { addKeysViaCli, deleteKeysViaCli, keyTypes } from '../../../helpers/keys';
4+
import { acceptLicenseTermsAndAddDatabaseApi } from '../../../helpers/database';
5+
import { BrowserPage } from '../../../pageObjects';
6+
import { commonUrl, ossStandaloneConfig } from '../../../helpers/conf';
7+
import { deleteStandaloneDatabaseApi } from '../../../helpers/api/api-database';
8+
import { Common } from '../../../helpers/common';
9+
10+
const browserPage = new BrowserPage();
11+
const common = new Common();
12+
13+
const keysData = keyTypes.map(object => ({ ...object })).filter((v, i) => i <= 6 && i !== 5);
14+
keysData.forEach(key => key.keyName = `${key.keyName}` + '-' + `${common.generateWord(keyLength)}`);
15+
const formatters = [{
16+
format: 'JSON',
17+
fromText: '{ "field": "value" }'
18+
}, {
19+
format: 'Msgpack',
20+
fromText: '{ "field": "value" }',
21+
toText: 'DF00000001A56669656C64A576616C7565'
22+
}, {
23+
format: 'ASCII',
24+
fromText: '山女子水 рус ascii',
25+
toText: '\\xe5\\xb1\\xb1\\xe5\\xa5\\xb3\\xe5\\xad\\x90\\xe6\\xb0\\xb4 \\xd1\\x80\\xd1\\x83\\xd1\\x81 ascii'
26+
}, {
27+
format: 'HEX',
28+
fromText: '山女子水 рус ascii',
29+
toText: 'e5b1b1e5a5b3e5ad90e6b0b420d180d183d181206173636969'
30+
}];
31+
32+
fixture `Formatters`
33+
.meta({
34+
type: 'regression',
35+
rte: rte.standalone
36+
})
37+
.page(commonUrl)
38+
.beforeEach(async() => {
39+
await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName);
40+
// Create new keys
41+
await addKeysViaCli(keysData);
42+
})
43+
.afterEach(async() => {
44+
// Clear keys and database
45+
await deleteKeysViaCli(keysData);
46+
await deleteStandaloneDatabaseApi(ossStandaloneConfig);
47+
});
48+
test
49+
.before(async() => {
50+
await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName);
51+
// Create new keys
52+
await addKeysViaCli(keysData, formatters[0].fromText, formatters[0].fromText);
53+
})('Verify that user can see highlighted key details in JSON format', async t => {
54+
// Verify for Hash, List, Set, ZSet, String, Stream keys
55+
for (let i = 0; i < keysData.length; i++) {
56+
const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`);
57+
await browserPage.openKeyDetailsByKeyName(keysData[i].keyName);
58+
// Verify that json value not formatted with default formatter
59+
await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).notOk(`${keysData[i].textType} Value is formatted to JSON`);
60+
await browserPage.selectFormatter('JSON');
61+
// Verify that json value is formatted and highlighted
62+
await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).ok(`${keysData[i].textType} Value is not formatted to JSON`);
63+
// Verify that Hash field is formatted to json and highlighted
64+
if (keysData[i].keyName === 'hash') {
65+
await t.expect(browserPage.hashField.find(browserPage.cssJsonValue).exists).ok('Hash field is not formatted to JSON');
66+
}
67+
// Verify that Stream field is formatted to json and highlighted
68+
if (keysData[i].keyName === 'stream') {
69+
await t.expect(Selector(browserPage.cssJsonValue).count).eql(2, 'Hash field is not formatted to JSON');
70+
}
71+
}
72+
});
73+
test('Verify that user can edit the values in the key regardless if they are valid in JSON/Msgpack format or not', async t => {
74+
// Verify for JSON and Msgpack formatters
75+
const invalidText = 'invalid text';
76+
for (const formatter of formatters) {
77+
if (formatter.format === 'JSON' || formatter.format === 'Msgpack') {
78+
// Open key details and select formatter
79+
await browserPage.openKeyDetails(keysData[0].keyName);
80+
await browserPage.selectFormatter(formatter.format);
81+
await browserPage.editHashKeyValue(invalidText);
82+
// Verify that invalid value can be saved
83+
await t.expect(browserPage.hashFieldValue.textContent).contains(invalidText, `Invalid ${formatter.format} value is not saved`);
84+
await browserPage.editHashKeyValue(formatter.fromText);
85+
// Verify that valid value can be saved
86+
await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.fromText, `Valid ${formatter.format} value is not saved`);
87+
await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).ok(`Value is not formatted to ${formatter.format}`);
88+
}
89+
}
90+
});
91+
test('Verify that user can see tooltip with convertion failed message on hover when data is not valid JSON/Msgpack', async t => {
92+
// Verify for JSON and Msgpack formatters
93+
for (const formatter of formatters) {
94+
if (formatter.format === 'JSON' || formatter.format === 'Msgpack') {
95+
const failedMessage = `Failed to convert to ${formatter.format}`;
96+
for (let i = 0; i < keysData.length; i++) {
97+
const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`);
98+
// Open key details and select formatter
99+
await browserPage.openKeyDetailsByKeyName(keysData[i].keyName);
100+
await browserPage.selectFormatter(formatter.format);
101+
// Verify that not valid value is not formatted
102+
await t.expect(valueSelector.find(browserPage.cssJsonValue).exists).notOk(`${keysData[i].textType} Value is formatted to ${formatter.format}`);
103+
await t.hover(valueSelector, { offsetX: 5 });
104+
// Verify that tooltip with convertion failed message displayed
105+
await t.expect(browserPage.tooltip.textContent).contains(failedMessage, `"${failedMessage}" is not displayed in tooltip`);
106+
}
107+
}
108+
}
109+
});
110+
test
111+
.before(async() => {
112+
await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName);
113+
// Create new keys
114+
await addKeysViaCli(keysData, formatters[1].fromText);
115+
})('Verify that user can see highlighted key details in Msgpack format', async t => {
116+
// Open HaSH key details
117+
await browserPage.openKeyDetailsByKeyName(keysData[0].keyName);
118+
// Verify that msgpack value not formatted with default formatter
119+
await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).notOk('Value is formatted to Msgpack');
120+
// Add valid msgpack in HEX format
121+
await browserPage.selectFormatter('HEX');
122+
await browserPage.editHashKeyValue(formatters[1].toText!);
123+
await browserPage.selectFormatter('Msgpack');
124+
// Verify that msgpack value is formatted and highlighted
125+
await t.expect(browserPage.hashFieldValue.innerText).contains(formatters[1].fromText!, 'Value is not saved as msgpack');
126+
await t.expect(browserPage.hashFieldValue.find(browserPage.cssJsonValue).exists).ok('Value is not formatted to Msgpack');
127+
});
128+
test
129+
.before(async() => {
130+
await acceptLicenseTermsAndAddDatabaseApi(ossStandaloneConfig, ossStandaloneConfig.databaseName);
131+
// Create new keys
132+
await addKeysViaCli(keysData, formatters[2].fromText);
133+
})('Verify that user can see key details converted to ASCII/HEX format', async t => {
134+
// Verify for ASCII and HEX formatters
135+
for (const formatter of formatters) {
136+
if (formatter.format === 'ASCII' || formatter.format === 'HEX') {
137+
// Verify for Hash, List, Set, ZSet, String, Stream keys
138+
for (let i = 0; i < keysData.length; i++) {
139+
const valueSelector = Selector(`[data-testid^=${keysData[i].keyName.split('-')[0]}-][data-testid*=${keysData[i].data}]`);
140+
await browserPage.openKeyDetailsByKeyName(keysData[i].keyName);
141+
// Verify that value not formatted with default formatter
142+
await t.expect(valueSelector.innerText).contains(formatter.fromText!, `Value is formatted as ${formatter.format} in Unicode`);
143+
await browserPage.selectFormatter(formatter.format);
144+
// Verify that value is formatted
145+
await t.expect(valueSelector.innerText).contains(formatter.toText!, `Value is formatted to ${formatter.format}`);
146+
// Verify that Hash field is formatted to ASCII/HEX
147+
if (keysData[i].keyName === 'hash') {
148+
await t.expect(browserPage.hashField.innerText).contains(formatter.toText!, `Hash field is not formatted to ${formatter.format}`);
149+
}
150+
}
151+
}
152+
}
153+
});
154+
test('Verify that user can edit value for Hash field in ASCII/HEX and convert then to another format', async t => {
155+
// Verify for ASCII and HEX formaterrs
156+
for (const formatter of formatters) {
157+
if (formatter.format === 'ASCII' || formatter.format === 'HEX') {
158+
// Open key details and select formatter
159+
await browserPage.openKeyDetails(keysData[0].keyName);
160+
await browserPage.selectFormatter(formatter.format);
161+
// Add value in selected format
162+
await browserPage.editHashKeyValue(formatter.toText!);
163+
// Verify that value saved in selected format
164+
await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.toText!, `${formatter.format} value is not saved`);
165+
await browserPage.selectFormatter('Unicode');
166+
// Verify that value converted to Unicode
167+
await t.expect(browserPage.hashFieldValue.innerText).contains(formatter.fromText!, `${formatter.format} value is not converted to Unicode`);
168+
}
169+
}
170+
});

tests/e2e/tests/critical-path/browser/json-formatter.e2e.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)