Skip to content

Commit 7a03465

Browse files
committed
feat: update unit test coverage to 84.8% and enhance bounding box tests for edge cases
1 parent bafe9fc commit 7a03465

3 files changed

Lines changed: 79 additions & 23 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"rector --dry-run",
5959
"pint --test"
6060
],
61-
"test:unit": "pest --parallel --coverage --exactly=81.3",
61+
"test:unit": "pest --parallel --coverage --exactly=84.8",
6262
"test:types": "phpstan",
6363
"test": [
6464
"@test:lint",

playground/resources/views/test-pages/element-tests.blade.php

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
<!-- User Profile Section -->
183183
<div class="section user-profile" data-testid="user-profile">
184184
<h2>User Profile</h2>
185-
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgZmlsbD0iIzY2NzMiLz4KICA8dGV4dCB4PSI1MCIgeT0iNTUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0id2hpdGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPlVzZXI8L3RleHQ+Cjwvc3ZnPgo="
185+
<img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgZmlsbD0iIzY2NzMiLz4KICA8dGV4dCB4PSI1MCIgeT0iNTUiIGZvcnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNCIgZmlsbD0id2hpdGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiPlVzZXI8L3RleHQ+Cjwvc3ZnPgo="
186186
alt="Profile Picture"
187187
class="profile-picture" />
188188

@@ -284,7 +284,58 @@ class="profile-picture" />
284284
<div data-testid="scroll-target" style="margin-top: 500px;">
285285
This element is far down the page for scroll testing
286286
</div>
287-
</div> <script>
287+
</div>
288+
289+
<!-- Edge case elements that might return malformed bounding box data -->
290+
<div class="section">
291+
<h2>Edge Case Elements for Bounding Box Testing</h2>
292+
293+
<!-- Elements with unusual CSS properties -->
294+
<div data-testid="zero-width-element" style="width: 0; height: 0; overflow: hidden;">Zero dimensions element
295+
</div>
296+
<div data-testid="negative-margin-element" style="margin: -100px; width: 50px; height: 50px;">Negative margin element
297+
</div>
298+
<div data-testid="transform-element" style="transform: scale(0); width: 100px; height: 100px;">Scaled to zero element
299+
</div>
300+
<div data-testid="position-absolute-element" style="position: absolute; left: -9999px; top: -9999px;">Off-screen absolute element
301+
</div>
302+
303+
<!-- Elements that might cause bounding box calculation issues -->
304+
<div data-testid="float-element" style="float: left; width: 0.1px; height: 0.1px;">Tiny float element</div>
305+
<div data-testid="inline-block-element" style="display: inline-block; width: 0; height: 0;">Inline block zero size
306+
</div>
307+
308+
<!-- SVG elements that might have edge cases -->
309+
<svg width="0" height="0" data-testid="zero-svg">
310+
<rect width="0" height="0" data-testid="zero-rect" />
311+
</svg>
312+
313+
<!-- Table elements with edge cases -->
314+
<table data-testid="empty-table" style="border-collapse: collapse;">
315+
<tr data-testid="empty-row">
316+
<td data-testid="empty-cell" style="padding: 0; margin: 0; width: 0; height: 0;"></td>
317+
</tr>
318+
</table>
319+
320+
<!-- Elements with CSS that might cause calculation errors -->
321+
<div data-testid="overflow-hidden-element" style="overflow: hidden; width: 0; height: 0;">
322+
<div style="width: 100px; height: 100px;">Hidden content</div>
323+
</div>
324+
325+
<!-- Element with complex transform that might break calculations -->
326+
<div data-testid="complex-transform-element" style="transform: matrix(0, 0, 0, 0, 0, 0); width: 100px; height: 100px;">Matrix transform zero
327+
</div>
328+
329+
<!-- Element with visibility hidden but dimensions -->
330+
<div data-testid="visibility-hidden-element" style="visibility: hidden; width: 100px; height: 100px;">Visibility hidden element
331+
</div>
332+
333+
<!-- Element with opacity 0 -->
334+
<div data-testid="opacity-zero-element" style="opacity: 0; width: 100px; height: 100px;">Opacity zero element
335+
</div>
336+
</div>
337+
338+
<script>
288339
// Counter for click testing
289340
let clickCounter = 0;
290341
@@ -318,46 +369,46 @@ function trackHover(elementId) {
318369
}
319370
320371
// Add some basic interactivity for testing
321-
document.addEventListener('DOMContentLoaded', function() {
372+
document.addEventListener('DOMContentLoaded', function () {
322373
// Event button click handler
323374
const eventButton = document.getElementById('event-button');
324375
const eventResult = document.getElementById('event-result');
325376
326377
if (eventButton && eventResult) {
327-
eventButton.addEventListener('click', function() {
378+
eventButton.addEventListener('click', function () {
328379
eventResult.textContent = 'Button was clicked!';
329380
});
330381
}
331382
332383
// Add focus tracking event listeners
333-
document.getElementById('focus-target').addEventListener('focus', function() {
384+
document.getElementById('focus-target').addEventListener('focus', function () {
334385
trackFocus('focus-target');
335386
});
336-
document.getElementById('username').addEventListener('focus', function() {
387+
document.getElementById('username').addEventListener('focus', function () {
337388
trackFocus('username');
338389
});
339-
document.getElementById('password').addEventListener('focus', function() {
390+
document.getElementById('password').addEventListener('focus', function () {
340391
trackFocus('password');
341392
});
342-
document.getElementById('search').addEventListener('focus', function() {
393+
document.getElementById('search').addEventListener('focus', function () {
343394
trackFocus('search');
344395
});
345-
document.getElementById('comments').addEventListener('focus', function() {
396+
document.getElementById('comments').addEventListener('focus', function () {
346397
trackFocus('comments');
347398
});
348399
349400
// Hover tracking
350401
const hoverTarget = document.getElementById('hover-target');
351402
if (hoverTarget) {
352403
['mouseenter', 'mouseover', 'pointerenter'].forEach(event => {
353-
hoverTarget.addEventListener(event, function() {
404+
hoverTarget.addEventListener(event, function () {
354405
trackHover('hover-target');
355406
});
356407
});
357408
}
358409
359410
// Add global hover detection for Playwright compatibility
360-
document.addEventListener('mousemove', function(e) {
411+
document.addEventListener('mousemove', function (e) {
361412
if (e.target.id === 'hover-target') {
362413
trackHover('hover-target');
363414
}
@@ -366,7 +417,7 @@ function trackHover(elementId) {
366417
// Make forms more interactive
367418
const usernameInput = document.getElementById('username');
368419
if (usernameInput) {
369-
usernameInput.addEventListener('input', function() {
420+
usernameInput.addEventListener('input', function () {
370421
console.log('Username changed to:', this.value);
371422
});
372423
}

tests/Browser/Playwright/Locator/BoundingBoxTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,28 @@
2727
expect($boundingBox)->toBeNull();
2828
});
2929

30-
it('bounding box coordinates are valid', function (): void {
30+
it('returns null when boundingBox element is not found', function (): void {
3131
$page = page()->goto('/test/element-tests');
32-
$button = $page->getByTestId('click-button');
32+
$locator = $page->locator('.non-existent-element');
3333

34-
$boundingBox = $button->boundingBox();
34+
$boundingBox = $locator->boundingBox();
3535

36-
expect($boundingBox['x'])->toBeGreaterThanOrEqual(0);
37-
expect($boundingBox['y'])->toBeGreaterThanOrEqual(0);
38-
expect($boundingBox['width'])->toBeGreaterThan(0);
39-
expect($boundingBox['height'])->toBeGreaterThan(0);
36+
expect($boundingBox)->toBeNull();
4037
});
4138

42-
it('returns null when boundingBox element is not found', function (): void {
39+
it('returns null for elements without visible bounding boxes', function (): void {
4340
$page = page()->goto('/test/element-tests');
44-
$locator = $page->locator('.non-existent-element');
4541

42+
$locator = $page->locator('head');
4643
$boundingBox = $locator->boundingBox();
47-
4844
expect($boundingBox)->toBeNull();
4945
});
46+
47+
it('handles edge case elements that might return malformed bounding box data', function (): void {
48+
$page = page()->goto('/test/element-tests');
49+
50+
$locator = $page->getByTestId('zero-width-element');
51+
$boundingBox = $locator->boundingBox();
52+
53+
expect($boundingBox)->toBeNull();
54+
})->todo('find a way to handle zero-width elements gracefully');

0 commit comments

Comments
 (0)