-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add term settings page golden tests. (#1710)
- Loading branch information
1 parent
91e27b4
commit c764a7a
Showing
42 changed files
with
675 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+17.8 KB
...es/pages/term_settings_page/goldens/terms_settings_page_error_dark.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.9 KB
...rades/pages/term_settings_page/goldens/terms_settings_page_error_dark.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.3 KB
...s/term_settings_page/goldens/terms_settings_page_error_dark.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.4 KB
.../term_settings_page/goldens/terms_settings_page_error_dark.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+23.3 KB
...s/term_settings_page/goldens/terms_settings_page_error_dark.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+16.7 KB
...s/pages/term_settings_page/goldens/terms_settings_page_error_light.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.6 KB
...ades/pages/term_settings_page/goldens/terms_settings_page_error_light.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15 KB
.../term_settings_page/goldens/terms_settings_page_error_light.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.3 KB
...term_settings_page/goldens/terms_settings_page_error_light.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+22.2 KB
.../term_settings_page/goldens/terms_settings_page_error_light.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.82 KB
.../pages/term_settings_page/goldens/terms_settings_page_loading_dark.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.82 KB
...des/pages/term_settings_page/goldens/terms_settings_page_loading_dark.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.63 KB
...term_settings_page/goldens/terms_settings_page_loading_dark.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.8 KB
...erm_settings_page/goldens/terms_settings_page_loading_dark.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.9 KB
...term_settings_page/goldens/terms_settings_page_loading_dark.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+7.34 KB
...pages/term_settings_page/goldens/terms_settings_page_loading_light.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.49 KB
...es/pages/term_settings_page/goldens/terms_settings_page_loading_light.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.28 KB
...erm_settings_page/goldens/terms_settings_page_loading_light.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.5 KB
...rm_settings_page/goldens/terms_settings_page_loading_light.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.5 KB
...erm_settings_page/goldens/terms_settings_page_loading_light.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+78 KB
...es/term_settings_page/goldens/terms_settings_page_with_data_2_dark.iphone11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+59.9 KB
...pages/term_settings_page/goldens/terms_settings_page_with_data_2_dark.phone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.1 KB
..._settings_page/goldens/terms_settings_page_with_data_2_dark.phone_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+115 KB
...settings_page/goldens/terms_settings_page_with_data_2_dark.tablet_landscape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+115 KB
..._settings_page/goldens/terms_settings_page_with_data_2_dark.tablet_portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+73.5 KB
...s/term_settings_page/goldens/terms_settings_page_with_data_2_light.iphone11.png
Oops, something went wrong.
Binary file added
BIN
+56.4 KB
...ages/term_settings_page/goldens/terms_settings_page_with_data_2_light.phone.png
Oops, something went wrong.
Binary file added
BIN
+39.3 KB
...settings_page/goldens/terms_settings_page_with_data_2_light.phone_landscape.png
Oops, something went wrong.
Binary file added
BIN
+110 KB
...ettings_page/goldens/terms_settings_page_with_data_2_light.tablet_landscape.png
Oops, something went wrong.
Binary file added
BIN
+109 KB
...settings_page/goldens/terms_settings_page_with_data_2_light.tablet_portrait.png
Oops, something went wrong.
Binary file added
BIN
+77.3 KB
...s/pages/term_settings_page/goldens/terms_settings_with_data_1_dark.iphone11.png
Oops, something went wrong.
Binary file added
BIN
+59.2 KB
...ades/pages/term_settings_page/goldens/terms_settings_with_data_1_dark.phone.png
Oops, something went wrong.
Binary file added
BIN
+40.9 KB
.../term_settings_page/goldens/terms_settings_with_data_1_dark.phone_landscape.png
Oops, something went wrong.
Binary file added
BIN
+113 KB
...term_settings_page/goldens/terms_settings_with_data_1_dark.tablet_landscape.png
Oops, something went wrong.
Binary file added
BIN
+114 KB
.../term_settings_page/goldens/terms_settings_with_data_1_dark.tablet_portrait.png
Oops, something went wrong.
Binary file added
BIN
+73.4 KB
.../pages/term_settings_page/goldens/terms_settings_with_data_1_light.iphone11.png
Oops, something went wrong.
Binary file added
BIN
+56.3 KB
...des/pages/term_settings_page/goldens/terms_settings_with_data_1_light.phone.png
Oops, something went wrong.
Binary file added
BIN
+38.8 KB
...term_settings_page/goldens/terms_settings_with_data_1_light.phone_landscape.png
Oops, something went wrong.
Binary file added
BIN
+109 KB
...erm_settings_page/goldens/terms_settings_with_data_1_light.tablet_landscape.png
Oops, something went wrong.
Binary file added
BIN
+108 KB
...term_settings_page/goldens/terms_settings_with_data_1_light.tablet_portrait.png
Oops, something went wrong.
212 changes: 212 additions & 0 deletions
212
app/test_goldens/grades/pages/term_settings_page/term_settings_page_test.dart
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,212 @@ | ||
// Copyright (c) 2024 Sharezone UG (haftungsbeschränkt) | ||
// Licensed under the EUPL-1.2-or-later. | ||
// | ||
// You may obtain a copy of the Licence at: | ||
// https://joinup.ec.europa.eu/software/page/eupl | ||
// | ||
// SPDX-License-Identifier: EUPL-1.2 | ||
|
||
import 'dart:math'; | ||
|
||
import 'package:design/design.dart'; | ||
import 'package:fast_immutable_collections/fast_immutable_collections.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:sharezone/grades/grades_service/grades_service.dart'; | ||
import 'package:sharezone/grades/pages/term_settings_page/term_settings_page.dart'; | ||
import 'package:sharezone/grades/pages/term_settings_page/term_settings_page_controller.dart'; | ||
import 'package:sharezone/grades/pages/term_settings_page/term_settings_page_controller_factory.dart'; | ||
import 'package:sharezone/grades/pages/term_settings_page/term_settings_page_view.dart'; | ||
import 'package:sharezone_widgets/sharezone_widgets.dart'; | ||
|
||
import 'term_settings_page_test.mocks.dart'; | ||
|
||
@GenerateNiceMocks([ | ||
MockSpec<TermSettingsPageController>(), | ||
MockSpec<TermSettingsPageControllerFactory>(), | ||
]) | ||
void main() { | ||
group(TermSettingsPage, () { | ||
const termId = TermId('term-1'); | ||
late TermSettingsPageController controller; | ||
late TermSettingsPageControllerFactory controllerFactory; | ||
|
||
setUp(() { | ||
controller = MockTermSettingsPageController(); | ||
controllerFactory = MockTermSettingsPageControllerFactory(); | ||
when(controllerFactory.create(termId)).thenReturn(controller); | ||
}); | ||
|
||
void setState(TermSettingsState state) { | ||
// Mockito does not support mocking sealed classes yet, so we have to | ||
// provide a dummy implementation of the state. | ||
// | ||
// Ticket: https://github.com/dart-lang/mockito/issues/675 | ||
provideDummy<TermSettingsState>(state); | ||
when(controller.state).thenReturn(state); | ||
} | ||
|
||
void setLoaded2() { | ||
final random = Random(35); | ||
setState( | ||
TermSettingsLoaded( | ||
TermSettingsPageView( | ||
name: '11/23', | ||
isActiveTerm: true, | ||
gradingSystem: GradingSystem.zeroToFifteenPoints, | ||
finalGradeType: GradeType.writtenExam, | ||
selectableGradingTypes: const IListConst([]), | ||
weights: IMapConst({ | ||
GradeType.writtenExam.id: const Weight.factor(2), | ||
GradeType.oralParticipation.id: const Weight.factor(.5), | ||
GradeType.presentation.id: const Weight.factor(1), | ||
}), | ||
subjects: IListConst([ | ||
( | ||
displayName: 'Deutsch', | ||
abbreviation: 'DE', | ||
design: Design.random(random), | ||
id: const SubjectId('d'), | ||
weight: const Weight.factor(1), | ||
), | ||
( | ||
displayName: 'Englisch', | ||
abbreviation: 'E', | ||
design: Design.random(random), | ||
id: const SubjectId('e'), | ||
weight: const Weight.factor(2), | ||
), | ||
]), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void setLoaded1() { | ||
final random = Random(42); | ||
setState( | ||
TermSettingsLoaded( | ||
TermSettingsPageView( | ||
name: '10/22', | ||
isActiveTerm: true, | ||
gradingSystem: GradingSystem.oneToSixWithPlusAndMinus, | ||
finalGradeType: GradeType.schoolReportGrade, | ||
selectableGradingTypes: const IListConst([]), | ||
weights: IMapConst({ | ||
GradeType.writtenExam.id: const Weight.factor(2), | ||
GradeType.oralParticipation.id: const Weight.factor(.5), | ||
GradeType.presentation.id: const Weight.factor(1), | ||
}), | ||
subjects: IListConst([ | ||
( | ||
displayName: 'Deutsch', | ||
abbreviation: 'DE', | ||
design: Design.random(random), | ||
id: const SubjectId('d'), | ||
weight: const Weight.factor(1), | ||
), | ||
( | ||
displayName: 'Englisch', | ||
abbreviation: 'E', | ||
design: Design.random(random), | ||
id: const SubjectId('e'), | ||
weight: const Weight.factor(2), | ||
), | ||
]), | ||
), | ||
), | ||
); | ||
} | ||
|
||
void setError() { | ||
setState(const TermSettingsError('An error occurred.')); | ||
} | ||
|
||
void setLoading() { | ||
setState(const TermSettingsLoading()); | ||
} | ||
|
||
Future<void> pushTermSettingsPage( | ||
WidgetTester tester, ThemeData theme) async { | ||
await tester.pumpWidgetBuilder( | ||
MultiProvider(providers: [ | ||
Provider<GradesService>( | ||
create: (_) => GradesService(), | ||
), | ||
Provider<TermSettingsPageControllerFactory>.value( | ||
value: controllerFactory, | ||
), | ||
ChangeNotifierProvider<TermSettingsPageController>.value( | ||
value: controller, | ||
), | ||
], child: const TermSettingsPage(termId: termId)), | ||
wrapper: materialAppWrapper(theme: theme), | ||
); | ||
} | ||
|
||
group('empty', () { | ||
testGoldens('renders as expected (light mode)', (tester) async { | ||
setLoaded1(); | ||
await pushTermSettingsPage(tester, getLightTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_with_data_1_light'); | ||
}); | ||
|
||
testGoldens('renders as expected (dark mode)', (tester) async { | ||
setLoaded1(); | ||
await pushTermSettingsPage(tester, getDarkTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_with_data_1_dark'); | ||
}); | ||
}); | ||
|
||
group('with data', () { | ||
testGoldens('renders as expected (light mode)', (tester) async { | ||
setLoaded2(); | ||
await pushTermSettingsPage(tester, getLightTheme()); | ||
await multiScreenGolden( | ||
tester, 'terms_settings_page_with_data_2_light'); | ||
}); | ||
|
||
testGoldens('renders as expected (dark mode)', (tester) async { | ||
setLoaded2(); | ||
await pushTermSettingsPage(tester, getDarkTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_page_with_data_2_dark'); | ||
}); | ||
}); | ||
|
||
group('error', () { | ||
testGoldens('renders as expected (light mode)', (tester) async { | ||
setError(); | ||
await pushTermSettingsPage(tester, getLightTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_page_error_light'); | ||
}); | ||
|
||
testGoldens('renders as expected (dark mode)', (tester) async { | ||
setError(); | ||
await pushTermSettingsPage(tester, getDarkTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_page_error_dark'); | ||
}); | ||
}); | ||
|
||
group('loading', () { | ||
testGoldens('renders as expected (light mode)', (tester) async { | ||
setLoading(); | ||
await pushTermSettingsPage(tester, getLightTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_page_loading_light', | ||
customPump: (tester) => | ||
tester.pump(const Duration(milliseconds: 100))); | ||
}); | ||
|
||
testGoldens('renders as expected (dark mode)', (tester) async { | ||
setLoading(); | ||
await pushTermSettingsPage(tester, getDarkTheme()); | ||
await multiScreenGolden(tester, 'terms_settings_page_loading_dark', | ||
customPump: (tester) => | ||
tester.pump(const Duration(milliseconds: 100))); | ||
}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.