46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
import unittest
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
# Add scripts directory to path
|
|
script_dir = Path(__file__).resolve().parent.parent / "scripts"
|
|
sys.path.insert(0, str(script_dir))
|
|
|
|
from publish_website import validate_html, resolve_hosting_script
|
|
|
|
class TestPublishWebsite(unittest.TestCase):
|
|
def test_validate_html_valid(self):
|
|
valid_html = """
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
<script src="https://unpkg.com/lucide@latest"></script>
|
|
</head>
|
|
<body>
|
|
<i data-lucide="sparkles"></i>
|
|
<script>lucide.createIcons();</script>
|
|
</body>
|
|
</html>
|
|
"""
|
|
warnings = validate_html(valid_html)
|
|
self.assertEqual(warnings, [])
|
|
|
|
def test_validate_html_warnings(self):
|
|
broken_html = "<html><body>Hello</body></html>"
|
|
warnings = validate_html(broken_html)
|
|
self.assertIn("Missing <!DOCTYPE html> declaration.", warnings)
|
|
self.assertIn("Missing responsive viewport meta tag.", warnings)
|
|
self.assertIn("Tailwind CSS CDN not detected in HTML.", warnings)
|
|
self.assertIn("Alpine.js script not detected (interactivity might be missing).", warnings)
|
|
|
|
def test_resolve_hosting_script(self):
|
|
hosting_script = resolve_hosting_script()
|
|
self.assertTrue(hosting_script.exists())
|
|
self.assertEqual(hosting_script.name, "publish_file.py")
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|