Skip to content

Commit

Permalink
Merge branch 'main' into feat/purge-volatile-data-after-roll-forward
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku authored Dec 23, 2024
2 parents 762f6a3 + af34b4b commit e791fc3
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 35 deletions.
129 changes: 104 additions & 25 deletions catalyst_voices/apps/voices/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,119 @@ import 'package:go_router/go_router.dart';
import 'package:integration_test/integration_test.dart';
import 'package:patrol_finders/patrol_finders.dart';

import 'pageobject/dashboard_page.dart';
import 'pageobject/app_bar_page.dart';
import 'pageobject/overall_spaces_page.dart';
import 'pageobject/spaces_drawer_page.dart';
import 'utils/selector_utils.dart';

void main() async {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
late final GoRouter router;

setUpAll(() async {
router = buildAppRouter(initialLocation: const DiscoveryRoute().location);

router = buildAppRouter();
await bootstrap(router: router);
});

patrolWidgetTest('Spaces drawer guest menu renders correctly',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(DashboardPage.guestShortcutBtn).tap();
await $.pumpAndSettle();
await Future<void>.delayed(const Duration(seconds: 5));
await $(DashboardPage.spacesDrawerButton).waitUntilVisible().tap();
SpacesDrawerPage.looksAsExpected($);

//iterate thru spaces and check menu buttons are there
for (final space in Space.values) {
await $(SpacesDrawerPage.chooserItem(space)).tap();
expect(
$(SpacesDrawerPage.chooserIcon(space)),
findsOneWidget,
);
final children = find.descendant(
of: $(SpacesDrawerPage.guestMenuItems),
matching: find.byWidgetPredicate((widget) => true),
);
expect($(children), findsAtLeast(1));
}
setUp(() async {
await registerDependencies();
router.go(const DiscoveryRoute().location);
});

tearDown(() async {
await restartDependencies();
});

patrolWidgetTest(
'Spaces drawer - visitor - no drawer button',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.visitorShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
expect($(AppBarPage.spacesDrawerButton).exists, false);
},
);

patrolWidgetTest(
'Spaces drawer - guest - chooser - clicking on icons works correctly',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.guestShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
await $(AppBarPage.spacesDrawerButton).waitUntilVisible().tap();
SpacesDrawerPage.commonElementsLookAsExpected($);

// iterate thru spaces by clicking on spaces icons directly
for (final space in Space.values) {
await $(SpacesDrawerPage.chooserItem(space)).tap();
await SpacesDrawerPage.guestLooksAsExpected($, space);
}
SelectorUtils.isDisabled($, $(SpacesDrawerPage.chooserNextBtn));
},
);

patrolWidgetTest(
'Spaces drawer - guest - chooser - next,previous buttons work correctly',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.guestShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
await $(AppBarPage.spacesDrawerButton).waitUntilVisible().tap();

// iterate thru spaces by clicking next
for (final space in Space.values) {
await SpacesDrawerPage.guestLooksAsExpected($, space);
await $(SpacesDrawerPage.chooserNextBtn).tap();
SelectorUtils.isEnabled($, $(SpacesDrawerPage.chooserPrevBtn));
}
SelectorUtils.isDisabled($, $(SpacesDrawerPage.chooserNextBtn));

// iterate thru spaces by clicking previous
for (final space in Space.values.reversed) {
await SpacesDrawerPage.guestLooksAsExpected($, space);
await $(SpacesDrawerPage.chooserPrevBtn).tap();
SelectorUtils.isEnabled($, $(SpacesDrawerPage.chooserNextBtn));
}
SelectorUtils.isDisabled($, $(SpacesDrawerPage.chooserPrevBtn));
},
);

patrolWidgetTest(
'Spaces drawer - user - chooser - clicking on icons works correctly',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.userShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
await $(AppBarPage.spacesDrawerButton).waitUntilVisible().tap();
SpacesDrawerPage.commonElementsLookAsExpected($);
for (final space in Space.values) {
await $(SpacesDrawerPage.chooserItem(space)).tap();
await SpacesDrawerPage.userLooksAsExpected($, space);
}
},
);

patrolWidgetTest(
'Spaces drawer - guest - chooser - all spaces button works',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.guestShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
await $(AppBarPage.spacesDrawerButton).waitUntilVisible().tap();
await $(SpacesDrawerPage.allSpacesBtn).tap();
expect($(OverallSpacesPage.spacesListView), findsOneWidget);
},
);

