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.
ui: Extract ZulipAppBar for loading indicator.
Ideally we may have test to exhaustively ensure that all pages specific to a single PerAccountStore use ZulipAppBar. Some pages with `AppBar`s are skipped, such as AboutZulip (no PerAccountStore access) and lightboxes (progress indicator is occupied for other purposes, and the AppBar can be hidden). Fixes zulip#465. Signed-off-by: Zixuan James Li <[email protected]>
- Loading branch information
Showing
8 changed files
with
92 additions
and
9 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,22 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// A custom [AppBar] with a loading indicator. | ||
/// | ||
/// This should be used for most of the pages with access to [PerAccountStore]. | ||
// However, there are some exceptions (add more if necessary): | ||
// - `lib/widgets/lightbox.dart` | ||
class ZulipAppBar extends AppBar { | ||
ZulipAppBar({ | ||
super.key, | ||
required super.title, | ||
super.backgroundColor, | ||
super.shape, | ||
super.actions, | ||
required bool isLoading, | ||
}) : super( | ||
bottom: PreferredSize( | ||
preferredSize: const Size.fromHeight(4.0), | ||
child: (isLoading) | ||
? LinearProgressIndicator(backgroundColor: backgroundColor, minHeight: 4.0) | ||
: const SizedBox.shrink())); | ||
} |
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
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
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,38 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/widgets/app_bar.dart'; | ||
import 'package:zulip/widgets/profile.dart'; | ||
|
||
import '../example_data.dart' as eg; | ||
import '../model/binding.dart'; | ||
import '../model/test_store.dart'; | ||
import 'test_app.dart'; | ||
|
||
void main() { | ||
TestZulipBinding.ensureInitialized(); | ||
|
||
testWidgets('show progress indicator when loading', (tester) async { | ||
addTearDown(testBinding.reset); | ||
await testBinding.globalStore.add(eg.selfAccount, eg.initialSnapshot()); | ||
|
||
final store = await testBinding.globalStore.perAccount(eg.selfAccount.id); | ||
await store.addUser(eg.selfUser); | ||
|
||
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id, | ||
child: ProfilePage(userId: eg.selfUser.userId))); | ||
|
||
final finder = find.descendant( | ||
of: find.byType(ZulipAppBar), | ||
matching: find.byType(LinearProgressIndicator)); | ||
|
||
await tester.pumpAndSettle(); | ||
final rectBefore = tester.getRect(find.byType(ZulipAppBar)); | ||
check(finder.evaluate()).isEmpty(); | ||
store.isLoading = true; | ||
|
||
await tester.pump(); | ||
check(tester.getRect(find.byType(ZulipAppBar))).equals(rectBefore); | ||
check(finder.evaluate()).single; | ||
}); | ||
} |