Skip to content

Commit da6eb17

Browse files
(test) improve coverage on editor
1 parent aa8a135 commit da6eb17

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Dev Server",
9+
"request": "launch",
10+
"sourceMapPathOverrides": {
11+
"webpack:///src/*": "${webRoot}/*"
12+
},
13+
"type": "chrome",
14+
"url": "http://localhost:3000",
15+
"runtimeExecutable": "/usr/bin/chromium",
16+
"webRoot": "${workspaceRoot}/src",
17+
},
18+
{
19+
"name": "Debug Karma Tests",
20+
"request": "launch",
21+
"runtimeArgs": ["--headless"],
22+
"sourceMapPathOverrides": {
23+
"webpack:///src/*": "${workspaceRoot}/src/*",
24+
"webpack:///tests/*": "${workspaceRoot}/tests/*"
25+
},
26+
"type": "chrome",
27+
"runtimeExecutable": "/usr/bin/chromium",
28+
"url": "http://localhost:9876/debug.html",
29+
}
30+
]
31+
}

tests/Editor-test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,79 @@ describe('Editor component', () => {
3333
});
3434

3535
it ('should dispatch selected suggestion', () => {
36+
//S
3637
const spy = expect.createSpy();
3738
const wraper = mount(<Editor input={document.createElement('input')} onJsonPathChanged={spy} jsonpath='abc' position={{x: 0, y:0}} json={{type: 'string'}} />);
39+
//E
3840
wraper.instance().onSelectSuggestion({value: 'test', description: 'test'});
41+
//V
3942
expect(spy).toHaveBeenCalledWith('test');
4043
});
4144

4245
it ('should dispatch selected suggestion when suggestion has setCarretAt', () => {
46+
//S
4347
const spy = expect.createSpy();
4448
const wraper = mount(<Editor input={document.createElement('input')} onJsonPathChanged={spy} jsonpath='abc' position={{x: 0, y:0}} json={{type: 'string'}} />);
49+
//E
4550
wraper.instance().onSelectSuggestion({value: 'test', description: 'test', setCarretAt: 1});
51+
//V
4652
expect(spy).toHaveBeenCalledWith('test');
4753
});
54+
55+
it ('should set json path with suggestion value correctly when jsonpath ends with a part of the suggestion', () => {
56+
//S
57+
const spy = expect.createSpy();
58+
const jsonPath = '$.te.es'; // es is included in 'test' which is the value of the suggestion
59+
const input = document.createElement('input');
60+
input.value = jsonPath;
61+
const wraper = mount(<Editor input={input} onJsonPathChanged={spy} jsonpath={jsonPath} position={{x: 0, y:0}} json={{type: 'string'}} />);
62+
//E
63+
wraper.instance().onSelectSuggestion({value: 'test', description: 'test', setCarretAt: 1});
64+
//V
65+
expect(spy).toHaveBeenCalledWith('$.te.test');
66+
});
67+
68+
it ('should set json path with suggestion value correctly when jsonpath doesn\'t ends with a part of the suggestion', () => {
69+
//S
70+
const spy = expect.createSpy();
71+
const jsonPath = '$.te.re';
72+
const input = document.createElement('input');
73+
input.value = jsonPath;
74+
const wraper = mount(<Editor input={input} onJsonPathChanged={spy} jsonpath={jsonPath} position={{x: 0, y:0}} json={{type: 'string'}} />);
75+
//E
76+
wraper.instance().onSelectSuggestion({value: 'test', description: 'test', setCarretAt: 1});
77+
//V
78+
expect(spy).toHaveBeenCalledWith('$.te.retest');
79+
});
80+
81+
it ('should evaluate suggestions when caret position is updated', () => {
82+
//S
83+
const wraper = mount(<Editor input={document.createElement('input')} position={{x: 0, y:0}} json={{type: 'string'}} />);
84+
const spy = expect.spyOn(wraper.instance(), 'evalPathAndSuggestions');
85+
//E
86+
wraper.instance().onCaretChanged({code: 'ArrowLeft'});
87+
//V
88+
expect(spy).toHaveBeenCalled();
89+
});
90+
91+
92+
it ('should not evaluate suggestions when caret position is updated due to up arrow', () => {
93+
//S
94+
const wraper = mount(<Editor input={document.createElement('input')} position={{x: 0, y:0}} json={{type: 'string'}} />);
95+
const spy = expect.spyOn(wraper.instance(), 'evalPathAndSuggestions');
96+
//E
97+
wraper.instance().onCaretChanged({code: 'ArrowUp'});
98+
//V
99+
expect(spy).toNotHaveBeenCalled();
100+
});
101+
102+
it ('should not evaluate suggestions when caret position is updated due to down arrow', () => {
103+
//S
104+
const wraper = mount(<Editor input={document.createElement('input')} position={{x: 0, y:0}} json={{type: 'string'}} />);
105+
const spy = expect.spyOn(wraper.instance(), 'evalPathAndSuggestions');
106+
//E
107+
wraper.instance().onCaretChanged({code: 'ArrowDown'});
108+
//V
109+
expect(spy).toNotHaveBeenCalled();
110+
});
48111
});

0 commit comments

Comments
 (0)