|
| 1 | +from great_tables._text import Html |
| 2 | +from gt_extras.images import img_header |
| 3 | + |
| 4 | + |
| 5 | +def test_img_header_snapshot(snapshot): |
| 6 | + result = img_header(label="Test Label", img_url="https://example.com/image.png") |
| 7 | + assert snapshot == result |
| 8 | + |
| 9 | + |
| 10 | +def test_img_header_basic(): |
| 11 | + result = img_header(label="Test Label", img_url="https://example.com/image.png") |
| 12 | + |
| 13 | + assert isinstance(result, Html) |
| 14 | + assert "Test Label" in result.text |
| 15 | + assert "https://example.com/image.png" in result.text |
| 16 | + assert "height:60px;" in result.text |
| 17 | + assert "border-bottom:2px solid black;" in result.text |
| 18 | + assert "color:black;" in result.text |
| 19 | + |
| 20 | + |
| 21 | +def test_img_header_custom_height_and_colors(): |
| 22 | + result = img_header( |
| 23 | + label="Custom Label", |
| 24 | + img_url="https://example.com/custom.png", |
| 25 | + height=100, |
| 26 | + border_color="blue", |
| 27 | + text_color="red", |
| 28 | + ) |
| 29 | + |
| 30 | + assert isinstance(result, Html) |
| 31 | + assert "Custom Label" in result.text |
| 32 | + assert "https://example.com/custom.png" in result.text |
| 33 | + assert "height:100px;" in result.text |
| 34 | + assert "border-bottom:2px solid blue;" in result.text |
| 35 | + assert "color:red;" in result.text |
| 36 | + |
| 37 | + |
| 38 | +def test_img_header_custom_font_size(): |
| 39 | + result = img_header( |
| 40 | + label="Font Size Test", img_url="https://example.com/font.png", font_size=20 |
| 41 | + ) |
| 42 | + |
| 43 | + assert isinstance(result, Html) |
| 44 | + assert "Font Size Test" in result.text |
| 45 | + assert "font-size:20px;" in result.text |
| 46 | + |
| 47 | + |
| 48 | +def test_img_header_empty_label(): |
| 49 | + result = img_header(label="", img_url="https://example.com/empty_label.png") |
| 50 | + |
| 51 | + assert isinstance(result, Html) |
| 52 | + assert "https://example.com/empty_label.png" in result.text |
| 53 | + assert "<div" in result.text |
| 54 | + assert "font-size:12px;" in result.text |
| 55 | + |
| 56 | + |
| 57 | +def test_img_header_empty_url(): |
| 58 | + result = img_header(label="Invalid URL Test", img_url="") |
| 59 | + |
| 60 | + assert isinstance(result, Html) |
| 61 | + assert "Invalid URL Test" in result.text |
| 62 | + assert 'src=""' in result.text |
| 63 | + |
| 64 | + |
| 65 | +def test_img_header_no_border(): |
| 66 | + result = img_header( |
| 67 | + label="No Border Test", |
| 68 | + img_url="https://example.com/no_border.png", |
| 69 | + border_color="transparent", |
| 70 | + ) |
| 71 | + |
| 72 | + assert isinstance(result, Html) |
| 73 | + assert "No Border Test" in result.text |
| 74 | + assert "border-bottom:2px solid transparent;" in result.text |
0 commit comments