196 lines
7.7 KiB
Python
196 lines
7.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo.tests.common import TransactionCase
|
|
from hypothesis import given, strategies as st, settings
|
|
|
|
|
|
class TestStarHighlighting(TransactionCase):
|
|
"""
|
|
Test cases for star highlighting behavior
|
|
|
|
Property 2: Star highlighting follows selection
|
|
For any star selected, the system should highlight that star
|
|
and all stars with lower numbers.
|
|
|
|
Validates: Requirements 1.2
|
|
"""
|
|
|
|
def setUp(self):
|
|
super(TestStarHighlighting, self).setUp()
|
|
# We'll test the highlighting logic that would be used in the frontend
|
|
# The logic is: if star_number <= selected_value, then star is highlighted
|
|
self.max_stars = 5
|
|
|
|
def _get_highlighted_stars(self, selected_value):
|
|
"""
|
|
Simulate the highlighting logic from the JavaScript component.
|
|
Returns a list of star numbers that should be highlighted.
|
|
|
|
This mirrors the isStarFilled() logic in rating_stars.js:
|
|
- A star is filled if starNumber <= displayValue
|
|
"""
|
|
if selected_value == 0:
|
|
return []
|
|
return list(range(1, int(selected_value) + 1))
|
|
|
|
def _verify_highlighting_property(self, selected_star):
|
|
"""
|
|
Verify that when a star is selected, that star and all stars
|
|
with lower numbers are highlighted.
|
|
|
|
Args:
|
|
selected_star: The star number that was selected (1-5)
|
|
"""
|
|
highlighted = self._get_highlighted_stars(selected_star)
|
|
|
|
# Property: All stars from 1 to selected_star should be highlighted
|
|
expected_highlighted = list(range(1, selected_star + 1))
|
|
|
|
self.assertEqual(
|
|
highlighted,
|
|
expected_highlighted,
|
|
f"When star {selected_star} is selected, stars {expected_highlighted} "
|
|
f"should be highlighted, but got {highlighted}"
|
|
)
|
|
|
|
# Verify the count matches
|
|
self.assertEqual(
|
|
len(highlighted),
|
|
selected_star,
|
|
f"When star {selected_star} is selected, exactly {selected_star} "
|
|
f"stars should be highlighted, but {len(highlighted)} were highlighted"
|
|
)
|
|
|
|
# Verify all highlighted stars are <= selected_star
|
|
for star in highlighted:
|
|
self.assertLessEqual(
|
|
star,
|
|
selected_star,
|
|
f"Highlighted star {star} should be <= selected star {selected_star}"
|
|
)
|
|
|
|
# Verify all stars > selected_star are NOT highlighted
|
|
for star in range(selected_star + 1, self.max_stars + 1):
|
|
self.assertNotIn(
|
|
star,
|
|
highlighted,
|
|
f"Star {star} should NOT be highlighted when star {selected_star} is selected"
|
|
)
|
|
|
|
# Feature: helpdesk-rating-five-stars, Property 2: Star highlighting follows selection
|
|
@given(selected_star=st.integers(min_value=1, max_value=5))
|
|
@settings(max_examples=100, deadline=None)
|
|
def test_property_star_highlighting_follows_selection(self, selected_star):
|
|
"""
|
|
Property 2: Star highlighting follows selection
|
|
|
|
For any star selected (1-5), the system should highlight that star
|
|
and all stars with lower numbers.
|
|
|
|
This tests the core highlighting logic that ensures:
|
|
1. The selected star is highlighted
|
|
2. All stars with numbers < selected star are highlighted
|
|
3. All stars with numbers > selected star are NOT highlighted
|
|
|
|
Validates: Requirements 1.2
|
|
"""
|
|
self._verify_highlighting_property(selected_star)
|
|
|
|
def test_star_highlighting_specific_cases(self):
|
|
"""
|
|
Test specific cases to ensure highlighting works correctly
|
|
"""
|
|
# Test case 1: Select star 1 -> only star 1 highlighted
|
|
highlighted = self._get_highlighted_stars(1)
|
|
self.assertEqual(highlighted, [1], "Only star 1 should be highlighted")
|
|
|
|
# Test case 2: Select star 3 -> stars 1, 2, 3 highlighted
|
|
highlighted = self._get_highlighted_stars(3)
|
|
self.assertEqual(highlighted, [1, 2, 3], "Stars 1, 2, 3 should be highlighted")
|
|
|
|
# Test case 3: Select star 5 -> all stars highlighted
|
|
highlighted = self._get_highlighted_stars(5)
|
|
self.assertEqual(highlighted, [1, 2, 3, 4, 5], "All stars should be highlighted")
|
|
|
|
# Test case 4: No selection (0) -> no stars highlighted
|
|
highlighted = self._get_highlighted_stars(0)
|
|
self.assertEqual(highlighted, [], "No stars should be highlighted")
|
|
|
|
def test_star_highlighting_sequential_selection(self):
|
|
"""
|
|
Test that highlighting updates correctly when selection changes
|
|
"""
|
|
# Simulate selecting stars in sequence
|
|
for star in range(1, self.max_stars + 1):
|
|
highlighted = self._get_highlighted_stars(star)
|
|
|
|
# Verify correct number of stars highlighted
|
|
self.assertEqual(
|
|
len(highlighted),
|
|
star,
|
|
f"Selecting star {star} should highlight {star} stars"
|
|
)
|
|
|
|
# Verify the highlighted stars are exactly [1, 2, ..., star]
|
|
self.assertEqual(
|
|
highlighted,
|
|
list(range(1, star + 1)),
|
|
f"Selecting star {star} should highlight stars 1 through {star}"
|
|
)
|
|
|
|
def test_star_highlighting_reverse_selection(self):
|
|
"""
|
|
Test that highlighting works correctly when selecting in reverse order
|
|
"""
|
|
# Simulate selecting stars in reverse sequence
|
|
for star in range(self.max_stars, 0, -1):
|
|
highlighted = self._get_highlighted_stars(star)
|
|
|
|
# Verify correct number of stars highlighted
|
|
self.assertEqual(
|
|
len(highlighted),
|
|
star,
|
|
f"Selecting star {star} should highlight {star} stars"
|
|
)
|
|
|
|
# Verify the highlighted stars are exactly [1, 2, ..., star]
|
|
self.assertEqual(
|
|
highlighted,
|
|
list(range(1, star + 1)),
|
|
f"Selecting star {star} should highlight stars 1 through {star}"
|
|
)
|
|
|
|
def test_star_highlighting_boundary_cases(self):
|
|
"""
|
|
Test boundary cases for star highlighting
|
|
"""
|
|
# Minimum valid selection (star 1)
|
|
highlighted = self._get_highlighted_stars(1)
|
|
self.assertEqual(len(highlighted), 1, "Minimum selection should highlight 1 star")
|
|
self.assertIn(1, highlighted, "Star 1 should be highlighted")
|
|
|
|
# Maximum valid selection (star 5)
|
|
highlighted = self._get_highlighted_stars(5)
|
|
self.assertEqual(len(highlighted), 5, "Maximum selection should highlight 5 stars")
|
|
for star in range(1, 6):
|
|
self.assertIn(star, highlighted, f"Star {star} should be highlighted")
|
|
|
|
# No selection (0)
|
|
highlighted = self._get_highlighted_stars(0)
|
|
self.assertEqual(len(highlighted), 0, "No selection should highlight 0 stars")
|
|
|
|
def test_star_highlighting_consistency(self):
|
|
"""
|
|
Test that highlighting is consistent across multiple calls
|
|
"""
|
|
for star in range(1, self.max_stars + 1):
|
|
# Call multiple times with same value
|
|
result1 = self._get_highlighted_stars(star)
|
|
result2 = self._get_highlighted_stars(star)
|
|
result3 = self._get_highlighted_stars(star)
|
|
|
|
# All results should be identical
|
|
self.assertEqual(result1, result2, "Highlighting should be consistent")
|
|
self.assertEqual(result2, result3, "Highlighting should be consistent")
|
|
self.assertEqual(result1, result3, "Highlighting should be consistent")
|