From 2623046ba720e1d799e1db903dc81f1344cffff0 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 11 Jan 2022 20:15:24 +0530 Subject: [PATCH] test: Variant Selector - Fetch next valid Attribute values fetching after selection of one --- .../variant_selector/test_variant_selector.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/erpnext/e_commerce/variant_selector/test_variant_selector.py b/erpnext/e_commerce/variant_selector/test_variant_selector.py index 5443d099b0..608ff230a6 100644 --- a/erpnext/e_commerce/variant_selector/test_variant_selector.py +++ b/erpnext/e_commerce/variant_selector/test_variant_selector.py @@ -72,18 +72,22 @@ class TestVariantSelector(unittest.TestCase): # Only L and M attribute values must be fetched since S is disabled self.assertEqual(len(attr_data[0]["values"]), 2) # ['Medium', 'Large'] - # def test_next_item_variant_values(self): - # """ - # Test if on selecting an attribute value, the next possible values - # are filtered accordingly. - # Values that dont apply should not be fetched. - # E.g. - # There is a ** Small-Red ** Tshirt. No other colour in this size. - # On selecting ** Small **, only ** Red ** should be selectable next. - # """ - # from erpnext.e_commerce.variant_selector.utils import get_next_attribute_and_values + def test_next_item_variant_values(self): + """ + Test if on selecting an attribute value, the next possible values + are filtered accordingly. + Values that dont apply should not be fetched. + E.g. + There is a ** Small-Red ** Tshirt. No other colour in this size. + On selecting ** Small **, only ** Red ** should be selectable next. + """ + from erpnext.e_commerce.variant_selector.utils import get_next_attribute_and_values - # next_values = get_next_attribute_and_values("Test-Tshirt-Temp", selected_attributes={ - # "Colour": "Red" - # }) - # print(next_values) \ No newline at end of file + next_values = get_next_attribute_and_values("Test-Tshirt-Temp", selected_attributes={"Test Size": "Small"}) + next_colours = next_values["valid_options_for_attributes"]["Test Colour"] + filtered_items = next_values["filtered_items"] + + self.assertEqual(len(next_colours), 1) + self.assertEqual(next_colours.pop(), "Red") + self.assertEqual(len(filtered_items), 1) + self.assertEqual(filtered_items.pop(), "Test-Tshirt-Temp-S-R")