JJ_MKVMaker/test/storage_chart_test.dart

51 lines
2.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jj_mkvmaker/ui/storage_chart.dart';
/// X-plore 비교 P3 (87 위): 저장 공간 그림 (treemap) - 넓이는 크기에 비례, 겹치지 않고 다 채움, 누르면 그 폴더
void main() {
test('칸 나누기: 넓이 비례 · 영역 안 · 겹치지 않음 · 0 은 빠짐', () {
const area = Rect.fromLTWH(0, 0, 400, 300);
final blocks = [
const StorageBlock('a', 600, 'A'),
const StorageBlock('b', 300, 'B'),
const StorageBlock('c', 100, 'C'),
const StorageBlock('d', 200),
const StorageBlock('z', 0, 'Z'),
];
final cells = StorageTreemap.layout(blocks, area);
expect(cells.map((c) => c.$1.label), ['a', 'b', 'd', 'c'], reason: '큰 것부터, 0 은 빠짐');
const total = 1200;
for (final (b, r) in cells) {
expect(r.width * r.height, closeTo(area.width * area.height * b.size / total, 0.5));
expect(area.inflate(0.01).contains(r.topLeft) && area.inflate(0.01).contains(r.bottomRight - const Offset(0.001, 0.001)), isTrue);
}
for (var i = 0; i < cells.length; i++) {
for (var j = i + 1; j < cells.length; j++) {
final o = cells[i].$2.intersect(cells[j].$2);
expect(o.width <= 0.01 || o.height <= 0.01, isTrue, reason: '${cells[i].$1.label} · ${cells[j].$1.label} 겹침');
}
}
expect(StorageTreemap.layout(const [], area), isEmpty);
});
testWidgets('폴더 칸을 누르면 그 폴더, 경로 없는 칸 (이 폴더의 파일) 은 누를 수 없음', (t) async {
final tapped = <String>[];
await t.pumpWidget(MaterialApp(
home: Scaffold(
body: SizedBox(
width: 400,
height: 300,
child: StorageTreemap(
blocks: const [StorageBlock('Videos', 800, '/v'), StorageBlock('files', 200)],
onTap: (b) => tapped.add(b.path!),
),
),
),
));
await t.tap(find.text('Videos'));
await t.tap(find.text('files'));
expect(tapped, ['/v']);
});
}