Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

2.9 KB
Raw Blame
@TestOn('browser')
library;

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/core/config.dart';
import 'package:harness/state/app_state.dart';
import 'package:harness/shortcuts/shortcuts_browser.dart';
import 'package:harness/web/parts/terminal_fonts.dart';
import 'package:harness/web/update/web_update_host.dart';
import 'package:harness/web/web_entry.dart';
import 'package:harness/widgets/key_hints.dart';

void main() {
  // The frame stands above the Navigator, as `HarnessApp` places it, so every
  // screen and route of the browser build reads key hints off (audit S8).
  testWidgets('the web frame turns key hints off on every screen', (
    tester,
  ) async {
    final hints = <bool>[];
    final navigator = GlobalKey<NavigatorState>();
    final app = AppNotifier(
      config: AppConfig.dev,
      authSession: AuthSession(),
      configStore: null,
    );
    addTearDown(app.dispose);
    // Under the app's ProviderScope, as `startHarness` runs it: the frame
    // reads whether anyone is signed in.
    await tester.pumpWidget(
      ProviderScope(
        overrides: [appStateProvider.overrideWithValue(app)],
        child: MaterialApp(
          navigatorKey: navigator,
          builder: (context, child) => appFrame(child!),
          home: Builder(
            builder: (context) {
              hints.add(KeyHints.visibleOf(context));
              return const SizedBox.shrink();
            },
          ),
        ),
      ),
    );
    expect(hints.last, isFalse);

    unawaited(
      navigator.currentState!.push(
        MaterialPageRoute<void>(
          builder: (_) => Scaffold(body: ShortcutsBrowser(onClose: () {})),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(find.byKey(const ValueKey('shortcuts-search')), findsOneWidget);
    expect(find.text('↑↓ Browse'), findsNothing);
    expect(find.text('Return Practice'), findsNothing);
    // The frame started the workspace's download, which waits for the terminal
    // font a test browser never sends: let its grace run out.
    await tester.pump(terminalFontsGrace);
  });

  // A page held open across a release says so (task #2185).
  testWidgets('the web frame watches for a newer release', (tester) async {
    final app = AppNotifier(
      config: AppConfig.dev,
      authSession: AuthSession(),
      configStore: null,
    );
    addTearDown(app.dispose);
    await tester.pumpWidget(
      ProviderScope(
        overrides: [appStateProvider.overrideWithValue(app)],
        child: MaterialApp(
          builder: (context, child) => appFrame(child!),
          home: const SizedBox.shrink(),
        ),
      ),
    );
    expect(find.byType(WebUpdateHost), findsOneWidget);
    await tester.pump(terminalFontsGrace);
  });
}