Skip to content

Commit

Permalink
[Parent] Add refresh buttons to course shell (#808)
Browse files Browse the repository at this point in the history
* [Parent] Add refresh buttons to course shell

* remove accidental return

* add refresh test

* updated interactor call

* cure unwell test
  • Loading branch information
TrevorNeedham authored May 14, 2020
1 parent e94dc81 commit e83628d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'package:flutter_parent/utils/service_locator.dart';

class CourseRoutingShellInteractor {
Future<CourseShellData> loadCourseShell(CourseShellType type, String courseId, {bool forceRefresh = false}) async {
var course = await _loadCourse(courseId);
var course = await _loadCourse(courseId, forceRefresh: forceRefresh);
CanvasPage frontPage = null;

if (type == CourseShellType.frontPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import 'package:flutter_parent/l10n/app_localizations.dart';
import 'package:flutter_parent/screens/courses/routing_shell/course_routing_shell_interactor.dart';
import 'package:flutter_parent/utils/common_widgets/error_panda_widget.dart';
import 'package:flutter_parent/utils/common_widgets/loading_indicator.dart';
import 'package:flutter_parent/utils/common_widgets/web_view/canvas_html.dart';
import 'package:flutter_parent/utils/common_widgets/web_view/canvas_web_view.dart';
import 'package:flutter_parent/utils/design/canvas_icons.dart';
import 'package:flutter_parent/utils/design/parent_theme.dart';
import 'package:flutter_parent/utils/service_locator.dart';

Expand Down Expand Up @@ -74,6 +75,15 @@ class _CourseRoutingShellScreenState extends State<CourseRoutingShellScreen> {
Widget _scaffold(CourseShellType type, CourseShellData data) {
return Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(
tooltip: L10n(context).refresh,
icon: Icon(CanvasIcons.refresh),
onPressed: () async {
_refresh();
},
),
],
title: _appBarTitle(
(widget.type == CourseShellType.frontPage)
? L10n(context).courseFrontPageLabel.toUpperCase()
Expand All @@ -85,14 +95,20 @@ class _CourseRoutingShellScreenState extends State<CourseRoutingShellScreen> {
}

Widget _body(CourseShellData data) {
return RefreshIndicator(
onRefresh: () {
return _refresh();
},
child: widget.type == CourseShellType.frontPage
? CanvasHtml(data.frontPage.body,
emptyDescription: data.frontPage.lockExplanation ?? L10n(context).noPageFound)
: CanvasHtml(data.course.syllabusBody));
return widget.type == CourseShellType.frontPage
? _webView(data.frontPage.body, emptyDescription: data.frontPage.lockExplanation ?? L10n(context).noPageFound)
: _webView(data.course.syllabusBody);
}

Widget _webView(String html, {String emptyDescription}) {
return Padding(
padding: const EdgeInsets.only(top: 16.0),
child: CanvasWebView(
content: html,
emptyDescription: emptyDescription,
horizontalPadding: 16,
fullScreen: true,
));
}

Widget _appBarTitle(String title, String subtitle) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'package:flutter_parent/models/course.dart';
import 'package:flutter_parent/screens/courses/routing_shell/course_routing_shell_interactor.dart';
import 'package:flutter_parent/screens/courses/routing_shell/course_routing_shell_screen.dart';
import 'package:flutter_parent/utils/common_widgets/loading_indicator.dart';
import 'package:flutter_parent/utils/common_widgets/web_view/canvas_html.dart';
import 'package:flutter_parent/utils/common_widgets/web_view/canvas_web_view.dart';
import 'package:flutter_parent/utils/common_widgets/web_view/web_content_interactor.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
Expand Down Expand Up @@ -66,7 +66,7 @@ void main() {

expect(find.text(AppLocalizations().courseSyllabusLabel.toUpperCase()), findsOneWidget);
expect(find.text(course.name), findsOneWidget);
expect(find.byType(CanvasHtml), findsOneWidget);
expect(find.byType(CanvasWebView), findsOneWidget);
});

testWidgetsWithAccessibilityChecks('frontPage type loads frontPage', (tester) async {
Expand All @@ -79,7 +79,7 @@ void main() {

expect(find.text(AppLocalizations().courseFrontPageLabel.toUpperCase()), findsOneWidget);
expect(find.text(course.name), findsOneWidget);
expect(find.byType(CanvasHtml), findsOneWidget);
expect(find.byType(CanvasWebView), findsOneWidget);
});

testWidgetsWithAccessibilityChecks('loading state displays loading indicator', (tester) async {
Expand Down Expand Up @@ -111,4 +111,28 @@ void main() {

verify(interactor.loadCourseShell(any, any)).called(2); // Once for initial load, another for the refresh
});

testWidgetsWithAccessibilityChecks('Refresh displays loading indicator and loads state', (tester) async {
final result = CourseShellData(course);
when(interactor.loadCourseShell(CourseShellType.syllabus, any, forceRefresh: anyNamed('forceRefresh')))
.thenAnswer((_) => Future.value(result));

await tester.pumpWidget(TestApp(CourseRoutingShellScreen(course.id, CourseShellType.syllabus),
platformConfig: PlatformConfig(initWebview: true)));
await tester.pumpAndSettle();

await tester.tap(find.byType(IconButton));
await tester.pump();

expect(find.byType(LoadingIndicator), findsOneWidget);

await tester.pumpAndSettle();

verify(interactor.loadCourseShell(any, any, forceRefresh: true)).called(1);
expect(find.text(AppLocalizations().courseSyllabusLabel.toUpperCase()), findsOneWidget);
expect(find.text(course.name), findsOneWidget);
expect(find.byType(CanvasWebView), findsOneWidget);
expect(find.text(AppLocalizations().unexpectedError), findsNothing);
expect(find.byType(LoadingIndicator), findsNothing);
});
}

This file was deleted.

0 comments on commit e83628d

Please sign in to comment.