-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_modal_components.py
More file actions
executable file
Β·278 lines (225 loc) Β· 9.74 KB
/
test_modal_components.py
File metadata and controls
executable file
Β·278 lines (225 loc) Β· 9.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env python3
"""
Test suite for Modal components in Flowbite MCP Server
Tests all modal variants: basic, confirmation, form, timeline
"""
import asyncio
import sys
import os
# Add the current directory to the path so we can import the mcp_server_simple module
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from mcp_server_simple import SimpleMCPServer
class ModalComponentTester:
def __init__(self):
self.server = SimpleMCPServer()
self.test_results = []
async def test_basic_modal(self):
"""Test basic modal variant"""
print("π§ͺ Testing Basic Modal...")
result = await self.server.generate_component(
component_type="modal",
variant="basic",
props={
"id": "basic-modal",
"title": "Terms of Service",
"content": "Please read and accept our terms of service to continue.",
"primary_button": "Accept",
"secondary_button": "Decline"
}
)
success = "error" not in result and "modal" in result["content"][0]["text"].lower()
self.test_results.append(("Basic Modal", success))
if success:
print("β
Basic modal generated successfully")
print(f" Generated ID: basic-modal")
print(f" Title: Terms of Service")
print(f" Buttons: Accept, Decline")
else:
print("β Basic modal generation failed")
print(f" Error: {result}")
return success
async def test_confirmation_modal(self):
"""Test confirmation modal variant"""
print("\nπ§ͺ Testing Confirmation Modal...")
result = await self.server.generate_component(
component_type="modal",
variant="confirmation",
props={
"id": "delete-confirmation",
"message": "Are you sure you want to delete this item? This action cannot be undone.",
"confirm_button": "Yes, delete it",
"cancel_button": "No, keep it"
}
)
success = "error" not in result and "confirmation" in result["content"][0]["text"].lower()
self.test_results.append(("Confirmation Modal", success))
if success:
print("β
Confirmation modal generated successfully")
print(f" Modal type: Delete confirmation")
print(f" Buttons: Yes, delete it | No, keep it")
else:
print("β Confirmation modal generation failed")
print(f" Error: {result}")
return success
async def test_form_modal(self):
"""Test form modal variant"""
print("\nπ§ͺ Testing Form Modal...")
result = await self.server.generate_component(
component_type="modal",
variant="form",
props={
"id": "add-product-modal",
"title": "Add New Product",
"form_fields": "Product Name",
"submit_button": "Add Product"
}
)
success = "error" not in result and "form" in result["content"][0]["text"].lower()
self.test_results.append(("Form Modal", success))
if success:
print("β
Form modal generated successfully")
print(f" Form type: Add New Product")
print(f" Fields: Product Name")
print(f" Submit: Add Product")
else:
print("β Form modal generation failed")
print(f" Error: {result}")
return success
async def test_timeline_modal(self):
"""Test timeline modal variant"""
print("\nπ§ͺ Testing Timeline Modal...")
result = await self.server.generate_component(
component_type="modal",
variant="timeline",
props={
"id": "project-timeline",
"title": "Project History",
"timeline_item": "Version 2.0 Released",
"timeline_date": "March 2024",
"timeline_description": "Major update with new features and improvements."
}
)
success = "error" not in result and "timeline" in result["content"][0]["text"].lower()
self.test_results.append(("Timeline Modal", success))
if success:
print("β
Timeline modal generated successfully")
print(f" Timeline: Version 2.0 Released")
print(f" Date: March 2024")
print(f" Description: Major update...")
else:
print("β Timeline modal generation failed")
print(f" Error: {result}")
return success
async def test_modal_suggestions(self):
"""Test modal component suggestions"""
print("\nπ§ͺ Testing Modal Suggestions...")
# Test popup/modal keyword suggestions
result = await self.server.suggest_components(
description="popup dialog for user confirmation",
context="dashboard"
)
text = result["content"][0]["text"]
has_modal = "modal" in text.lower()
has_confirmation = "confirmation" in text.lower()
success = has_modal and has_confirmation
self.test_results.append(("Modal Suggestions", success))
if success:
print("β
Modal suggestions working correctly")
print(f" Suggested modal component: β")
print(f" Context-aware suggestions: β")
else:
print("β Modal suggestions failed")
print(f" Modal suggested: {has_modal}")
print(f" Context-aware: {has_confirmation}")
return success
async def test_modal_validation(self):
"""Test modal component validation"""
print("\nπ§ͺ Testing Modal Validation...")
# Test invalid variant
result = await self.server.generate_component(
component_type="modal",
variant="invalid-variant",
props={}
)
has_error = "error" in result
success = has_error and "invalid-variant" in str(result.get("error", "")).lower()
self.test_results.append(("Modal Validation", success))
if success:
print("β
Modal validation working correctly")
print(f" Invalid variant detected: β")
print(f" Available variants listed: β")
else:
print("β Modal validation failed")
print(f" Error handling: {has_error}")
return success
async def test_modal_defaults(self):
"""Test modal default properties"""
print("\nπ§ͺ Testing Modal Defaults...")
# Test modal with minimal props (should use defaults)
result = await self.server.generate_component(
component_type="modal",
variant="basic",
props={}
)
success = "error" not in result
text = result["content"][0]["text"] if success else ""
has_defaults = all(keyword in text.lower() for keyword in [
"basic modal", "confirm", "cancel"
])
success = success and has_defaults
self.test_results.append(("Modal Defaults", success))
if success:
print("β
Modal defaults working correctly")
print(f" Default title: β")
print(f" Default buttons: β")
print(f" Default content: β")
else:
print("β Modal defaults failed")
print(f" Result: {result}")
return success
async def run_all_tests(self):
"""Run all modal component tests"""
print("π Starting Modal Component Tests...")
print("=" * 50)
tests = [
self.test_basic_modal,
self.test_confirmation_modal,
self.test_form_modal,
self.test_timeline_modal,
self.test_modal_suggestions,
self.test_modal_validation,
self.test_modal_defaults
]
for test in tests:
await test()
# Summary
print("\n" + "=" * 50)
print("π MODAL COMPONENT TEST SUMMARY")
print("=" * 50)
passed = sum(1 for _, success in self.test_results if success)
total = len(self.test_results)
for test_name, success in self.test_results:
status = "β
PASS" if success else "β FAIL"
print(f"{status} | {test_name}")
print(f"\nπ― Results: {passed}/{total} tests passed ({passed/total*100:.1f}% success rate)")
if passed == total:
print("π ALL MODAL TESTS PASSED! Modal components are working perfectly!")
return True
else:
print("β οΈ Some modal tests failed. Check the output above for details.")
return False
async def main():
"""Main test execution"""
tester = ModalComponentTester()
success = await tester.run_all_tests()
if success:
print("\n⨠Modal component implementation is complete and ready for use!")
print("\nπ§ Try these examples:")
print(" β’ generate_component('modal', 'basic', {'title': 'Welcome'})")
print(" β’ generate_component('modal', 'confirmation', {'message': 'Delete item?'})")
print(" β’ generate_component('modal', 'form', {'title': 'Add User'})")
print(" β’ generate_component('modal', 'timeline', {'title': 'Project Status'})")
else:
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())