aggiunta quantità a intrattenimento e unica
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m6s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m23s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m37s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 26m18s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 2m6s
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m23s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m37s
Build and Release FLUX (Multi-Platform) / build-macos (push) Failing after 26m18s
This commit is contained in:
1 parent
2bf668a088
commit
4b111766dc
12 files changed
+571
-71
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_details_form_cubit.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_details_list_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_detail_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_type.dart';
|
||||
|
||||
void main() {
|
||||
group('OperationDetailsListCubit quantity updates', () {
|
||||
test('updateOperationDetailQuantity updates target detail and ignores < 1', () {
|
||||
final cubit = OperationDetailsListCubit(
|
||||
details: const [
|
||||
OperationDetailModel(type: OperationType.entertainment, quantity: 1),
|
||||
OperationDetailModel(type: OperationType.unica, quantity: 2),
|
||||
],
|
||||
);
|
||||
|
||||
cubit.updateOperationDetailQuantity(0, 3);
|
||||
expect(cubit.state.details[0].quantity, 3);
|
||||
expect(cubit.state.status, OperationDetailsListStatus.updated);
|
||||
|
||||
// Clamping to minimum 1
|
||||
cubit.updateOperationDetailQuantity(1, 0);
|
||||
expect(cubit.state.details[1].quantity, 1);
|
||||
|
||||
// Out-of-bounds index is a no-op
|
||||
cubit.updateOperationDetailQuantity(5, 4);
|
||||
expect(cubit.state.details.length, 2);
|
||||
|
||||
cubit.close();
|
||||
});
|
||||
});
|
||||
|
||||
group('OperationDetailsFormCubit quantity updates', () {
|
||||
test('updateFields clamps quantity to at least 1', () {
|
||||
final cubit = OperationDetailsFormCubit(
|
||||
initialDetail: const OperationDetailModel(
|
||||
type: OperationType.entertainment,
|
||||
quantity: 1,
|
||||
),
|
||||
);
|
||||
|
||||
cubit.updateFields(quantity: 4);
|
||||
expect(cubit.state.operationDetail.quantity, 4);
|
||||
|
||||
cubit.updateFields(quantity: -2);
|
||||
expect(cubit.state.operationDetail.quantity, 1);
|
||||
|
||||
cubit.close();
|
||||
});
|
||||
|
||||
test('setTypeWithSmartDefaults resets quantity to 1 when type does not support quantity', () {
|
||||
final cubit = OperationDetailsFormCubit(
|
||||
initialDetail: const OperationDetailModel(
|
||||
type: OperationType.entertainment,
|
||||
quantity: 3,
|
||||
),
|
||||
);
|
||||
|
||||
// Switching between entertainment and unica preserves quantity
|
||||
cubit.setTypeWithSmartDefaults(
|
||||
newType: OperationType.unica,
|
||||
allProviders: const [],
|
||||
);
|
||||
expect(cubit.state.operationDetail.quantity, 3);
|
||||
|
||||
// Switching to a type without quantity support resets to 1
|
||||
cubit.setTypeWithSmartDefaults(
|
||||
newType: OperationType.al,
|
||||
allProviders: const [],
|
||||
);
|
||||
expect(cubit.state.operationDetail.quantity, 1);
|
||||
|
||||
cubit.close();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flux/features/operations/models/operation_detail_model.dart';
|
||||
import 'package:flux/features/operations/models/operation_type.dart';
|
||||
|
||||
void main() {
|
||||
group('OperationDetailModel', () {
|
||||
test('defaults quantity to 1 in constructor and empty()', () {
|
||||
const detail = OperationDetailModel();
|
||||
final empty = OperationDetailModel.empty();
|
||||
|
||||
expect(detail.quantity, 1);
|
||||
expect(empty.quantity, 1);
|
||||
});
|
||||
|
||||
test('fromMap parses quantity and clamps values < 1 to 1', () {
|
||||
final withQty = OperationDetailModel.fromMap({
|
||||
'type': 'Entertainment',
|
||||
'sub_type': 'TIMVISION L',
|
||||
'quantity': 3,
|
||||
});
|
||||
expect(withQty.type, OperationType.entertainment);
|
||||
expect(withQty.subType, 'TIMVISION L');
|
||||
expect(withQty.quantity, 3);
|
||||
|
||||
final missingQty = OperationDetailModel.fromMap({
|
||||
'type': 'UNICA',
|
||||
});
|
||||
expect(missingQty.type, OperationType.unica);
|
||||
expect(missingQty.quantity, 1);
|
||||
|
||||
final zeroQty = OperationDetailModel.fromMap({
|
||||
'type': 'Entertainment',
|
||||
'quantity': 0,
|
||||
});
|
||||
expect(zeroQty.quantity, 1);
|
||||
});
|
||||
|
||||
test('toMap serializes quantity and clamps values < 1 to 1', () {
|
||||
const detail = OperationDetailModel(
|
||||
type: OperationType.entertainment,
|
||||
subType: 'Calcio',
|
||||
quantity: 3,
|
||||
);
|
||||
expect(detail.toMap()['quantity'], 3);
|
||||
|
||||
const invalidDetail = OperationDetailModel(
|
||||
type: OperationType.unica,
|
||||
quantity: 0,
|
||||
);
|
||||
expect(invalidDetail.toMap()['quantity'], 1);
|
||||
});
|
||||
|
||||
test('copyWith and Equatable include quantity', () {
|
||||
const a = OperationDetailModel(
|
||||
type: OperationType.entertainment,
|
||||
quantity: 2,
|
||||
);
|
||||
final b = a.copyWith(quantity: 3);
|
||||
|
||||
expect(b.quantity, 3);
|
||||
expect(a, isNot(equals(b)));
|
||||
expect(a.copyWith(), equals(a));
|
||||
});
|
||||
|
||||
test('supportsQuantity is true only for entertainment and unica', () {
|
||||
expect(OperationType.entertainment.supportsQuantity, isTrue);
|
||||
expect(OperationType.unica.supportsQuantity, isTrue);
|
||||
expect(OperationType.al.supportsQuantity, isFalse);
|
||||
expect(OperationType.mnp.supportsQuantity, isFalse);
|
||||
expect(OperationType.energy.supportsQuantity, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:flux/features/operations/models/operation_type.dart';
|
||||
import 'package:flux/features/targets/data/target_progress_service.dart';
|
||||
|
||||
void main() {
|
||||
group('TargetProgressService.mapDetailToCategories', () {
|
||||
test('entertainment Calcio maps to both calcio and contenuti', () {
|
||||
expect(
|
||||
TargetProgressService.mapDetailToCategories(
|
||||
opType: OperationType.entertainment,
|
||||
subType: 'Calcio',
|
||||
providerName: 'TIM',
|
||||
isBusinessOp: false,
|
||||
),
|
||||
equals(['calcio', 'contenuti']),
|
||||
);
|
||||
|
||||
expect(
|
||||
TargetProgressService.mapDetailToCategories(
|
||||
opType: OperationType.entertainment,
|
||||
subType: 'TIMVISION Calcio',
|
||||
providerName: 'TIM',
|
||||
isBusinessOp: false,
|
||||
),
|
||||
equals(['calcio', 'contenuti']),
|
||||
);
|
||||
});
|
||||
|
||||
test('non-calcio entertainment maps only to contenuti', () {
|
||||
expect(
|
||||
TargetProgressService.mapDetailToCategories(
|
||||
opType: OperationType.entertainment,
|
||||
subType: 'Disney+',
|
||||
providerName: 'TIM',
|
||||
isBusinessOp: false,
|
||||
),
|
||||
equals(['contenuti']),
|
||||
);
|
||||
|
||||
expect(
|
||||
TargetProgressService.mapDetailToCategories(
|
||||
opType: OperationType.entertainment,
|
||||
subType: null,
|
||||
providerName: 'TIM',
|
||||
isBusinessOp: false,
|
||||
),
|
||||
equals(['contenuti']),
|
||||
);
|
||||
});
|
||||
|
||||
test('unica maps to unica', () {
|
||||
expect(
|
||||
TargetProgressService.mapDetailToCategories(
|
||||
opType: OperationType.unica,
|
||||
subType: null,
|
||||
providerName: 'TIM',
|
||||
isBusinessOp: false,
|
||||
),
|
||||
equals(['unica']),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('TargetProgressService.aggregateOperationCounts', () {
|
||||
test('accumulates quantity and counts calcio into both calcio and contenuti', () {
|
||||
final operations = [
|
||||
{
|
||||
'staff_id': 'staff-1',
|
||||
'is_business': false,
|
||||
'operation_details': [
|
||||
// 1 Calcio -> +1 calcio, +1 contenuti
|
||||
{'type': 'Entertainment', 'sub_type': 'Calcio', 'quantity': 1},
|
||||
// 1 Disney -> +1 contenuti
|
||||
{'type': 'Entertainment', 'sub_type': 'Disney', 'quantity': 1},
|
||||
// 1 TIMVISION L da 3 canali -> +3 contenuti
|
||||
{'type': 'Entertainment', 'sub_type': 'TIMVISION L', 'quantity': 3},
|
||||
// 1 Unica da 2 -> +2 unica
|
||||
{'type': 'UNICA', 'sub_type': null, 'quantity': 2},
|
||||
],
|
||||
},
|
||||
{
|
||||
'staff_id': 'staff-2',
|
||||
'is_business': false,
|
||||
'operation_details': [
|
||||
// Calcio con quantity 2 -> +2 calcio, +2 contenuti
|
||||
{'type': 'Entertainment', 'sub_type': 'Calcio', 'quantity': 2},
|
||||
// Dettaglio legacy senza quantity -> default 1
|
||||
{'type': 'MNP', 'sub_type': null},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
final result = TargetProgressService.aggregateOperationCounts(operations);
|
||||
|
||||
expect(result.storeCounts['calcio'], 3);
|
||||
expect(result.storeCounts['contenuti'], 7); // 1 + 1 + 3 + 2
|
||||
expect(result.storeCounts['unica'], 2);
|
||||
expect(result.storeCounts['mnp'], 1);
|
||||
|
||||
expect(result.staffCounts['staff-1']?['calcio'], 1);
|
||||
expect(result.staffCounts['staff-1']?['contenuti'], 5);
|
||||
expect(result.staffCounts['staff-1']?['unica'], 2);
|
||||
|
||||
expect(result.staffCounts['staff-2']?['calcio'], 2);
|
||||
expect(result.staffCounts['staff-2']?['contenuti'], 2);
|
||||
expect(result.staffCounts['staff-2']?['mnp'], 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user