- Remove redundant string= from 17 field definitions where name matches string value (W8113) - Convert @staticmethod to instance methods in selection methods for proper self.env._() access - Fix W8161 (prefer-env-translation) by using self.env._() instead of standalone _() - Fix W8301/W8115 (translation-not-lazy) by proper placement of % interpolation outside self.env._() - Remove unused imports of odoo._ from group_order.py and sale_order_extension.py - All OCA linting warnings in website_sale_aplicoop main models are now resolved Changes: - website_sale_aplicoop/models/group_order.py: 21 field definitions cleaned - website_sale_aplicoop/models/sale_order_extension.py: 5 field definitions cleaned + @staticmethod conversion - Consistent with OCA standards for addon submission
6.9 KiB
6.9 KiB
JavaScript Tests for website_sale_aplicoop
This directory contains QUnit tests for the JavaScript functionality of the website_sale_aplicoop module.
Test Files
1. test_cart_functions.js
Tests for core cart functionality:
- Cart initialization
- Adding items to cart
- Removing items from cart
- Updating quantities
- Calculating totals
- localStorage persistence
- Decimal quantity handling
- Zero quantity handling
2. test_tooltips_labels.js
Tests for tooltip and label functionality:
- Tooltip initialization from labels
- Label loading and structure
- Missing label handling
- Label reinitialization
- JSON serialization of labels
- Empty labels handling
3. test_realtime_search.js
Tests for real-time product search:
- Search input functionality
- Category filtering
- Combined search and category filters
- Case-insensitive search
- Partial matching
- Whitespace trimming
- Product visibility toggling
- Result counting
4. test_suite.js
Main test suite that imports all test modules.
Running the Tests
Method 1: Via Odoo Test Runner (Recommended)
-
Access the test interface:
http://localhost:8069/web/tests?mod=website_sale_aplicoop -
Run specific test modules:
http://localhost:8069/web/tests?mod=website_sale_aplicoop.test_cart_functions http://localhost:8069/web/tests?mod=website_sale_aplicoop.test_tooltips_labels http://localhost:8069/web/tests?mod=website_sale_aplicoop.test_realtime_search -
View results:
- Tests run in the browser
- Results displayed in QUnit interface
- Green = Pass, Red = Fail
- Click failed tests to see details
Method 2: Via Command Line
Run Odoo with test mode:
# Run all tests
docker-compose exec odoo odoo -d odoo --test-enable --stop-after-init
# Run with specific test tags
docker-compose exec odoo odoo -d odoo --test-enable --test-tags=website_sale_aplicoop --stop-after-init
# Run in verbose mode for more details
docker-compose exec odoo odoo -d odoo --test-enable --log-level=test --stop-after-init
Method 3: Via Browser Console
- Open the application page in browser
- Open browser console (F12)
- Run:
QUnit.start();
Test Coverage
Cart Functions (11 tests)
- ✅ Object initialization
- ✅ Empty cart verification
- ✅ Add item to cart
- ✅ Remove item from cart
- ✅ Update quantity
- ✅ Calculate total
- ✅ localStorage persistence
- ✅ Decimal quantities
- ✅ Zero quantity handling
- ✅ Same price products
- ✅ Label initialization
Tooltips & Labels (10 tests)
- ✅ Tooltip initialization
- ✅ Missing label handling
- ✅ Label object structure
- ✅ Label data types
- ✅ Global label usage
- ✅ Reinitialization
- ✅ Elements without tooltips
- ✅ querySelectorAll functionality
- ✅ JSON serialization
- ✅ Empty labels handling
Realtime Search (13 tests)
- ✅ Element existence
- ✅ Search by name
- ✅ Case insensitive search
- ✅ Empty search shows all
- ✅ Category filtering
- ✅ Combined filters
- ✅ Non-existent product
- ✅ Partial matching
- ✅ Whitespace trimming
- ✅ CSS class toggling
- ✅ Visibility restoration
- ✅ Result counting
Total: 34 tests
Adding New Tests
-
Create a new test file in
/static/tests/:odoo.define('website_sale_aplicoop.test_my_feature', function (require) { 'use strict'; var QUnit = window.QUnit; QUnit.module('website_sale_aplicoop.my_feature', { beforeEach: function() { // Setup code }, afterEach: function() { // Cleanup code } }, function() { QUnit.test('test description', function(assert) { assert.expect(1); assert.ok(true, 'test passes'); }); }); }); -
Add to
test_suite.js:require('website_sale_aplicoop.test_my_feature'); -
Add to
__manifest__.pyassets:'web.assets_tests': [ # ... existing files ... 'website_sale_aplicoop/static/tests/test_my_feature.js', ], -
Reload module and run tests
QUnit Assertions Reference
Common assertions used in tests:
assert.ok(value, message)- Verify truthy valueassert.equal(actual, expected, message)- Loose equality (==)assert.strictEqual(actual, expected, message)- Strict equality (===)assert.deepEqual(actual, expected, message)- Deep object comparisonassert.notOk(value, message)- Verify falsy valueassert.notEqual(actual, expected, message)- Verify not equalassert.expect(count)- Set expected assertion count
Debugging Tests
View Test Output
- Open browser console (F12)
- Check "Console" tab for test logs
- Check "Network" tab for failed requests
Debug Individual Test
QUnit.test('test name', function(assert) {
debugger; // Browser will pause here
// ... test code ...
});
Run Single Test
QUnit.only('test name', function(assert) {
// Only this test will run
});
Skip Test
QUnit.skip('test name', function(assert) {
// This test will be skipped
});
Continuous Integration
Tests can be integrated into CI/CD pipelines:
# In CI script
docker-compose up -d
docker-compose exec -T odoo odoo -d odoo --test-enable --test-tags=website_sale_aplicoop --stop-after-init
exit_code=$?
docker-compose down
exit $exit_code
Troubleshooting
Tests not loading
- Verify module is installed and updated
- Check browser console for JavaScript errors
- Verify assets are properly declared in manifest.py
- Clear browser cache and restart Odoo
Tests failing unexpectedly
- Check if labels are loaded (
window.groupOrderShop.labels) - Verify DOM elements exist before testing
- Check for timing issues (use beforeEach/afterEach)
- Verify localStorage is not blocked by browser
Assets not found
- Update module:
docker-compose exec odoo odoo -d odoo -u website_sale_aplicoop - Clear assets cache:
docker-compose exec odoo rm -rf /var/lib/odoo/filestore/odoo/web/static/lib/minified_assets/ - Restart Odoo
Best Practices
- Use beforeEach/afterEach: Clean up DOM and global state
- Expect assertions: Always use
assert.expect(n)to verify all assertions run - Test isolation: Each test should be independent
- Descriptive names: Use clear, descriptive test names
- One concept per test: Test one thing at a time
- Mock external dependencies: Don't rely on real API calls
- Test edge cases: Empty strings, null values, extreme numbers
Resources
Maintainer: Criptomart License: AGPL-3.0 Last Updated: February 3, 2026