|
| 1 | +import 'package:stardust/src/config/config.dart'; |
| 2 | +import 'package:stardust/src/generator/builders/page_styles_builder.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group('PageStylesBuilder', () { |
| 7 | + group('custom CSS', () { |
| 8 | + test('includes custom CSS when configured', () { |
| 9 | + const config = StardustConfig( |
| 10 | + name: 'Test', |
| 11 | + theme: ThemeConfig( |
| 12 | + custom: CustomThemeConfig( |
| 13 | + css: '.my-class { color: red; }', |
| 14 | + ), |
| 15 | + ), |
| 16 | + ); |
| 17 | + final builder = PageStylesBuilder(config: config); |
| 18 | + |
| 19 | + final result = builder.buildStyles(); |
| 20 | + |
| 21 | + expect(result, contains('.my-class { color: red; }')); |
| 22 | + expect(result, contains('/* Custom styles */')); |
| 23 | + }); |
| 24 | + |
| 25 | + test('does not include custom styles section when not configured', () { |
| 26 | + const config = StardustConfig(name: 'Test'); |
| 27 | + final builder = PageStylesBuilder(config: config); |
| 28 | + |
| 29 | + final result = builder.buildStyles(); |
| 30 | + |
| 31 | + expect(result, isNot(contains('/* Custom styles */'))); |
| 32 | + }); |
| 33 | + |
| 34 | + test('does not include custom styles section when css is empty', () { |
| 35 | + const config = StardustConfig( |
| 36 | + name: 'Test', |
| 37 | + theme: ThemeConfig( |
| 38 | + custom: CustomThemeConfig(css: ''), |
| 39 | + ), |
| 40 | + ); |
| 41 | + final builder = PageStylesBuilder(config: config); |
| 42 | + |
| 43 | + final result = builder.buildStyles(); |
| 44 | + |
| 45 | + expect(result, isNot(contains('/* Custom styles */'))); |
| 46 | + }); |
| 47 | + |
| 48 | + test('custom CSS appears after responsive styles', () { |
| 49 | + const config = StardustConfig( |
| 50 | + name: 'Test', |
| 51 | + theme: ThemeConfig( |
| 52 | + custom: CustomThemeConfig( |
| 53 | + css: '.custom { display: flex; }', |
| 54 | + ), |
| 55 | + ), |
| 56 | + ); |
| 57 | + final builder = PageStylesBuilder(config: config); |
| 58 | + |
| 59 | + final result = builder.buildStyles(); |
| 60 | + |
| 61 | + final responsiveIndex = result.indexOf('@media (max-width: 768px)'); |
| 62 | + final customIndex = result.indexOf('.custom { display: flex; }'); |
| 63 | + expect(customIndex, greaterThan(responsiveIndex)); |
| 64 | + }); |
| 65 | + |
| 66 | + test('includes CSS from resolved file content', () { |
| 67 | + const config = StardustConfig( |
| 68 | + name: 'Test', |
| 69 | + theme: ThemeConfig( |
| 70 | + custom: CustomThemeConfig(cssFile: 'custom.css'), |
| 71 | + ), |
| 72 | + ); |
| 73 | + final builder = PageStylesBuilder(config: config); |
| 74 | + builder.resolvedCssFileContent = '.from-file { color: blue; }'; |
| 75 | + |
| 76 | + final result = builder.buildStyles(); |
| 77 | + |
| 78 | + expect(result, contains('.from-file { color: blue; }')); |
| 79 | + expect(result, contains('/* Custom styles */')); |
| 80 | + }); |
| 81 | + |
| 82 | + test('combines resolved file content and inline css', () { |
| 83 | + const config = StardustConfig( |
| 84 | + name: 'Test', |
| 85 | + theme: ThemeConfig( |
| 86 | + custom: CustomThemeConfig( |
| 87 | + cssFile: 'custom.css', |
| 88 | + css: '.inline { color: red; }', |
| 89 | + ), |
| 90 | + ), |
| 91 | + ); |
| 92 | + final builder = PageStylesBuilder(config: config); |
| 93 | + builder.resolvedCssFileContent = '.from-file { color: blue; }'; |
| 94 | + |
| 95 | + final result = builder.buildStyles(); |
| 96 | + |
| 97 | + expect(result, contains('.from-file { color: blue; }')); |
| 98 | + expect(result, contains('.inline { color: red; }')); |
| 99 | + }); |
| 100 | + |
| 101 | + test('no custom styles when cssFile set but content not resolved', () { |
| 102 | + const config = StardustConfig( |
| 103 | + name: 'Test', |
| 104 | + theme: ThemeConfig( |
| 105 | + custom: CustomThemeConfig(cssFile: '/nonexistent/style.css'), |
| 106 | + ), |
| 107 | + ); |
| 108 | + final builder = PageStylesBuilder(config: config); |
| 109 | + |
| 110 | + final result = builder.buildStyles(); |
| 111 | + |
| 112 | + expect(result, isNot(contains('/* Custom styles */'))); |
| 113 | + }); |
| 114 | + |
| 115 | + test('supports CSS variable overrides', () { |
| 116 | + const config = StardustConfig( |
| 117 | + name: 'Test', |
| 118 | + theme: ThemeConfig( |
| 119 | + custom: CustomThemeConfig( |
| 120 | + css: ':root { --color-primary: #ff0000; }', |
| 121 | + ), |
| 122 | + ), |
| 123 | + ); |
| 124 | + final builder = PageStylesBuilder(config: config); |
| 125 | + |
| 126 | + final result = builder.buildStyles(); |
| 127 | + |
| 128 | + expect(result, contains('--color-primary: #ff0000')); |
| 129 | + }); |
| 130 | + }); |
| 131 | + }); |
| 132 | +} |
0 commit comments