nandi/vflutter_ffipublic Fork 0
4506a586d7400b00d732dcb97167be75ab41cab1
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Replace V with Nim 472eb49 · on 4506a586d7400b00d732dcb97167be75ab41cab1 · nandithebull · 8h ago
explorer_test.dart · 101 lines · 3.7 KBDart Blame HistoryRaw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
// Widget-level checks on the explorer. These need the native library on the
// loader path:
//
//   cd example && LD_LIBRARY_PATH=../build flutter test
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:nimflutter_ffi_example/main.dart';

/// pumpAndSettle cannot be used here: the in-flight-render spinner animates
/// indefinitely, and rendering runs on real isolates outside the fake clock.
Future<void> settle(WidgetTester tester) async {
  for (var i = 0; i < 20; i++) {
    await tester.pump(const Duration(milliseconds: 50));
  }
}

void main() {
  /// The side panel only exists in the wide layout, so size the surface like a
  /// desktop window rather than the 800x600 test default.
  Future<void> pumpWide(WidgetTester tester) async {
    tester.view.physicalSize = const Size(1400, 900);
    tester.view.devicePixelRatio = 1.0;
    addTearDown(tester.view.reset);
    await tester.pumpWidget(const ExampleApp());
    await tester.pump(const Duration(milliseconds: 100));
  }

  testWidgets('starts at the documented defaults, not the slider maxima',
      (tester) async {
    await pumpWide(tester);

    final sliders = tester.widgetList<Slider>(find.byType(Slider)).toList();
    expect(sliders, hasLength(2));
    expect(sliders[0].value, 400, reason: 'iterations should default to 400');
    expect(sliders[1].value, 16, reason: 'isolates should default to 16');
  });

  testWidgets('reset restores the framing without touching iterations',
      (tester) async {
    await pumpWide(tester);

    // Move the iteration slider off its default, then reset the view.
    await tester.drag(find.byType(Slider).first, const Offset(200, 0));
    await settle(tester);
    final changed =
        tester.widgetList<Slider>(find.byType(Slider)).first.value;
    expect(changed, greaterThan(400),
        reason: 'the drag should have raised the iteration count');

    await tester.tap(find.text('Reset view'));
    await settle(tester);

    // Reset owns pan/zoom only: the iteration setting must survive it.
    expect(tester.widgetList<Slider>(find.byType(Slider)).first.value, changed);
    expect(find.textContaining('zoom 1.0x'), findsOneWidget);
  });

  testWidgets('dragging pans without also zooming', (tester) async {
    await pumpWide(tester);
    String zoomLabel() => (tester
        .widget<Text>(find.textContaining('zoom ').first)
        .data)!;
    final before = zoomLabel();

    // Guards the gesture arena's behaviour: a pan must claim the pointer so
    // the tap recognizer never fires. (This passes with the zoom on either
    // onTapDown or onTapUp — the arena, not the callback choice, is what
    // separates them.)
    await tester.drag(find.byKey(canvasKey), const Offset(-120, -60));
    await settle(tester);

    expect(zoomLabel(), before, reason: 'a drag must not change the zoom');
  });

  testWidgets('a tap still zooms', (tester) async {
    await pumpWide(tester);
    String zoomLabel() => (tester
        .widget<Text>(find.textContaining('zoom ').first)
        .data)!;
    final before = zoomLabel();

    await tester.tap(find.byKey(canvasKey));
    await settle(tester);

    expect(zoomLabel(), isNot(before));
  });

  testWidgets('narrow layout lays out without overflowing', (tester) async {
    // Regression guard: the controls used to be a ListView nested inside the
    // page's ListView, which threw "Vertical viewport was given unbounded
    // height" and broke the whole mobile layout.
    tester.view.physicalSize = const Size(420, 900);
    tester.view.devicePixelRatio = 1.0;
    addTearDown(tester.view.reset);

    await tester.pumpWidget(const ExampleApp());
    await tester.pump(const Duration(milliseconds: 100));

    expect(tester.takeException(), isNull);
  });
}