filtri avanzati operazioni
Build and Release FLUX (Multi-Platform) / build-linux (push) Successful in 1m31s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m50s
Build and Release FLUX (Multi-Platform) / build-macos (push) Successful in 2m26s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 9m43s

This commit is contained in:
brontomark committed 2026-11-21 10:23:04 +01:00
1 parent 4b111766dc
commit 57a4dc6f68
12 files changed
+2045 -321

No files matched your search

@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
import 'package:flux/features/operations/models/operation_filter_params.dart';
import 'package:flux/features/operations/models/operation_type.dart';
void main() {
group('OperationListState filter properties', () {
test('hasActiveFilters returns false on default initial state', () {
const state = OperationListState();
expect(state.hasActiveFilters, isFalse);
expect(state.activeFiltersCount, 0);
});
test('hasActiveFilters returns true when any filter is set', () {
const withSearch = OperationListState(searchTerm: 'Mario');
expect(withSearch.hasActiveFilters, isTrue);
expect(withSearch.activeFiltersCount, 1);
final withDate = OperationListState(
dateRange: DateTimeRange(
start: DateTime(2026, 11, 1),
end: DateTime(2026, 11, 30),
),
);
expect(withDate.hasActiveFilters, isTrue);
expect(withDate.activeFiltersCount, 1);
const withType = OperationListState(detailType: OperationType.telepass);
expect(withType.hasActiveFilters, isTrue);
expect(withType.activeFiltersCount, 1);
const withStaff = OperationListState(
staffId: 'staff-1',
staffDisplayName: 'Marco',
);
expect(withStaff.hasActiveFilters, isTrue);
expect(withStaff.activeFiltersCount, 1);
const withMultiple = OperationListState(
searchTerm: 'Test',
detailType: OperationType.mnp,
staffId: 'staff-1',
);
expect(withMultiple.hasActiveFilters, isTrue);
expect(withMultiple.activeFiltersCount, 3);
});
test('toFilterParams accurately exports state into OperationFilterParams', () {
final state = OperationListState(
searchTerm: 'Cliente',
detailType: OperationType.mnp,
subType: 'Vodafone',
staffId: 'staff-42',
staffDisplayName: 'Alessandro',
categoryKey: 'mnp',
categoryLabel: 'MNP',
storeId: 'store-1',
dateRange: DateTimeRange(
start: DateTime(2026, 11, 1),
end: DateTime(2026, 11, 30),
),
);
final OperationFilterParams params = state.toFilterParams();
expect(params.searchTerm, 'Cliente');
expect(params.detailType, OperationType.mnp);
expect(params.subType, 'Vodafone');
expect(params.staffId, 'staff-42');
expect(params.staffDisplayName, 'Alessandro');
expect(params.categoryKey, 'mnp');
expect(params.storeId, 'store-1');
expect(params.dateRange, state.dateRange);
});
test('copyWith can clear individual filters with explicit callbacks', () {
final state = OperationListState(
searchTerm: 'Test',
detailType: OperationType.mnp,
staffId: 'staff-1',
);
final cleared = state.copyWith(
searchTerm: () => null,
detailType: () => null,
);
expect(cleared.searchTerm, isNull);
expect(cleared.detailType, isNull);
expect(cleared.staffId, 'staff-1');
expect(cleared.hasActiveFilters, isTrue);
expect(cleared.activeFiltersCount, 1);
});
});
}
@@ -0,0 +1,143 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flux/features/operations/models/operation_filter_params.dart';
import 'package:flux/features/operations/models/operation_type.dart';
import 'package:flux/features/targets/models/target_model.dart';
void main() {
group('OperationFilterParams Tests', () {
test('empty() produces an empty params instance', () {
final empty = OperationFilterParams.empty();
expect(empty.isEmpty, isTrue);
expect(empty.isNotEmpty, isFalse);
expect(empty.detailType, isNull);
expect(empty.staffId, isNull);
expect(empty.dateRange, isNull);
expect(empty.searchTerm, isNull);
});
test('fromTargetCategory maps MNP category accurately', () {
final target = TargetModel.empty(
companyId: 'comp-1',
storeId: 'store-1',
startDay: DateTime(2026, 11, 1),
endDay: DateTime(2026, 11, 30, 23, 59, 59),
);
final params = OperationFilterParams.fromTargetCategory(
categoryKey: 'mnp',
categoryLabel: 'MNP',
target: target,
staffId: 'staff-99',
staffDisplayName: 'Marco',
);
expect(params.categoryKey, 'mnp');
expect(params.categoryLabel, 'MNP');
expect(params.detailType, OperationType.mnp);
expect(params.subType, isNull);
expect(params.storeId, 'store-1');
expect(params.staffId, 'staff-99');
expect(params.staffDisplayName, 'Marco');
expect(params.dateRange?.start, target.startDay);
expect(params.dateRange?.end, target.endDay);
expect(params.isNotEmpty, isTrue);
});
test('fromTargetCategory maps Calcio category to entertainment with calcio subtype', () {
final target = TargetModel.empty(
companyId: 'comp-1',
storeId: 'store-1',
);
final params = OperationFilterParams.fromTargetCategory(
categoryKey: 'calcio',
categoryLabel: 'Calcio',
target: target,
);
expect(params.categoryKey, 'calcio');
expect(params.detailType, OperationType.entertainment);
expect(params.subType, 'calcio');
});
test('fromTargetCategory maps Contenuti, Unica, Telepass, etc.', () {
final target = TargetModel.empty();
final contenuti = OperationFilterParams.fromTargetCategory(
categoryKey: 'contenuti',
categoryLabel: 'Contenuti',
target: target,
);
expect(contenuti.detailType, OperationType.entertainment);
final unica = OperationFilterParams.fromTargetCategory(
categoryKey: 'unica',
categoryLabel: 'TIM Unica',
target: target,
);
expect(unica.detailType, OperationType.unica);
final telepass = OperationFilterParams.fromTargetCategory(
categoryKey: 'telepass',
categoryLabel: 'Telepass',
target: target,
);
expect(telepass.detailType, OperationType.telepass);
final energy = OperationFilterParams.fromTargetCategory(
categoryKey: 'energiaTim',
categoryLabel: 'Energia TIM',
target: target,
);
expect(energy.detailType, OperationType.energy);
});
test('toQueryParams and fromQueryParams serialization round-trip', () {
final original = OperationFilterParams(
searchTerm: 'Mario Rossi',
dateRange: DateTimeRange(
start: DateTime(2026, 11, 1),
end: DateTime(2026, 11, 30),
),
detailType: OperationType.telepass,
subType: 'Base',
categoryKey: 'telepass',
categoryLabel: 'Telepass',
staffId: 'staff-1',
staffDisplayName: 'Luca',
storeId: 'store-1',
);
final query = original.toQueryParams();
final reconstructed = OperationFilterParams.fromQueryParams(query);
expect(reconstructed.searchTerm, original.searchTerm);
expect(reconstructed.detailType, original.detailType);
expect(reconstructed.subType, original.subType);
expect(reconstructed.categoryKey, original.categoryKey);
expect(reconstructed.staffId, original.staffId);
expect(reconstructed.staffDisplayName, original.staffDisplayName);
expect(reconstructed.storeId, original.storeId);
expect(reconstructed.dateRange?.start, original.dateRange?.start);
expect(reconstructed.dateRange?.end, original.dateRange?.end);
});
test('copyWith properly updates and clears individual filters', () {
final initial = OperationFilterParams(
searchTerm: 'Test',
detailType: OperationType.mnp,
staffId: 's-1',
);
final updated = initial.copyWith(
searchTerm: 'New Test',
clearDetailType: true,
);
expect(updated.searchTerm, 'New Test');
expect(updated.detailType, isNull);
expect(updated.staffId, 's-1');
});
});
}