|
15 | 15 | fetch_percy_dom, |
16 | 16 | percy_snapshot, |
17 | 17 | percy_automate_screenshot, |
| 18 | + create_region |
18 | 19 | ) |
19 | 20 | import percy.screenshot as local |
20 | 21 |
|
@@ -367,6 +368,120 @@ def test_percy_automate_screenshot_invalid_call(self, mock_is_percy_enabled): |
367 | 368 |
|
368 | 369 | self.assertTrue("Invalid function call" in str(context.exception)) |
369 | 370 |
|
| 371 | +class TestCreateRegion(unittest.TestCase): |
| 372 | + |
| 373 | + def test_create_region_with_all_params(self): |
| 374 | + result = create_region( |
| 375 | + boundingBox={"x": 10, "y": 20, "width": 100, "height": 200}, |
| 376 | + elementXpath="//*[@id='test']", |
| 377 | + elementCSS=".test-class", |
| 378 | + padding=10, |
| 379 | + algorithm="intelliignore", |
| 380 | + diffSensitivity=0.8, |
| 381 | + imageIgnoreThreshold=0.5, |
| 382 | + carouselsEnabled=True, |
| 383 | + bannersEnabled=False, |
| 384 | + adsEnabled=True, |
| 385 | + diffIgnoreThreshold=0.2 |
| 386 | + ) |
| 387 | + |
| 388 | + expected_result = { |
| 389 | + "algorithm": "intelliignore", |
| 390 | + "elementSelector": { |
| 391 | + "boundingBox": {"x": 10, "y": 20, "width": 100, "height": 200}, |
| 392 | + "elementXpath": "//*[@id='test']", |
| 393 | + "elementCSS": ".test-class" |
| 394 | + }, |
| 395 | + "padding": 10, |
| 396 | + "configuration": { |
| 397 | + "diffSensitivity": 0.8, |
| 398 | + "imageIgnoreThreshold": 0.5, |
| 399 | + "carouselsEnabled": True, |
| 400 | + "bannersEnabled": False, |
| 401 | + "adsEnabled": True |
| 402 | + }, |
| 403 | + "assertion": { |
| 404 | + "diffIgnoreThreshold": 0.2 |
| 405 | + } |
| 406 | + } |
| 407 | + |
| 408 | + self.assertEqual(result, expected_result) |
| 409 | + |
| 410 | + def test_create_region_with_minimal_params(self): |
| 411 | + result = create_region( |
| 412 | + algorithm="standard", |
| 413 | + boundingBox={"x": 10, "y": 20, "width": 100, "height": 200} |
| 414 | + ) |
| 415 | + |
| 416 | + expected_result = { |
| 417 | + "algorithm": "standard", |
| 418 | + "elementSelector": { |
| 419 | + "boundingBox": {"x": 10, "y": 20, "width": 100, "height": 200} |
| 420 | + } |
| 421 | + } |
| 422 | + |
| 423 | + self.assertEqual(result, expected_result) |
| 424 | + |
| 425 | + def test_create_region_with_padding(self): |
| 426 | + result = create_region( |
| 427 | + algorithm="ignore", |
| 428 | + padding=15 |
| 429 | + ) |
| 430 | + |
| 431 | + expected_result = { |
| 432 | + "algorithm": "ignore", |
| 433 | + "elementSelector": {}, |
| 434 | + "padding": 15 |
| 435 | + } |
| 436 | + |
| 437 | + self.assertEqual(result, expected_result) |
| 438 | + |
| 439 | + def test_create_region_with_configuration_only_for_valid_algorithms(self): |
| 440 | + result = create_region( |
| 441 | + algorithm="intelliignore", |
| 442 | + diffSensitivity=0.9, |
| 443 | + imageIgnoreThreshold=0.7 |
| 444 | + ) |
| 445 | + |
| 446 | + expected_result = { |
| 447 | + "algorithm": "intelliignore", |
| 448 | + "elementSelector": {}, |
| 449 | + "configuration": { |
| 450 | + "diffSensitivity": 0.9, |
| 451 | + "imageIgnoreThreshold": 0.7 |
| 452 | + } |
| 453 | + } |
| 454 | + |
| 455 | + self.assertEqual(result, expected_result) |
| 456 | + |
| 457 | + def test_create_region_with_diffIgnoreThreshold_in_assertion(self): |
| 458 | + result = create_region( |
| 459 | + algorithm="standard", |
| 460 | + diffIgnoreThreshold=0.3 |
| 461 | + ) |
| 462 | + |
| 463 | + expected_result = { |
| 464 | + "algorithm": "standard", |
| 465 | + "elementSelector": {}, |
| 466 | + "assertion": { |
| 467 | + "diffIgnoreThreshold": 0.3 |
| 468 | + } |
| 469 | + } |
| 470 | + |
| 471 | + self.assertEqual(result, expected_result) |
| 472 | + |
| 473 | + def test_create_region_with_invalid_algorithm(self): |
| 474 | + result = create_region( |
| 475 | + algorithm="invalid_algorithm" |
| 476 | + ) |
| 477 | + |
| 478 | + expected_result = { |
| 479 | + "algorithm": "invalid_algorithm", |
| 480 | + "elementSelector": {} |
| 481 | + } |
| 482 | + |
| 483 | + self.assertEqual(result, expected_result) |
| 484 | + |
370 | 485 |
|
371 | 486 | if __name__ == "__main__": |
372 | 487 | unittest.main() |
0 commit comments