iv_and/product_test.dart
joe a8242c2a7e
Some checks are pending
Flutter CI / build (push) Waiting to run
feat: Invoiceアプリの基本機能を追加
Co-authored-by: aider (ollama_chat/7b) <aider@aider.chat>
2026-01-16 09:35:27 +09:00

40 lines
1.2 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:sqflite/sqflite.dart';
import 'package:path_provider/path_provider.dart';
import 'db_helper.dart';
import 'product.dart';
void main() {
group('Product Tests', () {
late Database db;
setUp(() async {
final io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = '${documentsDirectory.path}/test.db';
db = await openDatabase(path, version: 1, onCreate: DbHelper()._onCreate);
});
tearDown(() async {
await db.close();
final io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = '${documentsDirectory.path}/test.db';
await io.File(path).delete();
});
test('Add and fetch product', () async {
final product = Product(
name: 'Test Product',
unitPrice: 100.0,
discount: 0.1,
);
await db.insert('products', product.toMap());
final List<Map<String, dynamic>> maps = await db.query('products');
expect(maps.length, 1);
final fetchedProduct = Product.fromMap(maps.first);
expect(fetchedProduct.name, 'Test Product');
});
});
}