|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:flutter_test_goldens/flutter_test_goldens.dart'; |
| 4 | +import 'package:flutter_test_goldens/golden_bricks.dart'; |
| 5 | +import 'package:super_editor/src/chat/super_message.dart'; |
| 6 | +import 'package:super_editor/src/default_editor/default_document_editor.dart'; |
| 7 | +import 'package:super_editor/src/test/flutter_extensions/test_documents.dart'; |
| 8 | +import 'package:super_editor/src/test/super_reader_test/super_reader_robot.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + group("Super Message > styles >", () { |
| 12 | + testGoldenSceneOnIOS("re-renders when styles change", (tester) async { |
| 13 | + final editor = createDefaultDocumentEditor( |
| 14 | + document: singleParagraphDocShortText(), |
| 15 | + ); |
| 16 | + final lightStyles = SuperMessageStyles( |
| 17 | + stylesheet: defaultLightChatStylesheet, |
| 18 | + selectionStyles: defaultLightChatSelectionStyles, |
| 19 | + ); |
| 20 | + final darkStyles = SuperMessageStyles( |
| 21 | + stylesheet: defaultDarkChatStylesheet, |
| 22 | + selectionStyles: defaultDarkChatSelectionStyles, |
| 23 | + ); |
| 24 | + |
| 25 | + final timeline = Timeline( |
| 26 | + "Re-Render on Style Change", |
| 27 | + fileName: 'supermessage_re-render-on-style-change', |
| 28 | + windowSize: const Size(1179, 2556) / 3.0, |
| 29 | + layout: const ColumnSceneLayout(), |
| 30 | + // TODO: Document how to create an item scaffold, including the need for GoldenImageBounds |
| 31 | + itemScaffold: _chatItemScaffold, |
| 32 | + ); |
| 33 | + |
| 34 | + final brightness = ValueNotifier(Brightness.light); |
| 35 | + timeline.setupWithWidget( |
| 36 | + ValueListenableBuilder( |
| 37 | + valueListenable: brightness, |
| 38 | + builder: (context, value, child) { |
| 39 | + return ColoredBox( |
| 40 | + color: switch (value) { |
| 41 | + Brightness.light => Colors.white, |
| 42 | + Brightness.dark => Colors.grey.shade900, |
| 43 | + }, |
| 44 | + child: SuperMessage( |
| 45 | + editor: editor, |
| 46 | + styles: switch (value) { |
| 47 | + Brightness.light => lightStyles, |
| 48 | + Brightness.dark => darkStyles, |
| 49 | + }, |
| 50 | + ), |
| 51 | + ); |
| 52 | + }, |
| 53 | + ), |
| 54 | + ); |
| 55 | + |
| 56 | + await timeline |
| 57 | + .modifyScene((tester, testContext) async { |
| 58 | + await tester.doubleTapInParagraph("1", 24); |
| 59 | + }) |
| 60 | + .takePhoto("Light") |
| 61 | + // Switch to dark. |
| 62 | + .modifyScene((tester, testContext) async { |
| 63 | + brightness.value = Brightness.dark; |
| 64 | + await tester.pump(); |
| 65 | + }) |
| 66 | + .takePhoto("Dark") |
| 67 | + .run(tester); |
| 68 | + }); |
| 69 | + }); |
| 70 | +} |
| 71 | + |
| 72 | +Widget _chatItemScaffold(tester, content) { |
| 73 | + return GoldenSceneBounds( |
| 74 | + child: MaterialApp( |
| 75 | + theme: ThemeData( |
| 76 | + fontFamily: goldenBricks, |
| 77 | + ), |
| 78 | + home: Scaffold( |
| 79 | + body: Center( |
| 80 | + child: GoldenImageBounds( |
| 81 | + child: Padding( |
| 82 | + padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 48), |
| 83 | + child: content, |
| 84 | + ), |
| 85 | + ), |
| 86 | + ), |
| 87 | + ), |
| 88 | + ), |
| 89 | + ); |
| 90 | +} |
0 commit comments