mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
test: Add snapshot for sublimeSearch and a first test (no-changelog) (#13794)
This commit is contained in:
3
.vscode/settings.default.json
vendored
3
.vscode/settings.default.json
vendored
@@ -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",
|
||||
|
||||
13
packages/@n8n/utils/src/search/snapshots/README.md
Normal file
13
packages/@n8n/utils/src/search/snapshots/README.md
Normal 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**
|
||||
13255
packages/@n8n/utils/src/search/snapshots/toplevel.snapshot.json
Normal file
13255
packages/@n8n/utils/src/search/snapshots/toplevel.snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
21
packages/@n8n/utils/src/search/sublimeSearch.test.ts
Normal file
21
packages/@n8n/utils/src/search/sublimeSearch.test.ts
Normal 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);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -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 },
|
||||
|
||||
Reference in New Issue
Block a user