test: Add snapshot for sublimeSearch and a first test (no-changelog) (#13794)

This commit is contained in:
Charlie Kolb
2025-04-14 11:56:11 +02:00
committed by GitHub
parent e1246ab65c
commit 00038be81a
5 changed files with 13293 additions and 2 deletions

View File

@@ -20,7 +20,8 @@
"search.exclude": {
"node_modules": true,
"dist": true,
"pnpm-lock.yaml": true
"pnpm-lock.yaml": true,
"**/*.snapshot.json": true
},
"typescript.format.enable": false,
"typescript.tsdk": "node_modules/typescript/lib",

View File

@@ -0,0 +1,13 @@
# Search snapshots
This directory contains snapshots containing real data fed into the sublimeSearch function.
These were obtained via `console.log(items)` right before the sublimeSearch call in `editor-ui` (currently in `packages/frontend/editor-ui/src/components/Node/NodeCreator/utils.ts`)
Which is triggered by typing in the search bar in varying states of the application:
- toplevel: From an empty workflow (so missing e.g. tools)
After typing in the search bar you should see an object in the console you can copy via `Right Click->Copy Object" which will cleanly paste to json.
**Please use Chrome for capturing these - the recovered object in Chrome is about 3x larger than in Firefox due to Firefox dropping some nested values**

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
import topLevel from './snapshots/toplevel.snapshot.json';
import { sublimeSearch } from './sublimeSearch';
describe('sublimeSearch', () => {
const testCases = [{ filter: 'agent', expectedOrder: ['Magento 2', 'AI Agent'] }];
test.each(testCases)(
'should return results in the correct order for filter "$filter"',
({ filter, expectedOrder }) => {
const results = sublimeSearch(filter, topLevel, [
{ key: 'properties.displayName', weight: 1.3 },
{ key: 'properties.codex.alias', weight: 1 },
]);
const resultNames = results.map((result) => result.item.properties.displayName);
expectedOrder.forEach((expectedName, index) => {
expect(resultNames[index]).toBe(expectedName);
});
},
);
});

View File

@@ -98,7 +98,8 @@ export function searchNodes(searchFilter: string, items: INodeCreateElement[]) {
// In order to support the old search we need to remove the 'trigger' part
const trimmedFilter = searchFilter.toLowerCase().replace('trigger', '').trimEnd();
// We have a snapshot of this call in sublimeSearch.test.ts to assert practical order for some cases
// Please kindly update the test call if you modify the weights here, and ideally regenerate the snapshot as described in its file.
const result = (
sublimeSearch<INodeCreateElement>(trimmedFilter, items, [
{ key: 'properties.displayName', weight: 1.3 },