When an Owner is selected, the Customer filter options will update to show the corresponding customers, and vice versa
This commit is contained in:
43
tests/dependentFilters.test.cjs
Normal file
43
tests/dependentFilters.test.cjs
Normal 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']);
|
||||
});
|
||||
Reference in New Issue
Block a user