themeRoleAppTest function
The test of the theme role that the CLI keeps in its
app_tests/theme_role, for the apps with the role, whichever module
provides it, that among accepts, or all of them. Once the app started
with main(), it follows the device; a choice of a mode with
appThemeMode.choose() reaches the root MaterialApp, which takes the
mode, and the screen below it gets the light theme of the provider in
the light mode and its dark theme in the dark mode, the same colour
schemes that createLightTheme() and createDarkTheme() return for the
context of the root. A choice is saved under the key of the role, as
the name of the mode, and the next start, initPreferences() again,
has the mode whose name the test wrote under that key.
It is a test of the app entry role too. The root gets the mode from an inherited widget around it, which its arguments read from its context, so the test fails on a provider of the app entry whose root does not rebuild when that widget notifies.
The test knows only the roles. The matrix fills in the key, which the
role publishes (ThemeRole.modeKey). It has no probe for the start
check: on a device the mode is the same Dart state as in a test, and the
platform side of the preferences, which does differ there, has the
probes of the preferences role and of its provider. The matrix of the
fixtures runs the test only in its apps with every module, which run
other tests already.
Implementation
Future<MatrixAppTest> themeRoleAppTest({
bool Function(MatrixApp app)? among,
}) async =>
MatrixAppTest(
'${await appTestsDirectoryOf('smf_flutter_cli')}/theme_role',
appliesTo: (app) =>
app.hook!.presentRoles.contains(themeRole) &&
(among?.call(app) ?? true),
values: _themeValuesOf,
roles: {themeRole, appEntryRole},
);