forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code_block: Fix null-check
!
errors during hot reloads
On hot-reload, `lerp` is triggered even when the theme has not changed. Discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Exceptions.20during.20hot.20reloads/near/1846095 I considered just going ahead with placing the web app's current light-theme styles for code blocks (zulip#754), but pretty soon I realized there would still be some nulls in there after doing so, and those would need to be treated like we're treating the nulls here.
- Loading branch information
1 parent
8a4900e
commit 74de34c
Showing
2 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/widgets/app.dart'; | ||
import 'package:zulip/widgets/code_block.dart'; | ||
import 'package:zulip/widgets/page.dart'; | ||
|
||
import '../model/binding.dart'; | ||
|
||
void main() { | ||
TestZulipBinding.ensureInitialized(); | ||
|
||
group('CodeBlockTextStyles', () { | ||
group('lerp', () { | ||
Future<BuildContext> contextWithZulipTheme(WidgetTester tester) async { | ||
addTearDown(testBinding.reset); | ||
await tester.pumpWidget(const ZulipApp()); | ||
await tester.pump(); | ||
final navigator = await ZulipApp.navigator; | ||
navigator.push(MaterialWidgetRoute(page: Builder( | ||
builder: (context) => const Placeholder()))); | ||
await tester.pumpAndSettle(); | ||
return tester.element(find.byType(Placeholder)); | ||
} | ||
|
||
testWidgets('light -> light', (tester) async { | ||
final context = await contextWithZulipTheme(tester); | ||
final a = CodeBlockTextStyles.light(context); | ||
final b = CodeBlockTextStyles.light(context); | ||
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally(); | ||
}); | ||
|
||
testWidgets('light -> dark', (tester) async { | ||
final context = await contextWithZulipTheme(tester); | ||
final a = CodeBlockTextStyles.light(context); | ||
final b = CodeBlockTextStyles.dark(context); | ||
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally(); | ||
}); | ||
|
||
testWidgets('dark -> light', (tester) async { | ||
final context = await contextWithZulipTheme(tester); | ||
final a = CodeBlockTextStyles.dark(context); | ||
final b = CodeBlockTextStyles.light(context); | ||
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally(); | ||
}); | ||
|
||
testWidgets('dark -> dark', (tester) async { | ||
final context = await contextWithZulipTheme(tester); | ||
final a = CodeBlockTextStyles.dark(context); | ||
final b = CodeBlockTextStyles.dark(context); | ||
check(() => CodeBlockTextStyles.lerp(a, b, 0.5)).returnsNormally(); | ||
}); | ||
}); | ||
}); | ||
} |