When an Owner is selected, the Customer filter options will update to show the corresponding customers, and vice versa

This commit is contained in:
2026-10-30 16:53:04 -03:00
parent 2363e37aab
commit d689807a50
5 changed files with 130 additions and 33 deletions

View File

@@ -0,0 +1,43 @@
const { test } = require('node:test');
const assert = require('node:assert/strict');
const { loadApplication } = require('./support/application.cjs');
function setup() {
const app = loadApplication('content');
const items = [['A', 'X'], ['A', 'Y'], ['B', 'Y'], ['C', 'Z'], ['A', 'X']].map(([customer, owner]) => ({
CustomerAccount: { PartyId: customer, PartyUniqueName: customer }, Owner: owner
}));
app.opportunitiesTableState.opportunitiesTableState.items = items;
app.opportunitiesFilters.resetCustomerFilter(items);
app.opportunitiesFilters.resetOwnerFilter(items);
return { filters: app.opportunitiesFilters, state: app.opportunitiesFilterState };
}
const labels = options => Array.from(options, option => option.label);
test('customers narrow owners without losing all-owner selection; widening restores options', () => {
const { filters, state } = setup();
state.selectedCustomerKeys = new Set(['party:A']);
assert.deepEqual(labels(filters.getAvailableOwnerOptions()), ['X', 'Y']);
assert.deepEqual(labels(filters.getAvailableCustomerOptions()), ['A', 'B', 'C']);
state.selectedCustomerKeys.add('party:C');
assert.deepEqual(labels(filters.getAvailableOwnerOptions()), ['X', 'Y', 'Z']);
assert.equal(state.selectedOwnerKeys.size, 3);
});
test('owners narrow customers and multi-selection combines their customers', () => {
const { filters, state } = setup();
state.selectedOwnerKeys = new Set(['name:Y']);
assert.deepEqual(labels(filters.getAvailableCustomerOptions()), ['A', 'B']);
assert.deepEqual(labels(filters.getAvailableOwnerOptions()), ['X', 'Y', 'Z']);
state.selectedOwnerKeys.add('name:Z');
assert.deepEqual(labels(filters.getAvailableCustomerOptions()), ['A', 'B', 'C']);
});
test('both filters use the opposite selection, independent of search and stage', () => {
const { filters, state } = setup();
state.selectedOwnerKeys = new Set(['name:Y']);
state.selectedCustomerKeys = new Set(['party:A']);
state.tableSearch = 'no match';
state.selectedStages.clear();
assert.deepEqual(labels(filters.getAvailableCustomerOptions()), ['A', 'B']);
assert.deepEqual(labels(filters.getAvailableOwnerOptions()), ['X', 'Y']);
state.selectedCustomerKeys.clear();
assert.deepEqual(labels(filters.getAvailableOwnerOptions()), []);
assert.deepEqual(labels(filters.getAvailableCustomerOptions()), ['A', 'B']);
});