31 lines
1.9 KiB
JavaScript
31 lines
1.9 KiB
JavaScript
const assert = require('node:assert/strict');
|
|
const test = require('node:test');
|
|
const { pathToFileURL } = require('node:url');
|
|
const path = require('node:path');
|
|
const moduleUrl = pathToFileURL(path.resolve(__dirname, '../../../packages/common/business_components/src/ui/map/layerBulkSelection.js'));
|
|
|
|
test('toggle state follows all, partial, off and empty selections', async () => {
|
|
const { getBulkLayerState } = await import(moduleUrl.href);
|
|
const nodes = [{id:'a',data:{exprsYn:'Y'}},{id:'b',data:{exprsYn:'Y'}},{id:'h',data:{exprsYn:'N'}}];
|
|
assert.deepEqual(getBulkLayerState(nodes, []), {disabled:false,allChecked:false,partiallyChecked:false});
|
|
assert.deepEqual(getBulkLayerState(nodes, ['a']), {disabled:false,allChecked:false,partiallyChecked:true});
|
|
assert.deepEqual(getBulkLayerState(nodes, ['a','b']), {disabled:false,allChecked:true,partiallyChecked:false});
|
|
assert.deepEqual(getBulkLayerState([], []), {disabled:true,allChecked:false,partiallyChecked:false});
|
|
});
|
|
|
|
test('bulk on checks visible parents and children, excluding hidden nodes', async () => {
|
|
const { getBulkLayerSelection } = await import(moduleUrl.href);
|
|
const nodes = [{id:1,data:{exprsYn:'Y'}},{id:2,parent:1,data:{exprsYn:'Y'}},{id:3,data:{exprsYn:'N'}}];
|
|
const result = getBulkLayerSelection(nodes, true);
|
|
assert.deepEqual(result.checkedIds, [1,2]);
|
|
assert.deepEqual(result.uncheckedIds, [3]);
|
|
assert.deepEqual(result.selectedNodes, nodes.slice(0,2));
|
|
});
|
|
test('bulk off clears every registered tree layer, without mutating input', async () => {
|
|
const { getBulkLayerSelection } = await import(moduleUrl.href);
|
|
const nodes = [{id:'a',data:{exprsYn:'Y'}},{id:'hidden',data:{exprsYn:'N'}}];
|
|
assert.deepEqual(getBulkLayerSelection(nodes, false), {checkedIds:[],selectedNodes:[],uncheckedIds:['a','hidden']});
|
|
assert.equal(nodes[0].data.exprsYn, 'Y');
|
|
assert.deepEqual(getBulkLayerSelection([], true), {checkedIds:[],selectedNodes:[],uncheckedIds:[]});
|
|
});
|