Skip to content

Commit 56bc60e

Browse files
committed
Add test cases ui5/webcomponents-react explore
1 parent dcfc88b commit 56bc60e

File tree

6 files changed

+98
-0
lines changed

6 files changed

+98
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name List properties of react modelling
3+
* @description List properties of react modelling
4+
* @ kind problem
5+
* @problem.severity info
6+
* @precision high
7+
* @id js/ui5-investigate-react
8+
* @tags diagnostics
9+
*/
10+
11+
import javascript
12+
import semmle.javascript.frameworks.React
13+
14+
from ViewComponentInput v
15+
select v, v.getSourceType()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Input, Button } from '@ui5/webcomponents-react';
2+
import { useRef, useState } from 'react';
3+
import type { InputDomRef } from '@ui5/webcomponents-react';
4+
5+
function ControlledComponent( { props }) {
6+
const inputRef1 = useRef < InputDomRef > (null);
7+
const [inputRef2, setInputValue] = useState('');
8+
9+
const handleButtonPress1 = () => {
10+
// Access the input value via the hook
11+
console.log('Current input value:', inputRef1.current.value); // SOURCE
12+
};
13+
14+
const handleButtonPress2 = event => {
15+
setInputValue(event.target.value); // SOURCE
16+
console.log('Current input value:', inputRef2); // SOURCE - only because of setInputValue
17+
};
18+
19+
return (
20+
<div>
21+
<Input
22+
ref={inputRef1}
23+
placeholder="Enter some text"
24+
/>
25+
<Button onClick={handleButtonPress1}>
26+
Get Input Value
27+
</Button>
28+
<Input
29+
placeholder="Enter some text"
30+
value={inputRef2}
31+
/>
32+
<Button onClick={handleButtonPress2}>
33+
Get Input Value
34+
</Button>
35+
</div>
36+
);
37+
}
38+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Input } from '@ui5/webcomponents-react';
2+
3+
// normal react component props
4+
function ChildComponent({ value }) { // SOURCE
5+
6+
console.log('Input finalized with value:', value);
7+
8+
return (
9+
<div>
10+
<Input
11+
placeholder={value}
12+
/>
13+
</div>
14+
);
15+
}
16+
17+
function ParentComponent() {
18+
const data = "Hello from Parent";
19+
return <ChildComponent value={data} />;
20+
}

javascript/frameworks/ui5/test/models/source-react/sourceTest.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Diagnostics/InvestigateReact.ql
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Input, Button } from '@ui5/webcomponents-react';
2+
import type { InputDomRef } from '@ui5/webcomponents-react';
3+
import type { Ui5CustomEvent } from '@ui5/webcomponents-react-base';
4+
5+
function UncontrolledComponent({ props }) {
6+
7+
//direct event value access, no hook/react specific function
8+
const handleButtonPress = (event: Ui5CustomEvent<InputDomRef>) => {
9+
const finalValue = event.target.value; // SOURCE
10+
console.log('Input finalized with value:', finalValue);
11+
};
12+
13+
return (
14+
<div>
15+
<Input
16+
placeholder="Enter some text"
17+
/>
18+
<Button>
19+
Get Input Value
20+
</Button>
21+
</div>
22+
);
23+
}
24+

0 commit comments

Comments
 (0)