Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
AI-powered UI styling skill with 67 UI styles and 161 reasoning rules for professional interface design.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/tests/test_tailwind_config_gen.py
1"""Tests for tailwind_config_gen.py"""23from pathlib import Path45import pytest67# Add parent directory to path for imports8import sys9sys.path.insert(0, str(Path(__file__).parent.parent))1011from tailwind_config_gen import TailwindConfigGenerator121314class TestTailwindConfigGenerator:15"""Test TailwindConfigGenerator class."""1617def test_init_default_typescript(self):18"""Test initialization with default settings."""19generator = TailwindConfigGenerator()20assert generator.typescript is True21assert generator.framework == "react"2223def test_init_javascript(self):24"""Test initialization for JavaScript config."""25generator = TailwindConfigGenerator(typescript=False)26assert generator.typescript is False2728def test_init_framework(self):29"""Test initialization with different frameworks."""30for framework in ["react", "vue", "svelte", "nextjs"]:31generator = TailwindConfigGenerator(framework=framework)32assert generator.framework == framework3334def test_default_output_path_typescript(self):35"""Test default output path for TypeScript."""36generator = TailwindConfigGenerator(typescript=True)37assert generator.output_path.name == "tailwind.config.ts"3839def test_default_output_path_javascript(self):40"""Test default output path for JavaScript."""41generator = TailwindConfigGenerator(typescript=False)42assert generator.output_path.name == "tailwind.config.js"4344def test_custom_output_path(self, tmp_path):45"""Test custom output path."""46custom_path = tmp_path / "custom-config.ts"47generator = TailwindConfigGenerator(output_path=custom_path)48assert generator.output_path == custom_path4950def test_base_config_structure(self):51"""Test base configuration structure."""52generator = TailwindConfigGenerator()53config = generator.config5455assert "darkMode" in config56assert "content" in config57assert "theme" in config58assert "plugins" in config59assert "extend" in config["theme"]6061def test_default_content_paths_react(self):62"""Test default content paths for React."""63generator = TailwindConfigGenerator(framework="react")64paths = generator.config["content"]6566assert any("src/**/*.{js,jsx,ts,tsx}" in p for p in paths)67assert any("index.html" in p for p in paths)6869def test_default_content_paths_nextjs(self):70"""Test default content paths for Next.js."""71generator = TailwindConfigGenerator(framework="nextjs")72paths = generator.config["content"]7374assert any("app/**" in p for p in paths)75assert any("pages/**" in p for p in paths)76assert any("components/**" in p for p in paths)7778def test_default_content_paths_vue(self):79"""Test default content paths for Vue."""80generator = TailwindConfigGenerator(framework="vue")81paths = generator.config["content"]8283assert any("vue" in p for p in paths)8485def test_add_colors(self):86"""Test adding custom colors."""87generator = TailwindConfigGenerator()88colors = {89"brand": "#3b82f6",90"accent": "#8b5cf6"91}92generator.add_colors(colors)9394assert "colors" in generator.config["theme"]["extend"]95assert generator.config["theme"]["extend"]["colors"]["brand"] == "#3b82f6"96assert generator.config["theme"]["extend"]["colors"]["accent"] == "#8b5cf6"9798def test_add_colors_multiple_times(self):99"""Test adding colors multiple times."""100generator = TailwindConfigGenerator()101102generator.add_colors({"brand": "#3b82f6"})103generator.add_colors({"accent": "#8b5cf6"})104105colors = generator.config["theme"]["extend"]["colors"]106assert "brand" in colors107assert "accent" in colors108109def test_add_color_palette(self):110"""Test adding full color palette."""111generator = TailwindConfigGenerator()112generator.add_color_palette("brand", "#3b82f6")113114brand = generator.config["theme"]["extend"]["colors"]["brand"]115116assert isinstance(brand, dict)117assert "50" in brand118assert "500" in brand119assert "950" in brand120assert "var(--color-brand" in brand["500"]121122def test_add_fonts(self):123"""Test adding custom fonts."""124generator = TailwindConfigGenerator()125fonts = {126"sans": ["Inter", "system-ui", "sans-serif"],127"display": ["Playfair Display", "serif"]128}129generator.add_fonts(fonts)130131font_family = generator.config["theme"]["extend"]["fontFamily"]132assert font_family["sans"] == ["Inter", "system-ui", "sans-serif"]133assert font_family["display"] == ["Playfair Display", "serif"]134135def test_add_spacing(self):136"""Test adding custom spacing."""137generator = TailwindConfigGenerator()138spacing = {139"18": "4.5rem",140"navbar": "4rem"141}142generator.add_spacing(spacing)143144spacing_config = generator.config["theme"]["extend"]["spacing"]145assert spacing_config["18"] == "4.5rem"146assert spacing_config["navbar"] == "4rem"147148def test_add_breakpoints(self):149"""Test adding custom breakpoints."""150generator = TailwindConfigGenerator()151breakpoints = {152"3xl": "1920px",153"tablet": "768px"154}155generator.add_breakpoints(breakpoints)156157screens = generator.config["theme"]["extend"]["screens"]158assert screens["3xl"] == "1920px"159assert screens["tablet"] == "768px"160161def test_add_plugins(self):162"""Test adding plugins."""163generator = TailwindConfigGenerator()164plugins = ["@tailwindcss/typography", "@tailwindcss/forms"]165generator.add_plugins(plugins)166167assert "@tailwindcss/typography" in generator.config["plugins"]168assert "@tailwindcss/forms" in generator.config["plugins"]169170def test_add_plugins_no_duplicates(self):171"""Test that adding same plugin twice doesn't duplicate."""172generator = TailwindConfigGenerator()173generator.add_plugins(["@tailwindcss/typography"])174generator.add_plugins(["@tailwindcss/typography"])175176count = generator.config["plugins"].count("@tailwindcss/typography")177assert count == 1178179def test_recommend_plugins(self):180"""Test plugin recommendations."""181generator = TailwindConfigGenerator()182recommendations = generator.recommend_plugins()183184assert isinstance(recommendations, list)185assert "tailwindcss-animate" in recommendations186187def test_recommend_plugins_nextjs(self):188"""Test plugin recommendations for Next.js."""189generator = TailwindConfigGenerator(framework="nextjs")190recommendations = generator.recommend_plugins()191192assert "@tailwindcss/typography" in recommendations193194def test_generate_typescript_config(self):195"""Test generating TypeScript configuration."""196generator = TailwindConfigGenerator(typescript=True)197config = generator.generate_config_string()198199assert "import type { Config } from 'tailwindcss'" in config200assert "const config: Config" in config201assert "export default config" in config202203def test_generate_javascript_config(self):204"""Test generating JavaScript configuration."""205generator = TailwindConfigGenerator(typescript=False)206config = generator.generate_config_string()207208assert "module.exports" in config209assert "@type" in config210211def test_generate_config_with_colors(self):212"""Test generating config with custom colors."""213generator = TailwindConfigGenerator()214generator.add_colors({"brand": "#3b82f6"})215config = generator.generate_config_string()216217assert "colors" in config218assert "brand" in config219220def test_generate_config_with_plugins(self):221"""Test generating config with plugins."""222generator = TailwindConfigGenerator()223generator.add_plugins(["tailwindcss-animate"])224config = generator.generate_config_string()225226assert "plugins:" in config227assert "require('tailwindcss-animate')" in config228229def test_validate_config_valid(self):230"""Test validating valid configuration."""231generator = TailwindConfigGenerator()232valid, message = generator.validate_config()233234assert valid is True235236def test_validate_config_no_content(self):237"""Test validating config with no content paths."""238generator = TailwindConfigGenerator()239generator.config["content"] = []240241valid, message = generator.validate_config()242243assert valid is False244assert "No content paths" in message245246def test_validate_config_empty_theme(self):247"""Test validating config with empty theme extensions."""248generator = TailwindConfigGenerator()249# Default has empty theme.extend250251valid, message = generator.validate_config()252253assert valid is True254assert "Warning" in message255256def test_write_config(self, tmp_path):257"""Test writing configuration to file."""258output_path = tmp_path / "tailwind.config.ts"259generator = TailwindConfigGenerator(output_path=output_path)260261success, message = generator.write_config()262263assert success is True264assert output_path.exists()265assert "written to" in message266267def test_write_config_creates_content(self, tmp_path):268"""Test that written config contains expected content."""269output_path = tmp_path / "tailwind.config.ts"270generator = TailwindConfigGenerator(output_path=output_path)271generator.add_colors({"brand": "#3b82f6"})272273generator.write_config()274275content = output_path.read_text()276assert "import type { Config }" in content277assert "brand" in content278279def test_write_config_invalid_path(self):280"""Test writing config to invalid path."""281generator = TailwindConfigGenerator(output_path=Path("/invalid/path/config.ts"))282283success, message = generator.write_config()284285assert success is False286assert "Failed to write" in message287288def test_full_configuration_typescript(self, tmp_path):289"""Test generating complete TypeScript configuration."""290output_path = tmp_path / "tailwind.config.ts"291generator = TailwindConfigGenerator(292typescript=True,293framework="nextjs",294output_path=output_path295)296297# Add various customizations298generator.add_colors({"brand": "#3b82f6", "accent": "#8b5cf6"})299generator.add_fonts({"sans": ["Inter", "sans-serif"]})300generator.add_spacing({"navbar": "4rem"})301generator.add_breakpoints({"3xl": "1920px"})302generator.add_plugins(["tailwindcss-animate"])303304success, _ = generator.write_config()305assert success is True306307content = output_path.read_text()308309# Verify all customizations are present310assert "brand" in content311assert "accent" in content312assert "Inter" in content313assert "navbar" in content314assert "3xl" in content315assert "tailwindcss-animate" in content316317def test_full_configuration_javascript(self, tmp_path):318"""Test generating complete JavaScript configuration."""319output_path = tmp_path / "tailwind.config.js"320generator = TailwindConfigGenerator(321typescript=False,322framework="react",323output_path=output_path324)325326generator.add_colors({"primary": "#3b82f6"})327generator.add_plugins(["@tailwindcss/forms"])328329success, _ = generator.write_config()330assert success is True331332content = output_path.read_text()333334assert "module.exports" in content335assert "primary" in content336assert "@tailwindcss/forms" in content337