// Tests for per-tool settings memory (F1/F5/F11). import 'package:flutter_test/flutter_test.dart'; import 'package:badnote/editor/input/tool_settings.dart'; void main() { test('defaults: pen active, per-tool colors/widths', () { final s = ToolSettings.defaults(); expect(s.active, EditorToolType.pen); expect(s.configFor(EditorToolType.pen).color, 0xFF000000); expect(s.configFor(EditorToolType.highlighter).width, 0.02); expect(s.activeConfig, s.configFor(EditorToolType.pen)); }); test('switching tools remembers each tool\'s own config', () { var s = ToolSettings.defaults(); // Customize pen, switch to highlighter, customize it, switch back. s = s.withColor(0xFFFF0000).withWidth(0.005); // pen → red, 0.005 s = s.withActive(EditorToolType.highlighter); expect(s.activeConfig.color, 0x80FFEB3B); // highlighter unchanged s = s.withColor(0x8000FF00); // highlighter → green s = s.withActive(EditorToolType.pen); // Pen restored to its red/0.005, NOT the highlighter's green. expect(s.activeConfig.color, 0xFFFF0000); expect(s.activeConfig.width, 0.005); // Highlighter kept its green. expect(s.configFor(EditorToolType.highlighter).color, 0x8000FF00); }); test('withColor/withWidth only touch the active tool', () { var s = ToolSettings.defaults().withActive(EditorToolType.highlighter); final penBefore = s.configFor(EditorToolType.pen); s = s.withColor(0x80123456); expect(s.configFor(EditorToolType.pen), penBefore); // pen untouched expect(s.activeConfig.color, 0x80123456); }); test('immutability: updates return new instances, original unchanged', () { final a = ToolSettings.defaults(); final b = a.withActive(EditorToolType.eraser); expect(a.active, EditorToolType.pen); expect(b.active, EditorToolType.eraser); expect(a == b, isFalse); }); test('value equality', () { expect(ToolSettings.defaults(), ToolSettings.defaults()); expect(ToolSettings.defaults().withActive(EditorToolType.eraser) == ToolSettings.defaults(), isFalse); }); test('ToolConfig copyWith + equality', () { const c = ToolConfig(color: 0xFF000000, width: 0.003); expect(c.copyWith(width: 0.01), const ToolConfig(color: 0xFF000000, width: 0.01)); expect(c.copyWith(), c); }); }