100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

dbbasic-web-native/test_integration.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
test_integration.py · 8.5 KB · 259 lines
1#!/usr/bin/env python3
2"""
3Integration tests for component composition.
4Tests how components work together in real-world scenarios.
5Cost: FREE (Playwright functional testing)
6Run: On PR
7"""
8
9from playwright.sync_api import sync_playwright
10from pathlib import Path
11import json
12
13class IntegrationTester:
14 def __init__(self):
15 self.results = []
16
17 def test_modal_with_actions(self, page):
18 """Test modal containing action buttons"""
19 issues = []
20
21 # Create test page
22 page.set_content("""
23 <!DOCTYPE html>
24 <html>
25 <head><script src="file:///Users/danq/dbbasic-web-native/semantic-components.js"></script></head>
26 <body>
27 <semantic-modal id="test-modal" open>
28 <div slot="header">Confirm Delete</div>
29 <div>Are you sure?</div>
30 <div slot="actions">
31 <semantic-action intent="destructive">Delete</semantic-action>
32 <semantic-action intent="secondary">Cancel</semantic-action>
33 </div>
34 </semantic-modal>
35 </body>
36 </html>
37 """)
38 page.wait_for_load_state('networkidle')
39
40 # Check modal is visible
41 modal = page.locator('semantic-modal')
42 if not modal.is_visible():
43 issues.append({'type': 'modal_not_visible', 'severity': 'error'})
44
45 # Check action buttons rendered in shadow DOM
46 buttons = page.locator('semantic-action').count()
47 if buttons != 2:
48 issues.append({
49 'type': 'buttons_not_rendered',
50 'expected': 2,
51 'actual': buttons,
52 'severity': 'error'
53 })
54
55 return {'test': 'modal_with_actions', 'passed': len(issues) == 0, 'issues': issues}
56
57 def test_card_with_actions(self, page):
58 """Test card containing action buttons"""
59 issues = []
60
61 page.set_content("""
62 <!DOCTYPE html>
63 <html>
64 <head><script src="file:///Users/danq/dbbasic-web-native/semantic-components.js"></script></head>
65 <body>
66 <semantic-card>
67 <h3 slot="header">Project Alpha</h3>
68 <p>Description of the project</p>
69 <div slot="actions">
70 <semantic-action intent="primary">Open</semantic-action>
71 <semantic-action intent="secondary">Edit</semantic-action>
72 </div>
73 </semantic-card>
74 </body>
75 </html>
76 """)
77 page.wait_for_load_state('networkidle')
78
79 # Check card is visible
80 card = page.locator('semantic-card')
81 if not card.is_visible():
82 issues.append({'type': 'card_not_visible', 'severity': 'error'})
83
84 # Check actions slot
85 buttons = page.locator('semantic-action').count()
86 if buttons != 2:
87 issues.append({
88 'type': 'action_buttons_missing',
89 'expected': 2,
90 'actual': buttons,
91 'severity': 'error'
92 })
93
94 return {'test': 'card_with_actions', 'passed': len(issues) == 0, 'issues': issues}
95
96 def test_list_with_navigation(self, page):
97 """Test list items that navigate"""
98 issues = []
99
100 page.set_content("""
101 <!DOCTYPE html>
102 <html>
103 <head><script src="file:///Users/danq/dbbasic-web-native/semantic-components.js"></script></head>
104 <body>
105 <semantic-list selectable>
106 <div data-item-id="1">First Item</div>
107 <div data-item-id="2">Second Item</div>
108 <div data-item-id="3">Third Item</div>
109 </semantic-list>
110 </body>
111 </html>
112 """)
113 page.wait_for_load_state('networkidle')
114
115 # Check items are visible
116 items = page.locator('[data-item-id]').count()
117 if items != 3:
118 issues.append({
119 'type': 'list_items_missing',
120 'expected': 3,
121 'actual': items,
122 'severity': 'error'
123 })
124
125 # Check items are clickable (have proper cursor)
126 first_item = page.locator('[data-item-id="1"]')
127 if first_item.count() > 0:
128 cursor = first_item.evaluate('el => window.getComputedStyle(el).cursor')
129 if cursor != 'pointer':
130 issues.append({
131 'type': 'list_item_not_clickable',
132 'cursor': cursor,
133 'severity': 'warning'
134 })
135
136 return {'test': 'list_with_navigation', 'passed': len(issues) == 0, 'issues': issues}
137
138 def test_form_with_inputs(self, page):
139 """Test form composed of multiple inputs"""
140 issues = []
141
142 page.set_content("""
143 <!DOCTYPE html>
144 <html>
145 <head><script src="file:///Users/danq/dbbasic-web-native/semantic-components.js"></script></head>
146 <body>
147 <form id="test-form">
148 <semantic-input label="Name" placeholder="Enter name"></semantic-input>
149 <semantic-input label="Email" type="email"></semantic-input>
150 <semantic-action intent="primary">Submit</semantic-action>
151 </form>
152 </body>
153 </html>
154 """)
155 page.wait_for_load_state('networkidle')
156
157 # Check inputs rendered
158 inputs = page.locator('semantic-input').count()
159 if inputs != 2:
160 issues.append({
161 'type': 'inputs_missing',
162 'expected': 2,
163 'actual': inputs,
164 'severity': 'error'
165 })
166
167 # Check submit button
168 submit = page.locator('semantic-action').count()
169 if submit != 1:
170 issues.append({
171 'type': 'submit_button_missing',
172 'severity': 'error'
173 })
174
175 return {'test': 'form_with_inputs', 'passed': len(issues) == 0, 'issues': issues}
176
177 def test_nested_navigation(self, page):
178 """Test navigator with nested menu"""
179 issues = []
180
181 page.set_content("""
182 <!DOCTYPE html>
183 <html>
184 <head><script src="file:///Users/danq/dbbasic-web-native/semantic-components.js"></script></head>
185 <body>
186 <semantic-navigator type="tabs">
187 <div data-nav-id="home">Home</div>
188 <div data-nav-id="settings">Settings</div>
189 </semantic-navigator>
190 </body>
191 </html>
192 """)
193 page.wait_for_load_state('networkidle')
194
195 # Check nav items
196 nav_items = page.locator('[data-nav-id]').count()
197 if nav_items != 2:
198 issues.append({
199 'type': 'nav_items_missing',
200 'expected': 2,
201 'actual': nav_items,
202 'severity': 'error'
203 })
204
205 return {'test': 'nested_navigation', 'passed': len(issues) == 0, 'issues': issues}
206
207 def run_all_tests(self):
208 """Run all integration tests"""
209 print("\n🔗 Running integration tests...\n")
210
211 with sync_playwright() as p:
212 browser = p.chromium.launch(headless=True)
213 page = browser.new_page(viewport={'width': 1400, 'height': 1200})
214
215 tests = [
216 self.test_modal_with_actions,
217 self.test_card_with_actions,
218 self.test_list_with_navigation,
219 self.test_form_with_inputs,
220 self.test_nested_navigation
221 ]
222
223 for test in tests:
224 test_name = test.__doc__.strip()
225 print(f"🔍 {test_name}...", end='')
226 result = test(page)
227 self.results.append(result)
228
229 if result['passed']:
230 print(" ✅")
231 else:
232 print(f" ❌ ({len(result['issues'])} issues)")
233
234 browser.close()
235
236 self.generate_report()
237
238 def generate_report(self):
239 """Generate test report"""
240 passed = sum(1 for r in self.results if r['passed'])
241 total = len(self.results)
242
243 # Save JSON
244 results_path = Path(__file__).parent / 'test-results' / 'results-integration.json'
245 results_path.parent.mkdir(exist_ok=True)
246 with open(results_path, 'w') as f:
247 json.dump(self.results, f, indent=2)
248
249 print(f"\n📊 Integration tests complete!")
250 print(f" Passed: {passed}/{total}")
251 print(f" Results: {results_path}")
252
253 # Exit with error if any tests failed
254 if passed < total:
255 exit(1)
256
257if __name__ == '__main__':
258 tester = IntegrationTester()
259 tester.run_all_tests()