mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-03-11 09:12:52 +00:00
feat: pipeline improvements
This commit is contained in:
@@ -12,17 +12,17 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {treeGroupBy} from '../src/index.js';
|
||||
import {expect} from 'chai';
|
||||
import {Tree, treeGroupBy} from '../src/index.js';
|
||||
|
||||
interface TestItem {
|
||||
id: number;
|
||||
path?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {{id: number; path?: string[]}} TestItem
|
||||
* @typedef {import('../src/types.js').Tree<TestItem>} TestItemTree
|
||||
*/
|
||||
describe('tree-group', function () {
|
||||
it('should create a tree', function () {
|
||||
const items: Array<TestItem> = [
|
||||
/** @type {TestItem[]} */
|
||||
const items = [
|
||||
{
|
||||
id: 1,
|
||||
path: ['a', 'b', 'c'],
|
||||
@@ -35,20 +35,22 @@ describe('tree-group', function () {
|
||||
|
||||
const tree = treeGroupBy(items, item => item.path ?? []);
|
||||
|
||||
const expectedTree: Tree<TestItem> = {
|
||||
a: {
|
||||
/** @type {TestItemTree} */
|
||||
const expectedTree = {
|
||||
a: /** @type {TestItemTree} */ ({
|
||||
b: {
|
||||
c: {_: [items[0]]},
|
||||
d: {_: [items[1]]},
|
||||
} as Tree<TestItem>,
|
||||
} as Tree<TestItem>,
|
||||
} as Tree<TestItem>;
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
expect(tree).to.deep.equal(expectedTree);
|
||||
});
|
||||
|
||||
it('should also sort empty paths', () => {
|
||||
const items: Array<TestItem> = [
|
||||
/** @type {TestItem[]} */
|
||||
const items = [
|
||||
{
|
||||
id: 1,
|
||||
path: ['a', 'b', 'c'],
|
||||
@@ -60,14 +62,14 @@ describe('tree-group', function () {
|
||||
|
||||
const tree = treeGroupBy(items, item => item.path ?? []);
|
||||
|
||||
const expectedTree: Tree<TestItem> = {
|
||||
const expectedTree = /** @type {TestItemTree} */ ({
|
||||
a: {
|
||||
b: {
|
||||
c: {_: [items[0]]},
|
||||
} as Tree<TestItem>,
|
||||
} as Tree<TestItem>,
|
||||
},
|
||||
},
|
||||
_: [items[1]],
|
||||
} as Tree<TestItem>;
|
||||
});
|
||||
|
||||
expect(tree).to.deep.equal(expectedTree);
|
||||
});
|
||||
Reference in New Issue
Block a user