Newer
Older
SmTIAS-Capture / test / models / display_orientation_test.dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:smtias_capture/models/display_orientation.dart';

/// 向きの単一定義 [DisplayOrientation] が,ライブ系・スナップショット系の
/// 両方へ正しい値を派生させることを固定する契約テスト.
///
/// リファクタリングで「現行の向き挙動」が変わっていないことを保証する.
/// (ライブ系の見た目はゴールデンテスト,最終的な向きの正しさは実機目視で確認.)
void main() {
  group('DisplayOrientation.attachmentDownward(下向き設置の確定値)', () {
    const orientation = DisplayOrientation.attachmentDownward;

    test('ライブ系: previewMatrix が 180°回転(X反転+Y反転)である', () {
      expect(orientation.flipHorizontal, isTrue);
      expect(orientation.flipVertical, isTrue);
      expect(
        orientation.previewMatrix.storage,
        Matrix4.diagonal3Values(-1.0, -1.0, 1.0).storage,
      );
    });

    test('スナップショット系: native へ rotation:90, mirror:true を渡す', () {
      expect(orientation.snapshotRotationDegrees, 90);
      expect(orientation.snapshotMirror, isTrue);
    });
  });

  group('previewMatrix の派生', () {
    test('反転なしの場合は単位行列になる', () {
      const noFlip = DisplayOrientation(
        flipHorizontal: false,
        flipVertical: false,
        snapshotRotationDegrees: 0,
        snapshotMirror: false,
      );
      expect(noFlip.previewMatrix.storage, Matrix4.identity().storage);
    });

    test('X のみ反転すると対角 x = -1 になる', () {
      const flipX = DisplayOrientation(
        flipHorizontal: true,
        flipVertical: false,
        snapshotRotationDegrees: 0,
        snapshotMirror: false,
      );
      expect(
        flipX.previewMatrix.storage,
        Matrix4.diagonal3Values(-1.0, 1.0, 1.0).storage,
      );
    });
  });
}