92 lines
2.3 KiB
Dart
92 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kooltap/models/product.dart';
|
|
|
|
void main() {
|
|
group('Product', () {
|
|
group('isLowStock', () {
|
|
test('returns true when stock equals threshold', () {
|
|
const product = Product(
|
|
id: '1',
|
|
name: 'Test',
|
|
category: 'Drinks',
|
|
stockQuantity: 5,
|
|
lowStockThreshold: 5,
|
|
priceInCents: 100,
|
|
);
|
|
|
|
expect(product.isLowStock, true);
|
|
});
|
|
|
|
test('returns true when stock is below threshold', () {
|
|
const product = Product(
|
|
id: '1',
|
|
name: 'Test',
|
|
category: 'Drinks',
|
|
stockQuantity: 3,
|
|
lowStockThreshold: 5,
|
|
priceInCents: 100,
|
|
);
|
|
|
|
expect(product.isLowStock, true);
|
|
});
|
|
|
|
test('returns false when stock is above threshold', () {
|
|
const product = Product(
|
|
id: '1',
|
|
name: 'Test',
|
|
category: 'Drinks',
|
|
stockQuantity: 10,
|
|
lowStockThreshold: 5,
|
|
priceInCents: 100,
|
|
);
|
|
|
|
expect(product.isLowStock, false);
|
|
});
|
|
});
|
|
|
|
group('copyWith', () {
|
|
test('creates copy with updated fields', () {
|
|
const original = Product(
|
|
id: '1',
|
|
name: 'Original',
|
|
category: 'Drinks',
|
|
stockQuantity: 10,
|
|
lowStockThreshold: 5,
|
|
priceInCents: 100,
|
|
);
|
|
|
|
final copy = original.copyWith(name: 'Updated', stockQuantity: 20);
|
|
|
|
expect(copy.name, 'Updated');
|
|
expect(copy.stockQuantity, 20);
|
|
expect(copy.id, '1');
|
|
expect(copy.category, 'Drinks');
|
|
});
|
|
|
|
test('preserves original values when not specified', () {
|
|
const original = Product(
|
|
id: '1',
|
|
name: 'Test',
|
|
category: 'Food',
|
|
stockQuantity: 15,
|
|
lowStockThreshold: 3,
|
|
priceInCents: 750,
|
|
imagePath: '/path/to/image.jpg',
|
|
active: false,
|
|
);
|
|
|
|
final copy = original.copyWith();
|
|
|
|
expect(copy.id, '1');
|
|
expect(copy.name, 'Test');
|
|
expect(copy.category, 'Food');
|
|
expect(copy.stockQuantity, 15);
|
|
expect(copy.lowStockThreshold, 3);
|
|
expect(copy.priceInCents, 750);
|
|
expect(copy.imagePath, '/path/to/image.jpg');
|
|
expect(copy.active, false);
|
|
});
|
|
});
|
|
});
|
|
}
|