Skip to content

Commit 9657829

Browse files
authored
Merge pull request #3490 from RedisInsight/fe/bugfix/RI-5826-fix-json
#RI-5826 - fix json object
2 parents d9778b0 + 3d4669d commit 9657829

File tree

7 files changed

+261
-6
lines changed

7 files changed

+261
-6
lines changed

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('JSONUtils', () => {
5353
expect(isRealArray([])).toBeTruthy()
5454
expect(isRealArray([], 'array')).toBeTruthy()
5555
expect(isRealArray({}, 'array')).toBeTruthy()
56+
expect(isRealArray([], 'object')).toBeFalsy()
5657
expect(isRealArray({})).toBeFalsy()
5758
expect(isRealArray('')).toBeFalsy()
5859
expect(isRealArray(null)).toBeFalsy()

redisinsight/ui/src/pages/browser/modules/key-details/components/rejson-details/utils/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const isRealObject = (data: any, knownType?: string) => {
5151

5252
export const isRealArray = (data: any, knownType?: string) => {
5353
if (knownType === ObjectTypes.Array) return true
54+
if (knownType) return false
5455
return isArray(data)
5556
}
5657

tests/e2e/helpers/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class Common {
221221
const parsedJson = JSON.parse(fs.readFileSync(path, 'utf-8'));
222222
return parsedJson[property];
223223
}
224+
224225
/**
225226
* Create Zip archive from folder
226227
* @param folderPath Path to folder to archive

tests/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"build:ui": "yarn --cwd ../../ build:ui",
1414
"redis:last": "docker run --name redis-last-version -p 7777:6379 -d redislabs/redismod",
1515
"start:app": "cross-env yarn start:api",
16-
"test:chrome": "testcafe --compiler-options typescript.configPath=tsconfig.testcafe.json --cache --allow-insecure-localhost --ignore-certificate-errors --disable-multiple-windows --concurrency 1 chrome tests/ -r html:./report/report.html,spec -e -s takeOnFails=true,path=report/screenshots/,pathPattern=${OS}_${BROWSER}/${DATE}_${TIME}/${FIXTURE}_${TEST}_${FILE_INDEX}.png",
16+
"test:chrome": "testcafe --compiler-options typescript.configPath=tsconfig.testcafe.json --cache --allow-insecure-localhost --disable-multiple-windows --concurrency 1 chrome tests/ -r html:./report/report.html,spec -e -s takeOnFails=true,path=report/screenshots/,pathPattern=${OS}_${BROWSER}/${DATE}_${TIME}/${FIXTURE}_${TEST}_${FILE_INDEX}.png",
1717
"test:chrome:ci": "ts-node ./web.runner.ts",
1818
"test": "yarn test:chrome",
1919
"lint": "eslint . --ext .ts,.js,.tsx,.jsx",

tests/e2e/pageObjects/browser-page.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,8 @@ export class BrowserPage extends InstancePage {
870870
*/
871871
async addJsonKeyOnTheSameLevel(jsonKey: string, jsonKeyValue: string): Promise<void> {
872872
await t.click(this.addJsonObjectButton);
873-
await t.typeText(this.jsonKeyInput, jsonKey, { replace: true, paste: true });
874-
await t.typeText(this.jsonValueInput, jsonKeyValue, { replace: true, paste: true });
873+
await t.typeText(this.jsonKeyInput, jsonKey, { paste: true });
874+
await t.typeText(this.jsonValueInput, jsonKeyValue, { paste: true });
875875
await t.click(this.applyButton);
876876
}
877877

@@ -883,8 +883,19 @@ export class BrowserPage extends InstancePage {
883883
async addJsonKeyInsideStructure(jsonKey: string, jsonKeyValue: string): Promise<void> {
884884
await t.click(this.expandJsonObject);
885885
await t.click(this.addJsonFieldButton);
886-
await t.typeText(this.jsonKeyInput, jsonKey, { replace: true, paste: true });
887-
await t.typeText(this.jsonValueInput, jsonKeyValue, { replace: true, paste: true });
886+
await t.typeText(this.jsonKeyInput, jsonKey, { paste: true });
887+
await t.typeText(this.jsonValueInput, jsonKeyValue, { paste: true });
888+
await t.click(this.applyButton);
889+
}
890+
891+
/**
892+
* Add json value inside the Json structure
893+
* @param jsonKeyValue The value of the json key
894+
*/
895+
async addJsonValueInsideStructure(jsonKeyValue: string): Promise<void> {
896+
await t.click(this.expandJsonObject);
897+
await t.click(this.addJsonFieldButton);
898+
await t.typeText(this.jsonValueInput, jsonKeyValue, { paste: true });
888899
await t.click(this.applyButton);
889900
}
890901

@@ -897,7 +908,7 @@ export class BrowserPage extends InstancePage {
897908
await t.click(this.expandJsonObject);
898909
}
899910
await t.click(this.editJsonObjectButton);
900-
await t.typeText(this.jsonValueInput, jsonStructure, { replace: true, paste: true });
911+
await t.typeText(this.jsonValueInput, jsonStructure, { paste: true });
901912
await t.click(this.applyEditButton);
902913
}
903914

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
{
2+
"_id": "666c56b9f4f88278244b6dc8",
3+
"index": 0,
4+
"guid": "1743c04d-b95a-4ab9-9e8c-51b0e9b7e009",
5+
"isActive": true,
6+
"balance": "$2,469.16",
7+
"picture": "http://placehold.it/32x32",
8+
"age": 32,
9+
"eyeColor": "green",
10+
"name": "Camille Sims",
11+
"gender": "female",
12+
"company": "ZBOO",
13+
"email": "[email protected]",
14+
"phone": "+1 (942) 411-2857",
15+
"address": "817 Graham Avenue, Ezel, South Carolina, 5845",
16+
"about": "Ut mollit elit eu veniam non do ut in aliquip. Lorem culpa laborum non aliqua non eiusmod amet cupidatat sunt officia elit elit. Ut officia elit adipisicing labore ex deserunt. Amet sit excepteur quis ut adipisicing occaecat proident occaecat in minim.\r\n",
17+
"registered": "2017-08-30T02:25:04 -02:00",
18+
"latitude": 7.648678,
19+
"longitude": 109.700128,
20+
"tags": [
21+
"sit",
22+
"irure",
23+
"nisi",
24+
"ullamco",
25+
"sint",
26+
"consequat",
27+
"do",
28+
"ad",
29+
"elit",
30+
"deserunt",
31+
"ipsum",
32+
"nisi",
33+
"pariatur",
34+
"sit",
35+
"non",
36+
"ad",
37+
"do",
38+
"nulla",
39+
"ad",
40+
"irure",
41+
"ipsum",
42+
"incididunt",
43+
"Lorem",
44+
"enim",
45+
"proident",
46+
"veniam",
47+
"in",
48+
"reprehenderit",
49+
"irure",
50+
"pariatur",
51+
"cupidatat",
52+
"ipsum",
53+
"sit",
54+
"nisi",
55+
"irure",
56+
"ipsum",
57+
"cillum",
58+
"adipisicing",
59+
"reprehenderit",
60+
"occaecat",
61+
"irure",
62+
"irure",
63+
"amet",
64+
"reprehenderit",
65+
"voluptate",
66+
"veniam",
67+
"cillum",
68+
"incididunt",
69+
"magna",
70+
"laboris",
71+
"nisi",
72+
"duis",
73+
"irure",
74+
"do",
75+
"amet",
76+
"aliquip",
77+
"commodo",
78+
"nisi",
79+
"pariatur",
80+
"sunt",
81+
"dolor",
82+
"ut",
83+
"ea",
84+
"voluptate",
85+
"laboris",
86+
"pariatur",
87+
"qui",
88+
"duis",
89+
"commodo",
90+
"deserunt"
91+
],
92+
"friends": [
93+
{
94+
"id": 0,
95+
"name": "Erna Lynch"
96+
},
97+
{
98+
"id": 1,
99+
"name": "Vicky Vega"
100+
},
101+
{
102+
"id": 2,
103+
"name": "Haley Meyer"
104+
},
105+
{
106+
"id": 3,
107+
"name": "Darlene Knight"
108+
},
109+
{
110+
"id": 4,
111+
"name": "Odonnell Cain"
112+
},
113+
{
114+
"id": 5,
115+
"name": "Hopper Sellers"
116+
},
117+
{
118+
"id": 6,
119+
"name": "Knapp Barry"
120+
},
121+
{
122+
"id": 7,
123+
"name": "Alvarado Clements"
124+
},
125+
{
126+
"id": 8,
127+
"name": "Wolfe Taylor"
128+
},
129+
{
130+
"id": 9,
131+
"name": "Janell Chambers"
132+
},
133+
{
134+
"id": 10,
135+
"name": "Merle Wood"
136+
},
137+
{
138+
"id": 11,
139+
"name": "Ellen Savage"
140+
},
141+
{
142+
"id": 12,
143+
"name": "Elliott Humphrey"
144+
},
145+
{
146+
"id": 13,
147+
"name": "Ayers Chase"
148+
},
149+
{
150+
"id": 14,
151+
"name": "Robbie Kirkland"
152+
},
153+
{
154+
"id": 15,
155+
"name": "Whitney Perkins"
156+
},
157+
{
158+
"id": 16,
159+
"name": "Marisa Lloyd"
160+
},
161+
{
162+
"id": 17,
163+
"name": "Helene Case"
164+
},
165+
{
166+
"id": 18,
167+
"name": "Berry Tyler"
168+
},
169+
{
170+
"id": 19,
171+
"name": "Frieda Cannon"
172+
},
173+
{
174+
"id": 20,
175+
"name": "Sonya Leon"
176+
},
177+
{
178+
"id": 21,
179+
"name": "Wilda Glass"
180+
},
181+
{
182+
"id": 22,
183+
"name": "Sims Kaufman"
184+
},
185+
{
186+
"id": 23,
187+
"name": "Ballard Preston"
188+
},
189+
{
190+
"id": 24,
191+
"name": "Carroll Clay"
192+
},
193+
{
194+
"id": 25,
195+
"name": "Medina Curry"
196+
},
197+
{
198+
"id": 26,
199+
"name": "Beatriz Herrera"
200+
},
201+
{
202+
"id": 27,
203+
"name": "Marianne Vargas"
204+
},
205+
{
206+
"id": 28,
207+
"name": "Galloway Stanton"
208+
},
209+
{
210+
"id": 29,
211+
"name": "Rhea Marshall"
212+
}
213+
],
214+
"greeting": "Hello, Camille Sims! You have 10 unread messages.",
215+
"favoriteFruit": "strawberry"
216+
}

tests/e2e/tests/web/smoke/browser/json-key.e2e.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import { rte } from '../../../../helpers/constants';
23
import { DatabaseHelper } from '../../../../helpers/database';
34
import { BrowserPage } from '../../../../pageObjects';
@@ -15,6 +16,7 @@ let keyName = Common.generateWord(10);
1516
const keyTTL = '2147476121';
1617
const value = '{"name":"xyz"}';
1718
const jsonObjectValue = '{name:"xyz"}';
19+
const jsonFilePath = path.join('..', '..', '..', '..', 'test-data', 'big-json', 'big-json.json');
1820

1921
fixture `JSON Key verification`
2022
.meta({ type: 'smoke', rte: rte.standalone })
@@ -49,3 +51,26 @@ test('Verify that user can add key with value to any level of JSON structure', a
4951
// Check the added key contains json object with added key
5052
await t.expect(browserPage.jsonKeyValue.textContent).eql('{name:"xyz"key1:"value1"key2:{key2222:12345}}', 'The json object value not found');
5153
});
54+
test('Verify that user can add key with value to any level of JSON structure for big JSON object', async t => {
55+
keyName = Common.generateWord(10);
56+
// Add Json key with json object
57+
await t.click(browserPage.plusAddKeyButton);
58+
await t.click(browserPage.keyTypeDropDown);
59+
await t.click(browserPage.jsonOption);
60+
await t.click(browserPage.addKeyNameInput);
61+
await t.typeText(browserPage.addKeyNameInput, keyName, { replace: true, paste: true });
62+
await t.setFilesToUpload(browserPage.jsonUploadInput, [jsonFilePath]);
63+
await t.click(browserPage.addKeyButton);
64+
// Check the notification message
65+
const notification = browserPage.Toast.toastHeader.textContent;
66+
await t.expect(notification).contains('Key has been added', 'The notification not found');
67+
// Add key with value on the same level
68+
await browserPage.addJsonKeyOnTheSameLevel('"key1"', '"value1"');
69+
// Check the added key contains json object with added key
70+
await t.expect(browserPage.addJsonObjectButton.exists).ok('The add Json object button not found', { timeout: 10000 });
71+
await t.expect(browserPage.jsonKeyValue.textContent).contains('"key1:"value1"}', 'The json object value not found');
72+
// Add value inside the json array
73+
await browserPage.addJsonValueInsideStructure('12345');
74+
// Check the added key contains json object with added key
75+
await t.expect(browserPage.jsonKeyValue.textContent).contains('"70:12345]', 'The json object value not found');
76+
});

0 commit comments

Comments
 (0)