addons-cm/website_sale_aplicoop/static/tests
2026-02-11 15:32:11 +01:00
..
README.md Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
test_cart_functions.js Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
test_realtime_search.js Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
test_suite.js Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
test_tooltips_labels.js Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00

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

  1. Access the test interface:

    http://localhost:8069/web/tests?mod=website_sale_aplicoop
    
  2. 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
    
  3. 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

  1. Open the application page in browser
  2. Open browser console (F12)
  3. 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

  1. 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');
            });
        });
    });
    
  2. Add to test_suite.js:

    require('website_sale_aplicoop.test_my_feature');
    
  3. Add to __manifest__.py assets:

    'web.assets_tests': [
        # ... existing files ...
        'website_sale_aplicoop/static/tests/test_my_feature.js',
    ],
    
  4. Reload module and run tests

QUnit Assertions Reference

Common assertions used in tests:

  • assert.ok(value, message) - Verify truthy value
  • assert.equal(actual, expected, message) - Loose equality (==)
  • assert.strictEqual(actual, expected, message) - Strict equality (===)
  • assert.deepEqual(actual, expected, message) - Deep object comparison
  • assert.notOk(value, message) - Verify falsy value
  • assert.notEqual(actual, expected, message) - Verify not equal
  • assert.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

  1. Use beforeEach/afterEach: Clean up DOM and global state
  2. Expect assertions: Always use assert.expect(n) to verify all assertions run
  3. Test isolation: Each test should be independent
  4. Descriptive names: Use clear, descriptive test names
  5. One concept per test: Test one thing at a time
  6. Mock external dependencies: Don't rely on real API calls
  7. Test edge cases: Empty strings, null values, extreme numbers

Resources


Maintainer: Criptomart
License: AGPL-3.0
Last Updated: February 3, 2026