patrolWidgetTest(
'Spaces drawer - user - chooser - all spaces button works',
(PatrolTester $) async {
await $.pumpWidgetAndSettle(App(routerConfig: router));
await $(OverallSpacesPage.userShortcutBtn)
.tap(settleTimeout: const Duration(seconds: 10));
await $(AppBarPage.spacesDrawerButton).waitUntilVisible().tap();
await $(SpacesDrawerPage.allSpacesBtn).tap();
expect($(OverallSpacesPage.spacesListView), findsOneWidget);
},
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ library dashboard_page;

import 'package:flutter/material.dart';

class DashboardPage {
static const guestShortcutBtn = Key('GuestShortcut');
class AppBarPage {
static const spacesDrawerButton = Key('DrawerButton');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library dashboard_page;

import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';

class OverallSpacesPage {
static const guestShortcutBtn = Key('GuestShortcut');
static const visitorShortcutBtn = Key('VisitorShortcut');
static const userShortcutBtn = Key('UserShortcut');
static const spacesListView = Key('SpacesListView');

static Key spaceOverview(Space space) {
return Key('SpaceOverview.${space.name}');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,148 @@ class SpacesDrawerPage {
static const chooserPrevBtn = Key('DrawerChooserPreviousButton');
static const chooserNextBtn = Key('DrawerChooserNextButton');
static const chooserItemContainer = Key('DrawerChooserItem');
static const userDiscoveryDashboardTile = Key('DiscoveryDashboardTile');
static const userRolesTile = Key('RolesTile');
static const userFeedbackTile = Key('FeedbackTile');
static const userDocumentationTile = Key('DocumentationTile');
static const userDrawerMenuItem = Key('UserDrawerMenuItem');

static Key chooserItem(Space space) {
return Key('DrawerChooser$space');
}

static Key userHeader(Space space) {
return Key('SpaceHeader.${space.name}');
}

static Key chooserIcon(Space space) {
return Key('DrawerChooser${space}AvatarKey');
}

static void looksAsExpected(PatrolTester $) {
static Key userMenuContainer(Space space) {
return Key('Drawer${space}MenuKey');
}

static Key userSectionHeader(Space space) {
return Key('Header.${space.name}');
}

static void commonElementsLookAsExpected(PatrolTester $) {
expect($(closeBtn), findsOneWidget);
expect($(allSpacesBtn), findsOneWidget);
expect($(chooserPrevBtn), findsOneWidget);
expect($(chooserNextBtn), findsOneWidget);
expect($(chooserItemContainer), findsExactly(5));
}

static Future<void> guestLooksAsExpected(PatrolTester $, Space space) async {
expect(
$(SpacesDrawerPage.chooserIcon(space)),
findsOneWidget,
);
final children = find.descendant(
of: $(guestMenuItems),
matching: find.byWidgetPredicate((widget) => true),
);
expect($(children), findsAtLeast(1));
}

static Future<void> userLooksAsExpected(PatrolTester $, Space space) async {
switch (space) {
case Space.discovery:
userDiscoveryLooksAsExpected($);
break;
case Space.workspace:
userWorkspaceLooksAsExpected($);
break;
case Space.voting:
userVotingLooksAsExpected($);
break;
case Space.fundedProjects:
userFundedProjectsLooksAsExpected($);
break;
case Space.treasury:
userTreasuryLooksAsExpected($);
break;
}
}

static void userDiscoveryLooksAsExpected(PatrolTester $) {
expect(
$(userMenuContainer(Space.discovery)).$(userHeader(Space.discovery)),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.discovery)).$(userDiscoveryDashboardTile),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.discovery)).$(userRolesTile),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.discovery)).$(userFeedbackTile),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.discovery)).$(userDocumentationTile),
findsOneWidget,
);
}

static void userWorkspaceLooksAsExpected(PatrolTester $) {
expect(
$(userMenuContainer(Space.workspace)).$(userHeader(Space.workspace)),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.workspace))
.$(userSectionHeader(Space.workspace)),
findsOneWidget,
);
final children = find.descendant(
of: $(userMenuContainer(Space.workspace)),
matching: $(userDrawerMenuItem),
);
expect($(children), findsAtLeast(1));
}

static void userVotingLooksAsExpected(PatrolTester $) {
expect(
$(userMenuContainer(Space.voting)).$(userHeader(Space.voting)),
findsOneWidget,
);
expect(
$(chooserIcon(Space.discovery)),
$(userMenuContainer(Space.voting)).$(userSectionHeader(Space.voting)),
findsOneWidget,
);
final children = find.descendant(
of: $(userMenuContainer(Space.voting)),
matching: $(userDrawerMenuItem),
);
expect($(children), findsAtLeast(1));
}

static void userFundedProjectsLooksAsExpected(PatrolTester $) {
expect(
$(userMenuContainer(Space.fundedProjects)),
findsOneWidget,
);
}

static void userTreasuryLooksAsExpected(PatrolTester $) {
expect(
$(userMenuContainer(Space.treasury)).$(userHeader(Space.treasury)),
findsOneWidget,
);
expect(
$(userMenuContainer(Space.treasury)).$(userSectionHeader(Space.treasury)),
findsOneWidget,
);
final children = find.descendant(
of: $(userMenuContainer(Space.treasury)),
matching: $(userDrawerMenuItem),
);
expect($(children), findsAtLeast(1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol_finders/patrol_finders.dart';

class SelectorUtils {
static void isDisabled(
PatrolTester $,
PatrolFinder widget, {
bool? reverse = false,
}) {
final widgetProps = $.tester.widget(widget).toString().split('(').last;
final expectedState = reverse! ? 'enabled' : 'disabled';
expect(
widgetProps.contains('disabled'),
!reverse,
reason: 'Expected $expectedState (${widget.description})',
);
}

static void isEnabled(PatrolTester $, PatrolFinder widget) {
isDisabled($, widget, reverse: true);
}
}
15 changes: 14 additions & 1 deletion catalyst_voices/apps/voices/lib/configs/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Future<void> _doBootstrapAndRun(BootstrapWidgetBuilder builder) async {
await _runApp(app);
}

@visibleForTesting
GoRouter buildAppRouter({
String? initialLocation,
}) {
Expand All @@ -85,6 +86,18 @@ GoRouter buildAppRouter({
);
}

@visibleForTesting
Future<void> registerDependencies() async {
if (!Dependencies.instance.isInitialized) {
await Dependencies.instance.init();
}
}

@visibleForTesting
Future<void> restartDependencies() async {
await Dependencies.instance.reset;
}

/// Initializes the application before it can be run. Should setup all
/// the things which are necessary before the actual app is run,
/// either via [runApp] or injected into a test environment during
Expand All @@ -102,7 +115,7 @@ Future<BootstrapArgs> bootstrap({
GoRouter.optionURLReflectsImperativeAPIs = true;
setPathUrlStrategy();

await Dependencies.instance.init();
await registerDependencies();

// Key derivation needs to be initialized before it can be used
await CatalystKeyDerivation.init();
Expand Down
Loading

0 comments on commit e791fc3

Please sign in to comment.