Skip to content

Commit 74a4dcd

Browse files
committed
added more test components for tc_14 to test more component declarations and added test suite in parser.test.ts
1 parent 0f45300 commit 74a4dcd

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

src/test/suite/parser.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,24 @@ describe('Parser Test Suite', () => {
104104
expect(tree.children[0]).toHaveProperty('name', 'App');
105105
});
106106

107-
test('App should have three children, Component1 is a client component using hooks, Component2 is a client component using directives, and Component3 is not a client component', () => {
108-
// expect(tree.children[0].children[0]).toHaveProperty('name', 'Component1');
109-
// expect(tree.children[0].children[0]).toHaveProperty('isClientComponent', true);
107+
test('App should have three children, Component1 is a client component using hooks (variable declaration, export default declaration, and function declaration), Component2 is a client component using directives, and Component3 is not a client component', () => {
108+
expect(tree.children[0].children[0]).toHaveProperty('name', 'Component1');
109+
expect(tree.children[0].children[0]).toHaveProperty('isClientComponent', true);
110+
expect(typeof tree.children[0].children[0]).toBe('function');
111+
expect(typeof tree.children[0].children[0]).not.toBe('undefined');
112+
expect(typeof tree.children[0].children[0]).not.toBe('function');
110113

111114
expect(tree.children[0].children[1]).toHaveProperty('name', 'Component2');
112115
expect(tree.children[0].children[1]).toHaveProperty('isClientComponent', true);
113116

114117
expect(tree.children[0].children[2]).toHaveProperty('name', 'Component3');
115118
expect(tree.children[0].children[2]).toHaveProperty('isClientComponent', false);
119+
120+
expect(tree.children[0].children[3]).toHaveProperty('name', 'Component4');
121+
expect(tree.children[0].children[3]).toHaveProperty('isClientComponent', true);
122+
123+
expect(tree.children[0].children[4]).toHaveProperty('name', 'Component5');
124+
expect(tree.children[0].children[4]).toHaveProperty('isClientComponent', true);
116125
});
117126
});
118127
});

src/test/test_cases/tc_14/components/Component1.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState } from 'react';
22

3-
export default function Component1() {
3+
const Component1 = () => {
44
const [count, setCount] = useState(0);
55

66
const handleClick = () => {
@@ -14,4 +14,6 @@ export default function Component1() {
1414
<button onClick={handleClick}>Click Me</button>;
1515
</section>
1616
);
17-
}
17+
}
18+
19+
export default Component1;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useState } from 'react';
2+
3+
export default function Component4() {
4+
const [items, setItems] = useState([]);
5+
6+
const addItem = () => {
7+
const newItem = `Item ${items.length + 1}`;
8+
setItems([...items, newItem]);
9+
};
10+
11+
return (
12+
<section>
13+
<h2>List Component</h2>
14+
<button onClick={addItem}>Add Item</button>
15+
<ul>
16+
{items.map((item, index) => (
17+
<li key={index}>{item}</li>
18+
))}
19+
</ul>
20+
</section>
21+
);
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useState } from 'react';
2+
3+
function Component5() {
4+
const [isToggled, setIsToggled] = useState(false);
5+
6+
const handleToggle = () => {
7+
setIsToggled(!isToggled);
8+
};
9+
10+
return (
11+
<section>
12+
<h2>Toggle Component</h2>
13+
<p>Status: {isToggled ? 'Enabled' : 'Disabled'}</p>
14+
<button onClick={handleToggle}>{isToggled ? 'Disable' : 'Enable'}</button>;
15+
</section>
16+
);
17+
}
18+
19+
export default Component5;

0 commit comments

Comments
 (0)