From 2ee823b65fa1e60d0ffcd03185851336c8d6ad91 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 22 Nov 2026 18:22:08 +1100 Subject: [PATCH] bug fix for pricing didsplay (#929) * bug fix for pricing didsplay Display override values correctly * update release notes --- assets/release_notes.md | 1 + lib/widget/part/part_pricing.dart | 6 +- test/widget/part_pricing_test.dart | 121 +++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 test/widget/part_pricing_test.dart diff --git a/assets/release_notes.md b/assets/release_notes.md index 36549e71..291fe793 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -3,6 +3,7 @@ - Fix incorrect allocation count in build detail widget - Fix "new version available" notice showing in "About" view when app is up to date +- Bug fix for part pricing display - Fix handling of form response data for stock item creation - Improved allocation display for build orders - Multiple bug fixes for build order support diff --git a/lib/widget/part/part_pricing.dart b/lib/widget/part/part_pricing.dart index 342d1c1c..f3308afd 100644 --- a/lib/widget/part/part_pricing.dart +++ b/lib/widget/part/part_pricing.dart @@ -67,12 +67,12 @@ class _PartPricingWidgetState extends RefreshableState { ), ); - if (pricing.overallMin != null) { + if (pricing.overrideMin != null) { tiles.add( ListTile( title: Text(L10().priceOverrideMin), trailing: Text( - renderCurrency(pricing.overallMin, pricing.overrideMinCurrency), + renderCurrency(pricing.overrideMin, pricing.overrideMinCurrency), ), ), ); @@ -83,7 +83,7 @@ class _PartPricingWidgetState extends RefreshableState { ListTile( title: Text(L10().priceOverrideMax), trailing: Text( - renderCurrency(pricing.overallMax, pricing.overrideMaxCurrency), + renderCurrency(pricing.overrideMax, pricing.overrideMaxCurrency), ), ), ); diff --git a/test/widget/part_pricing_test.dart b/test/widget/part_pricing_test.dart new file mode 100644 index 00000000..3514cd06 --- /dev/null +++ b/test/widget/part_pricing_test.dart @@ -0,0 +1,121 @@ +/* + * Widget tests for the part pricing screen (regression tests for B5). + * + * The "override" rows previously displayed the overall price range, + * and were shown whenever an overall price existed. + * + * No server is required. + */ + +import "package:flutter/material.dart"; +import "package:flutter_test/flutter_test.dart"; +import "package:one_context/one_context.dart"; + +import "package:inventree/helpers.dart"; +import "package:inventree/inventree/part.dart"; +import "package:inventree/l10.dart"; +import "package:inventree/widget/part/part_pricing.dart"; +import "package:inventree/widget/refreshable_state.dart"; + +import "../setup.dart"; +import "harness.dart"; + +// Display the pricing screen for [pricing] data, and wait for it to load +Future pumpPricing( + WidgetTester tester, + Map pricing, +) async { + final screen = PartPricingWidget( + part: InvenTreePart.fromJson({"pk": 1, "name": "Widget"}), + partPricing: InvenTreePartPricing.fromJson(pricing), + ); + + await pumpScreen(tester, screen); + + final state = + tester.state(find.byWidget(screen)) as RefreshableState; + + await waitUntil(tester, () => state.loaded, reason: "pricing loaded"); + await idle(tester); + + // Allow the image cache (part thumbnail) to complete its cleanup timer + await tester.pump(const Duration(seconds: 11)); +} + +// The value displayed in the row titled [title] +Finder rowValue(String title, String value) => find.descendant( + of: find.widgetWithText(ListTile, title), + matching: find.text(value), +); + +void main() { + setupTestEnv(); + mockSharedPreferences(); + + setUp(() { + OneContext().key = GlobalKey(); + useNewTempDirectory(); + }); + + testWidgets("Override prices are displayed", (tester) async { + await pumpPricing(tester, { + "currency": "AUD", + "overall_min": 1, + "overall_max": 10, + "override_min": 2.5, + "override_min_currency": "AUD", + "override_max": 7.5, + "override_max_currency": "USD", + }); + + expect( + rowValue(L10().priceOverrideMin, renderCurrency(2.5, "AUD")), + findsOneWidget, + ); + + expect( + rowValue(L10().priceOverrideMax, renderCurrency(7.5, "USD")), + findsOneWidget, + ); + + // The overall range is not shown as an override + expect( + rowValue(L10().priceOverrideMin, renderCurrency(1, "AUD")), + findsNothing, + ); + + expect( + rowValue(L10().priceOverrideMax, renderCurrency(10, "USD")), + findsNothing, + ); + }); + + testWidgets("No override rows without overrides", (tester) async { + await pumpPricing(tester, { + "currency": "AUD", + "overall_min": 1, + "overall_max": 10, + }); + + expect(find.text(L10().priceRange), findsOneWidget); + expect(find.text(L10().priceOverrideMin), findsNothing); + expect(find.text(L10().priceOverrideMax), findsNothing); + }); + + testWidgets("Single override", (tester) async { + await pumpPricing(tester, { + "currency": "AUD", + "overall_min": 1, + "overall_max": 10, + "override_max": 7.5, + }); + + expect(find.text(L10().priceOverrideMin), findsNothing); + + // Currency falls back to the pricing currency + expect( + rowValue(L10().priceOverrideMax, renderCurrency(7.5, "AUD")), + findsOneWidget, + ); + }); +}