Files
cutdex/test/palette_theme_test.dart
T
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

113 lines
3.9 KiB
Dart

import 'dart:math' as math;
import 'package:cutdex/app/editor_theme.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_timeline_ui/cutdex_timeline_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
for (final palette in AppPalette.values) {
for (final brightness in Brightness.values) {
test(
'${palette.name} ${brightness.name} shares semantic colors and readable text',
() {
final theme = EditorTheme.forPalette(palette, brightness);
final colors = theme.colorScheme;
final tokens = AppColors.of(theme);
expect(theme.brightness, brightness);
expect(tokens.family, palette);
final settings = AppTheme.settingsContentTheme(theme);
final dialog = AppTheme.dialogContentTheme(theme);
final inspector = AppTheme.propertiesPanelTheme(theme);
final actions = AppTheme.dialogActionTheme(theme);
final timeline = theme.extension<TimelineThemeData>()!;
expect(
settings.switchTheme.trackColor!.resolve({WidgetState.selected}),
colors.primary,
);
expect(
(dialog.inputDecorationTheme.focusedBorder as OutlineInputBorder)
.borderSide
.color,
colors.primary,
);
expect(timeline.selectionOutlineColor, colors.primary);
expect(
(inspector.inputDecorationTheme.focusedBorder as OutlineInputBorder)
.borderSide
.color,
colors.primary,
);
for (final style in [
theme.filledButtonTheme.style!,
settings.filledButtonTheme.style!,
actions.filledButtonTheme.style!,
]) {
final background = style.backgroundColor!.resolve({})!;
final foreground = style.foregroundColor!.resolve({})!;
expect(background, colors.primary);
expect(
_contrast(foreground, background),
greaterThanOrEqualTo(4.5),
);
}
expect(timeline.backgroundColor, colors.surface);
expect(settings.colorScheme.surfaceContainer, tokens.card);
expect(settings.inputDecorationTheme.fillColor, tokens.card);
expect(inspector.inputDecorationTheme.fillColor, tokens.card);
expect(AppColors.of(settings), tokens);
expect(
theme.extension<AppSurfaces>()!.previewBackground,
Colors.black,
);
for (final surface in [
colors.surface,
colors.surfaceContainerLow,
colors.surfaceContainer,
timeline.visualClipColor,
timeline.audioClipColor,
]) {
expect(
_contrast(colors.onSurface, surface),
greaterThanOrEqualTo(4.5),
);
}
for (final surface in [
colors.surface,
colors.surfaceContainerLow,
colors.surfaceContainer,
]) {
expect(
_contrast(colors.onSurfaceVariant, surface),
greaterThanOrEqualTo(4.5),
);
}
expect(
_contrast(colors.onPrimary, colors.primary),
greaterThanOrEqualTo(4.5),
);
},
);
}
}
test('six theme combinations have distinct workspace colors', () {
final signatures = {
for (final palette in AppPalette.values)
for (final brightness in Brightness.values)
(
EditorTheme.forPalette(palette, brightness).colorScheme.surface,
EditorTheme.forPalette(palette, brightness).colorScheme.primary,
),
};
expect(signatures.length, 6);
});
}
double _contrast(Color a, Color b) {
final first = a.computeLuminance();
final second = b.computeLuminance();
return (math.max(first, second) + .05) / (math.min(first, second) + .05);
}