@memberjunction/ng-search 5.42.0 → 5.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/module.d.ts +2 -1
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/module.js +10 -3
- package/dist/lib/module.js.map +1 -1
- package/dist/lib/search-filter.component.d.ts +6 -2
- package/dist/lib/search-filter.component.d.ts.map +1 -1
- package/dist/lib/search-filter.component.js +66 -70
- package/dist/lib/search-filter.component.js.map +1 -1
- package/dist/lib/search-overlay.component.js +42 -52
- package/dist/lib/search-overlay.component.js.map +1 -1
- package/dist/lib/search-results.component.js +76 -79
- package/dist/lib/search-results.component.js.map +1 -1
- package/package.json +9 -7
- package/dist/__tests__/search-results.component.test.d.ts +0 -2
- package/dist/__tests__/search-results.component.test.d.ts.map +0 -1
- package/dist/__tests__/search-results.component.test.js +0 -263
- package/dist/__tests__/search-results.component.test.js.map +0 -1
- package/dist/__tests__/search-types.test.d.ts +0 -2
- package/dist/__tests__/search-types.test.d.ts.map +0 -1
- package/dist/__tests__/search-types.test.js +0 -111
- package/dist/__tests__/search-types.test.js.map +0 -1
- package/dist/__tests__/search.service.test.d.ts +0 -2
- package/dist/__tests__/search.service.test.d.ts.map +0 -1
- package/dist/__tests__/search.service.test.js +0 -438
- package/dist/__tests__/search.service.test.js.map +0 -1
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
describe('Search Types', () => {
|
|
3
|
-
describe('SearchResultItem', () => {
|
|
4
|
-
it('should be constructable with all required fields', () => {
|
|
5
|
-
const item = {
|
|
6
|
-
ID: 'test-1',
|
|
7
|
-
Title: 'Test Result',
|
|
8
|
-
Snippet: 'A snippet of matching text',
|
|
9
|
-
EntityName: 'Contacts',
|
|
10
|
-
RecordID: 'rec-123',
|
|
11
|
-
SourceType: 'entity',
|
|
12
|
-
ResultType: 'entity-record',
|
|
13
|
-
Score: 0.85,
|
|
14
|
-
ScoreBreakdown: { Vector: 0.8, FullText: 0.9 },
|
|
15
|
-
Tags: ['customer', 'active'],
|
|
16
|
-
SourceIcon: 'fa-solid fa-database',
|
|
17
|
-
MatchedAt: new Date()
|
|
18
|
-
};
|
|
19
|
-
expect(item.ID).toBe('test-1');
|
|
20
|
-
expect(item.Score).toBe(0.85);
|
|
21
|
-
expect(item.Tags).toHaveLength(2);
|
|
22
|
-
expect(item.SourceType).toBe('entity');
|
|
23
|
-
expect(item.ResultType).toBe('entity-record');
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('SearchResultGroup', () => {
|
|
27
|
-
it('should group results by source type', () => {
|
|
28
|
-
const group = {
|
|
29
|
-
Label: 'Entity Records',
|
|
30
|
-
Icon: 'fa-solid fa-database',
|
|
31
|
-
SourceType: 'entity',
|
|
32
|
-
Results: [],
|
|
33
|
-
TotalCount: 0
|
|
34
|
-
};
|
|
35
|
-
expect(group.SourceType).toBe('entity');
|
|
36
|
-
expect(group.Results).toHaveLength(0);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe('SearchFilter', () => {
|
|
40
|
-
it('should support multi-select filter options', () => {
|
|
41
|
-
const filter = {
|
|
42
|
-
Category: 'Source Type',
|
|
43
|
-
Options: [
|
|
44
|
-
{ Label: 'Entities', Value: 'entity', Count: 5, IsSelected: true },
|
|
45
|
-
{ Label: 'Files', Value: 'file', Count: 3, IsSelected: false }
|
|
46
|
-
],
|
|
47
|
-
MultiSelect: true
|
|
48
|
-
};
|
|
49
|
-
expect(filter.MultiSelect).toBe(true);
|
|
50
|
-
expect(filter.Options).toHaveLength(2);
|
|
51
|
-
expect(filter.Options[0].IsSelected).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('SearchRequest', () => {
|
|
55
|
-
it('should support filter configuration', () => {
|
|
56
|
-
const request = {
|
|
57
|
-
Query: 'test query',
|
|
58
|
-
MaxResults: 25,
|
|
59
|
-
ActiveFilters: {
|
|
60
|
-
'Source Type': ['entity', 'file'],
|
|
61
|
-
'Entity': ['Contacts']
|
|
62
|
-
},
|
|
63
|
-
IncludeSources: ['vector', 'fulltext']
|
|
64
|
-
};
|
|
65
|
-
expect(request.ActiveFilters['Source Type']).toHaveLength(2);
|
|
66
|
-
expect(request.IncludeSources).not.toContain('entity');
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('SearchResponse', () => {
|
|
70
|
-
it('should include source counts', () => {
|
|
71
|
-
const response = {
|
|
72
|
-
Success: true,
|
|
73
|
-
Results: [],
|
|
74
|
-
Groups: [],
|
|
75
|
-
Filters: [],
|
|
76
|
-
TotalCount: 42,
|
|
77
|
-
ElapsedMs: 150,
|
|
78
|
-
SourceCounts: { Vector: 20, FullText: 15, Entity: 7, Storage: 0 },
|
|
79
|
-
Providers: []
|
|
80
|
-
};
|
|
81
|
-
expect(response.Success).toBe(true);
|
|
82
|
-
expect(response.SourceCounts.Vector + response.SourceCounts.FullText + response.SourceCounts.Entity).toBe(42);
|
|
83
|
-
});
|
|
84
|
-
it('should support error state', () => {
|
|
85
|
-
const response = {
|
|
86
|
-
Success: false,
|
|
87
|
-
Results: [],
|
|
88
|
-
Groups: [],
|
|
89
|
-
Filters: [],
|
|
90
|
-
TotalCount: 0,
|
|
91
|
-
ElapsedMs: 0,
|
|
92
|
-
SourceCounts: { Vector: 0, FullText: 0, Entity: 0, Storage: 0 },
|
|
93
|
-
Providers: [],
|
|
94
|
-
ErrorMessage: 'Search service unavailable'
|
|
95
|
-
};
|
|
96
|
-
expect(response.Success).toBe(false);
|
|
97
|
-
expect(response.ErrorMessage).toBeDefined();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe('ScoreBreakdown', () => {
|
|
101
|
-
it('should support partial score sources', () => {
|
|
102
|
-
const breakdown = {
|
|
103
|
-
Vector: 0.92
|
|
104
|
-
};
|
|
105
|
-
expect(breakdown.Vector).toBe(0.92);
|
|
106
|
-
expect(breakdown.FullText).toBeUndefined();
|
|
107
|
-
expect(breakdown.Entity).toBeUndefined();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
//# sourceMappingURL=search-types.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-types.test.js","sourceRoot":"","sources":["../../src/__tests__/search-types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAc9C,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC1B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YACxD,MAAM,IAAI,GAAqB;gBAC3B,EAAE,EAAE,QAAQ;gBACZ,KAAK,EAAE,aAAa;gBACpB,OAAO,EAAE,4BAA4B;gBACrC,UAAU,EAAE,UAAU;gBACtB,QAAQ,EAAE,SAAS;gBACnB,UAAU,EAAE,QAAQ;gBACpB,UAAU,EAAE,eAAe;gBAC3B,KAAK,EAAE,IAAI;gBACX,cAAc,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE;gBAC9C,IAAI,EAAE,CAAC,UAAU,EAAE,QAAQ,CAAC;gBAC5B,UAAU,EAAE,sBAAsB;gBAClC,SAAS,EAAE,IAAI,IAAI,EAAE;aACxB,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC/B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvC,MAAM,CAAC,IA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earchFilterOption,\n SearchRequest,\n SearchResponse,\n SearchResultSelectedEvent,\n SearchFilterChangeEvent,\n SearchExecutedEvent,\n ScoreBreakdown\n} from '../lib/search-types';\n\ndescribe('Search Types', () => {\n describe('SearchResultItem', () => {\n it('should be constructable with all required fields', () => {\n const item: SearchResultItem = {\n ID: 'test-1',\n Title: 'Test Result',\n Snippet: 'A snippet of matching text',\n EntityName: 'Contacts',\n RecordID: 'rec-123',\n SourceType: 'entity',\n ResultType: 'entity-record',\n Score: 0.85,\n ScoreBreakdown: { Vector: 0.8, FullText: 0.9 },\n Tags: ['customer', 'active'],\n SourceIcon: 'fa-solid fa-database',\n MatchedAt: new Date()\n };\n\n expect(item.ID).toBe('test-1');\n expect(item.Score).toBe(0.85);\n expect(item.Tags).toHaveLength(2);\n expect(item.SourceType).toBe('entity');\n expect(item.ResultType).toBe('entity-record');\n });\n });\n\n describe('SearchResultGroup', () => {\n it('should group results by source type', () => {\n const group: SearchResultGroup = {\n Label: 'Entity Records',\n Icon: 'fa-solid fa-database',\n SourceType: 'entity',\n Results: [],\n TotalCount: 0\n };\n\n expect(group.SourceType).toBe('entity');\n expect(group.Results).toHaveLength(0);\n });\n });\n\n describe('SearchFilter', () => {\n it('should support multi-select filter options', () => {\n const filter: SearchFilter = {\n Category: 'Source Type',\n Options: [\n { Label: 'Entities', Value: 'entity', Count: 5, IsSelected: true },\n { Label: 'Files', Value: 'file', Count: 3, IsSelected: false }\n ],\n MultiSelect: true\n };\n\n expect(filter.MultiSelect).toBe(true);\n expect(filter.Options).toHaveLength(2);\n expect(filter.Options[0].IsSelected).toBe(true);\n });\n });\n\n describe('SearchRequest', () => {\n it('should support filter configuration', () => {\n const request: SearchRequest = {\n Query: 'test query',\n MaxResults: 25,\n ActiveFilters: {\n 'Source Type': ['entity', 'file'],\n 'Entity': ['Contacts']\n },\n IncludeSources: ['vector', 'fulltext']\n };\n\n expect(request.ActiveFilters['Source Type']).toHaveLength(2);\n expect(request.IncludeSources).not.toContain('entity');\n });\n });\n\n describe('SearchResponse', () => {\n it('should include source counts', () => {\n const response: SearchResponse = {\n Success: true,\n Results: [],\n Groups: [],\n Filters: [],\n TotalCount: 42,\n ElapsedMs: 150,\n SourceCounts: { Vector: 20, FullText: 15, Entity: 7, Storage: 0 },\n Providers: []\n };\n\n expect(response.Success).toBe(true);\n expect(response.SourceCounts.Vector + response.SourceCounts.FullText + response.SourceCounts.Entity).toBe(42);\n });\n\n it('should support error state', () => {\n const response: SearchResponse = {\n Success: false,\n Results: [],\n Groups: [],\n Filters: [],\n TotalCount: 0,\n ElapsedMs: 0,\n SourceCounts: { Vector: 0, FullText: 0, Entity: 0, Storage: 0 },\n Providers: [],\n ErrorMessage: 'Search service unavailable'\n };\n\n expect(response.Success).toBe(false);\n expect(response.ErrorMessage).toBeDefined();\n });\n });\n\n describe('ScoreBreakdown', () => {\n it('should support partial score sources', () => {\n const breakdown: ScoreBreakdown = {\n Vector: 0.92\n };\n\n expect(breakdown.Vector).toBe(0.92);\n expect(breakdown.FullText).toBeUndefined();\n expect(breakdown.Entity).toBeUndefined();\n });\n });\n});\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.service.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/search.service.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import { Subject } from 'rxjs';
|
|
3
|
-
import { Metadata } from '@memberjunction/core';
|
|
4
|
-
import { GraphQLDataProvider, GraphQLSearchClient } from '@memberjunction/graphql-dataprovider';
|
|
5
|
-
import { SearchService } from '../lib/search.service';
|
|
6
|
-
/**
|
|
7
|
-
* Installs a fake Metadata.Provider that passes the `instanceof GraphQLDataProvider` check
|
|
8
|
-
* and stubs GraphQLSearchClient.ExecuteSearch to return empty success.
|
|
9
|
-
*/
|
|
10
|
-
function installMockProvider() {
|
|
11
|
-
const mockExecuteSearch = vi.fn().mockResolvedValue({
|
|
12
|
-
Success: true,
|
|
13
|
-
Results: [],
|
|
14
|
-
TotalCount: 0,
|
|
15
|
-
ElapsedMs: 1,
|
|
16
|
-
SourceCounts: { Vector: 0, FullText: 0, Entity: 0, Storage: 0 },
|
|
17
|
-
});
|
|
18
|
-
// Create a mock that passes `instanceof GraphQLDataProvider`
|
|
19
|
-
const mockProvider = Object.create(GraphQLDataProvider.prototype);
|
|
20
|
-
Metadata['Provider'] = mockProvider;
|
|
21
|
-
// Stub GraphQLSearchClient.prototype so the service's `new GraphQLSearchClient(provider)` works
|
|
22
|
-
vi.spyOn(GraphQLSearchClient.prototype, 'ExecuteSearch').mockImplementation(mockExecuteSearch);
|
|
23
|
-
vi.spyOn(GraphQLSearchClient.prototype, 'PreviewSearch').mockImplementation(mockExecuteSearch);
|
|
24
|
-
return mockExecuteSearch;
|
|
25
|
-
}
|
|
26
|
-
describe('SearchService', () => {
|
|
27
|
-
let service;
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
service = new SearchService();
|
|
30
|
-
installMockProvider();
|
|
31
|
-
});
|
|
32
|
-
describe('ExecuteSearch', () => {
|
|
33
|
-
it('should set IsSearching to true during search', async () => {
|
|
34
|
-
const values = [];
|
|
35
|
-
service.IsSearching$.subscribe(val => values.push(val));
|
|
36
|
-
await service.ExecuteSearch({
|
|
37
|
-
Query: 'test query',
|
|
38
|
-
MaxResults: 10,
|
|
39
|
-
ActiveFilters: {},
|
|
40
|
-
IncludeSources: ['vector', 'fulltext', 'entity']
|
|
41
|
-
});
|
|
42
|
-
// Should have gone true then false
|
|
43
|
-
expect(values).toContain(true);
|
|
44
|
-
expect(values[values.length - 1]).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
it('should return empty results for empty query', async () => {
|
|
47
|
-
const response = await service.ExecuteSearch({
|
|
48
|
-
Query: ' ',
|
|
49
|
-
MaxResults: 10,
|
|
50
|
-
ActiveFilters: {},
|
|
51
|
-
IncludeSources: ['vector']
|
|
52
|
-
});
|
|
53
|
-
expect(response.Success).toBe(true);
|
|
54
|
-
expect(response.Results).toHaveLength(0);
|
|
55
|
-
expect(response.TotalCount).toBe(0);
|
|
56
|
-
});
|
|
57
|
-
it('should update SearchResults$ observable', async () => {
|
|
58
|
-
await service.ExecuteSearch({
|
|
59
|
-
Query: 'test',
|
|
60
|
-
MaxResults: 10,
|
|
61
|
-
ActiveFilters: {},
|
|
62
|
-
IncludeSources: ['vector']
|
|
63
|
-
});
|
|
64
|
-
const result = service.SearchResults$.value;
|
|
65
|
-
expect(result).not.toBeNull();
|
|
66
|
-
expect(result?.Success).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
it('should add to recent searches', async () => {
|
|
69
|
-
await service.ExecuteSearch({
|
|
70
|
-
Query: 'test query',
|
|
71
|
-
MaxResults: 10,
|
|
72
|
-
ActiveFilters: {},
|
|
73
|
-
IncludeSources: ['vector']
|
|
74
|
-
});
|
|
75
|
-
const recent = service.RecentSearches$.value;
|
|
76
|
-
expect(recent.length).toBe(1);
|
|
77
|
-
expect(recent[0].Query).toBe('test query');
|
|
78
|
-
});
|
|
79
|
-
it('should deduplicate recent searches', async () => {
|
|
80
|
-
const request = {
|
|
81
|
-
Query: 'test',
|
|
82
|
-
MaxResults: 10,
|
|
83
|
-
ActiveFilters: {},
|
|
84
|
-
IncludeSources: ['vector']
|
|
85
|
-
};
|
|
86
|
-
await service.ExecuteSearch(request);
|
|
87
|
-
await service.ExecuteSearch(request);
|
|
88
|
-
const recent = service.RecentSearches$.value;
|
|
89
|
-
expect(recent.length).toBe(1);
|
|
90
|
-
});
|
|
91
|
-
it('should limit recent searches to max 20', async () => {
|
|
92
|
-
for (let i = 0; i < 25; i++) {
|
|
93
|
-
await service.ExecuteSearch({
|
|
94
|
-
Query: `query ${i}`,
|
|
95
|
-
MaxResults: 10,
|
|
96
|
-
ActiveFilters: {},
|
|
97
|
-
IncludeSources: ['vector']
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
expect(service.RecentSearches$.value.length).toBeLessThanOrEqual(20);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
describe('StreamSearch', () => {
|
|
104
|
-
it('forwards Phase, ProviderName, and ElapsedMs unchanged and maps client results through mapClientResultItem', () => {
|
|
105
|
-
const stream$ = new Subject();
|
|
106
|
-
vi.spyOn(GraphQLSearchClient.prototype, 'StreamSearch').mockReturnValue(stream$);
|
|
107
|
-
const events = [];
|
|
108
|
-
const sub = service.StreamSearch({
|
|
109
|
-
Query: 'streamed query',
|
|
110
|
-
MaxResults: 10,
|
|
111
|
-
ActiveFilters: {},
|
|
112
|
-
IncludeSources: ['vector', 'fulltext']
|
|
113
|
-
}).subscribe({
|
|
114
|
-
next: ev => events.push(ev),
|
|
115
|
-
});
|
|
116
|
-
stream$.next({ StreamID: 'sid-1', Phase: 'provider', ProviderName: 'Vector', Results: [makeClientResultItem('a', 'fast-row')], ElapsedMs: 12 });
|
|
117
|
-
stream$.next({ StreamID: 'sid-1', Phase: 'fused', Results: [makeClientResultItem('a', 'fast-row'), makeClientResultItem('b', 'slow-row')], ElapsedMs: 50 });
|
|
118
|
-
stream$.next({ StreamID: 'sid-1', Phase: 'final', Results: [makeClientResultItem('a', 'fast-row'), makeClientResultItem('b', 'slow-row')], ElapsedMs: 75 });
|
|
119
|
-
expect(events).toHaveLength(3);
|
|
120
|
-
expect(events[0].Phase).toBe('provider');
|
|
121
|
-
expect(events[0].ProviderName).toBe('Vector');
|
|
122
|
-
expect(events[0].ElapsedMs).toBe(12);
|
|
123
|
-
// mapClientResultItem prefers RecordName over Title and unwraps RawMetadata; assert one mapped field
|
|
124
|
-
expect(events[0].Results?.[0].Title).toBe('fast-row');
|
|
125
|
-
expect(events[0].Results?.[0].MatchedAt).toBeInstanceOf(Date);
|
|
126
|
-
expect(events[1].Phase).toBe('fused');
|
|
127
|
-
expect(events[1].Results).toHaveLength(2);
|
|
128
|
-
expect(events[2].Phase).toBe('final');
|
|
129
|
-
expect(events[2].ElapsedMs).toBe(75);
|
|
130
|
-
sub.unsubscribe();
|
|
131
|
-
});
|
|
132
|
-
it('omits Results from emitted event when the wire frame has no Results', () => {
|
|
133
|
-
const stream$ = new Subject();
|
|
134
|
-
vi.spyOn(GraphQLSearchClient.prototype, 'StreamSearch').mockReturnValue(stream$);
|
|
135
|
-
const events = [];
|
|
136
|
-
const sub = service.StreamSearch({
|
|
137
|
-
Query: 'no-results phase',
|
|
138
|
-
MaxResults: 5,
|
|
139
|
-
ActiveFilters: {},
|
|
140
|
-
IncludeSources: ['vector']
|
|
141
|
-
}).subscribe({
|
|
142
|
-
next: ev => events.push(ev),
|
|
143
|
-
});
|
|
144
|
-
// 'reranked' phase server-side may carry no Results (it just signals the rerank step ran)
|
|
145
|
-
stream$.next({ StreamID: 'sid-2', Phase: 'reranked', ElapsedMs: 30 });
|
|
146
|
-
expect(events).toHaveLength(1);
|
|
147
|
-
expect(events[0].Phase).toBe('reranked');
|
|
148
|
-
expect(events[0].Results).toBeUndefined();
|
|
149
|
-
sub.unsubscribe();
|
|
150
|
-
});
|
|
151
|
-
it('propagates errors from the underlying client observable', () => {
|
|
152
|
-
const stream$ = new Subject();
|
|
153
|
-
vi.spyOn(GraphQLSearchClient.prototype, 'StreamSearch').mockReturnValue(stream$);
|
|
154
|
-
let captured = null;
|
|
155
|
-
const sub = service.StreamSearch({
|
|
156
|
-
Query: 'error path',
|
|
157
|
-
MaxResults: 5,
|
|
158
|
-
ActiveFilters: {},
|
|
159
|
-
IncludeSources: ['vector']
|
|
160
|
-
}).subscribe({
|
|
161
|
-
next: () => { },
|
|
162
|
-
error: err => { captured = err; },
|
|
163
|
-
});
|
|
164
|
-
stream$.error(new Error('upstream blew up'));
|
|
165
|
-
expect(captured).not.toBeNull();
|
|
166
|
-
expect(captured.message).toBe('upstream blew up');
|
|
167
|
-
sub.unsubscribe();
|
|
168
|
-
});
|
|
169
|
-
it('errors when no GraphQL provider is available (e.g., Metadata.Provider not yet bootstrapped)', () => {
|
|
170
|
-
Metadata['Provider'] = {}; // not a GraphQLDataProvider
|
|
171
|
-
let captured = null;
|
|
172
|
-
const sub = service.StreamSearch({
|
|
173
|
-
Query: 'no provider',
|
|
174
|
-
MaxResults: 5,
|
|
175
|
-
ActiveFilters: {},
|
|
176
|
-
IncludeSources: ['vector']
|
|
177
|
-
}).subscribe({
|
|
178
|
-
next: () => { },
|
|
179
|
-
error: err => { captured = err; },
|
|
180
|
-
});
|
|
181
|
-
expect(captured).not.toBeNull();
|
|
182
|
-
expect(captured.message).toBe('GraphQL provider not available');
|
|
183
|
-
sub.unsubscribe();
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
describe('ClearResults', () => {
|
|
187
|
-
it('should set SearchResults$ to null', async () => {
|
|
188
|
-
await service.ExecuteSearch({
|
|
189
|
-
Query: 'test',
|
|
190
|
-
MaxResults: 10,
|
|
191
|
-
ActiveFilters: {},
|
|
192
|
-
IncludeSources: ['vector']
|
|
193
|
-
});
|
|
194
|
-
service.ClearResults();
|
|
195
|
-
expect(service.SearchResults$.value).toBeNull();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
describe('ClearRecentSearches', () => {
|
|
199
|
-
it('should clear all recent searches', async () => {
|
|
200
|
-
await service.ExecuteSearch({
|
|
201
|
-
Query: 'test',
|
|
202
|
-
MaxResults: 10,
|
|
203
|
-
ActiveFilters: {},
|
|
204
|
-
IncludeSources: ['vector']
|
|
205
|
-
});
|
|
206
|
-
service.ClearRecentSearches();
|
|
207
|
-
expect(service.RecentSearches$.value).toHaveLength(0);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
describe('GroupResults', () => {
|
|
211
|
-
it('should group results by source type', () => {
|
|
212
|
-
const results = [
|
|
213
|
-
createMockResult('1', 'entity', 'Contacts'),
|
|
214
|
-
createMockResult('2', 'entity', 'Contacts'),
|
|
215
|
-
createMockResult('3', 'file', 'Documents'),
|
|
216
|
-
createMockResult('4', 'web-page', 'Pages'),
|
|
217
|
-
];
|
|
218
|
-
const groups = service.GroupResults(results);
|
|
219
|
-
expect(groups).toHaveLength(3);
|
|
220
|
-
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
221
|
-
expect(entityGroup?.Results).toHaveLength(2);
|
|
222
|
-
expect(entityGroup?.Label).toBe('Database');
|
|
223
|
-
});
|
|
224
|
-
it('should return empty array for empty input', () => {
|
|
225
|
-
const groups = service.GroupResults([]);
|
|
226
|
-
expect(groups).toHaveLength(0);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
describe('BuildFilters', () => {
|
|
230
|
-
it('should build source type, entity, and tag filters', () => {
|
|
231
|
-
const results = [
|
|
232
|
-
createMockResult('1', 'entity', 'Contacts', ['customer']),
|
|
233
|
-
createMockResult('2', 'file', 'Documents', ['internal']),
|
|
234
|
-
];
|
|
235
|
-
const filters = service.BuildFilters(results);
|
|
236
|
-
expect(filters).toHaveLength(3);
|
|
237
|
-
const sourceFilter = filters.find(f => f.Category === 'Source');
|
|
238
|
-
expect(sourceFilter?.Options).toHaveLength(2);
|
|
239
|
-
});
|
|
240
|
-
it('should limit tags filter to 15 options', () => {
|
|
241
|
-
const tags = Array.from({ length: 20 }, (_, i) => `tag${i}`);
|
|
242
|
-
const results = tags.map((tag, i) => createMockResult(String(i), 'entity', 'Test', [tag]));
|
|
243
|
-
const filters = service.BuildFilters(results);
|
|
244
|
-
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
245
|
-
expect(tagFilter.Options.length).toBeLessThanOrEqual(15);
|
|
246
|
-
});
|
|
247
|
-
it('should generate correct tag filter options with counts and icon', () => {
|
|
248
|
-
const results = [
|
|
249
|
-
createMockResult('1', 'entity', 'Contacts', ['crm', 'active']),
|
|
250
|
-
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
251
|
-
createMockResult('3', 'file', 'Docs', ['internal']),
|
|
252
|
-
];
|
|
253
|
-
const filters = service.BuildFilters(results);
|
|
254
|
-
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
255
|
-
expect(tagFilter).toBeDefined();
|
|
256
|
-
expect(tagFilter.MultiSelect).toBe(true);
|
|
257
|
-
// 'crm' appears in 2 results, should be sorted first
|
|
258
|
-
const crmOption = tagFilter.Options.find(o => o.Value === 'crm');
|
|
259
|
-
expect(crmOption).toBeDefined();
|
|
260
|
-
expect(crmOption.Count).toBe(2);
|
|
261
|
-
expect(crmOption.Icon).toBe('fa-solid fa-tag');
|
|
262
|
-
expect(crmOption.IsSelected).toBe(false);
|
|
263
|
-
// 'active' and 'internal' each appear once
|
|
264
|
-
const activeOption = tagFilter.Options.find(o => o.Value === 'active');
|
|
265
|
-
expect(activeOption.Count).toBe(1);
|
|
266
|
-
const internalOption = tagFilter.Options.find(o => o.Value === 'internal');
|
|
267
|
-
expect(internalOption.Count).toBe(1);
|
|
268
|
-
});
|
|
269
|
-
it('should omit Tags filter when no results have tags', () => {
|
|
270
|
-
const results = [
|
|
271
|
-
createMockResult('1', 'entity', 'Contacts'),
|
|
272
|
-
createMockResult('2', 'entity', 'Companies'),
|
|
273
|
-
];
|
|
274
|
-
const filters = service.BuildFilters(results);
|
|
275
|
-
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
276
|
-
expect(tagFilter).toBeUndefined(); // Empty categories are filtered out
|
|
277
|
-
});
|
|
278
|
-
it('should sort tags by count descending', () => {
|
|
279
|
-
const results = [
|
|
280
|
-
createMockResult('1', 'entity', 'A', ['rare', 'common']),
|
|
281
|
-
createMockResult('2', 'entity', 'B', ['common']),
|
|
282
|
-
createMockResult('3', 'entity', 'C', ['common']),
|
|
283
|
-
];
|
|
284
|
-
const filters = service.BuildFilters(results);
|
|
285
|
-
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
286
|
-
expect(tagFilter.Options[0].Value).toBe('common');
|
|
287
|
-
expect(tagFilter.Options[0].Count).toBe(3);
|
|
288
|
-
expect(tagFilter.Options[1].Value).toBe('rare');
|
|
289
|
-
expect(tagFilter.Options[1].Count).toBe(1);
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
describe('GetSourceIcon', () => {
|
|
293
|
-
it('should return correct icon for known types', () => {
|
|
294
|
-
expect(service.GetSourceIcon('entity')).toContain('fa-database');
|
|
295
|
-
expect(service.GetSourceIcon('file')).toContain('fa-file');
|
|
296
|
-
expect(service.GetSourceIcon('web-page')).toContain('fa-globe');
|
|
297
|
-
});
|
|
298
|
-
it('should return fallback icon for unknown types', () => {
|
|
299
|
-
expect(service.GetSourceIcon('unknown')).toContain('fa-circle');
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
// ═══════════════════════════════════════════════════════════════
|
|
303
|
-
// SR-3 Bug Fix: BuildFilters should preserve all options from full result set
|
|
304
|
-
// ═══════════════════════════════════════════════════════════════
|
|
305
|
-
describe('BuildFilters (SR-3: filter options from full result set)', () => {
|
|
306
|
-
it('should include all entity names even when results are filtered', () => {
|
|
307
|
-
// Full result set with 3 entities
|
|
308
|
-
const fullResults = [
|
|
309
|
-
createMockResult('1', 'entity', 'Contacts', ['crm']),
|
|
310
|
-
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
311
|
-
createMockResult('3', 'entity', 'Deals', ['sales']),
|
|
312
|
-
];
|
|
313
|
-
// Build filters from FULL set (this is what the fix does)
|
|
314
|
-
const filters = service.BuildFilters(fullResults);
|
|
315
|
-
const entityFilter = filters.find(f => f.Category === 'Entity');
|
|
316
|
-
// All 3 entities should appear in filter options
|
|
317
|
-
expect(entityFilter?.Options).toHaveLength(3);
|
|
318
|
-
expect(entityFilter?.Options.map(o => o.Value)).toContain('Contacts');
|
|
319
|
-
expect(entityFilter?.Options.map(o => o.Value)).toContain('Companies');
|
|
320
|
-
expect(entityFilter?.Options.map(o => o.Value)).toContain('Deals');
|
|
321
|
-
});
|
|
322
|
-
it('should count tags correctly across all results', () => {
|
|
323
|
-
const results = [
|
|
324
|
-
createMockResult('1', 'entity', 'Contacts', ['crm', 'sales']),
|
|
325
|
-
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
326
|
-
createMockResult('3', 'entity', 'Deals', ['sales', 'pipeline']),
|
|
327
|
-
];
|
|
328
|
-
const filters = service.BuildFilters(results);
|
|
329
|
-
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
330
|
-
// 'crm' appears in 2 results, 'sales' in 2, 'pipeline' in 1
|
|
331
|
-
expect(tagFilter?.Options).toHaveLength(3);
|
|
332
|
-
const crmOption = tagFilter?.Options.find(o => o.Value === 'crm');
|
|
333
|
-
expect(crmOption?.Count).toBe(2);
|
|
334
|
-
});
|
|
335
|
-
it('should not lose filter options when building from subset vs full set', () => {
|
|
336
|
-
const fullResults = [
|
|
337
|
-
createMockResult('1', 'entity', 'Contacts'),
|
|
338
|
-
createMockResult('2', 'entity', 'Companies'),
|
|
339
|
-
createMockResult('3', 'file', 'Documents'),
|
|
340
|
-
];
|
|
341
|
-
// Simulating filtering to only Contacts
|
|
342
|
-
const filteredResults = fullResults.filter(r => r.EntityName === 'Contacts');
|
|
343
|
-
// Building from filtered set loses Companies and Documents
|
|
344
|
-
const filteredFilters = service.BuildFilters(filteredResults);
|
|
345
|
-
const filteredEntityFilter = filteredFilters.find(f => f.Category === 'Entity');
|
|
346
|
-
expect(filteredEntityFilter?.Options).toHaveLength(1); // Only Contacts
|
|
347
|
-
// Building from full set preserves all options (the fix)
|
|
348
|
-
const fullFilters = service.BuildFilters(fullResults);
|
|
349
|
-
const fullEntityFilter = fullFilters.find(f => f.Category === 'Entity');
|
|
350
|
-
expect(fullEntityFilter?.Options).toHaveLength(3); // Contacts + Companies + Documents
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
// ═══════════════════════════════════════════════════════════════
|
|
354
|
-
// SR-4 Bug Fix: GroupResults should sort within groups by score
|
|
355
|
-
// ═══════════════════════════════════════════════════════════════
|
|
356
|
-
describe('GroupResults (SR-4: grouping and sorting)', () => {
|
|
357
|
-
it('should group results by source type with correct labels', () => {
|
|
358
|
-
const results = [
|
|
359
|
-
{ ...createMockResult('1', 'entity', 'Contacts'), Score: 0.9 },
|
|
360
|
-
{ ...createMockResult('2', 'content-item', 'Items'), Score: 0.8 },
|
|
361
|
-
{ ...createMockResult('3', 'entity', 'Companies'), Score: 0.7 },
|
|
362
|
-
];
|
|
363
|
-
const groups = service.GroupResults(results);
|
|
364
|
-
expect(groups).toHaveLength(2);
|
|
365
|
-
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
366
|
-
expect(entityGroup?.Label).toBe('Database');
|
|
367
|
-
expect(entityGroup?.TotalCount).toBe(2);
|
|
368
|
-
const contentGroup = groups.find(g => g.SourceType === 'content-item');
|
|
369
|
-
expect(contentGroup?.Label).toBe('Content Items');
|
|
370
|
-
expect(contentGroup?.TotalCount).toBe(1);
|
|
371
|
-
});
|
|
372
|
-
it('should use fallback label for unknown source types', () => {
|
|
373
|
-
const results = [
|
|
374
|
-
createMockResult('1', 'entity', 'Test'),
|
|
375
|
-
];
|
|
376
|
-
// Hack source type to unknown
|
|
377
|
-
results[0]['SourceType'] = 'custom-type';
|
|
378
|
-
const groups = service.GroupResults(results);
|
|
379
|
-
expect(groups[0].Label).toBe('custom-type'); // Falls back to raw type name
|
|
380
|
-
});
|
|
381
|
-
it('should use fallback icon for unknown source types', () => {
|
|
382
|
-
const results = [
|
|
383
|
-
createMockResult('1', 'entity', 'Test'),
|
|
384
|
-
];
|
|
385
|
-
results[0]['SourceType'] = 'unknown-source';
|
|
386
|
-
const groups = service.GroupResults(results);
|
|
387
|
-
expect(groups[0].Icon).toBe('fa-solid fa-circle');
|
|
388
|
-
});
|
|
389
|
-
it('should handle mixed known and unknown source types', () => {
|
|
390
|
-
const results = [
|
|
391
|
-
createMockResult('1', 'entity', 'Contacts'),
|
|
392
|
-
createMockResult('2', 'entity', 'Companies'),
|
|
393
|
-
];
|
|
394
|
-
results[1]['SourceType'] = 'custom-plugin';
|
|
395
|
-
const groups = service.GroupResults(results);
|
|
396
|
-
expect(groups).toHaveLength(2);
|
|
397
|
-
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
398
|
-
expect(entityGroup?.Label).toBe('Database');
|
|
399
|
-
const customGroup = groups.find(g => g.SourceType === 'custom-plugin');
|
|
400
|
-
expect(customGroup?.Label).toBe('custom-plugin');
|
|
401
|
-
expect(customGroup?.Icon).toBe('fa-solid fa-circle');
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
function createMockResult(id, sourceType, entityName, tags = []) {
|
|
406
|
-
return {
|
|
407
|
-
ID: id,
|
|
408
|
-
Title: `Result ${id}`,
|
|
409
|
-
Snippet: `Snippet for result ${id}`,
|
|
410
|
-
EntityName: entityName,
|
|
411
|
-
RecordID: `rec-${id}`,
|
|
412
|
-
SourceType: sourceType,
|
|
413
|
-
ResultType: sourceType === 'file' ? 'storage-file' : 'entity-record',
|
|
414
|
-
Score: 0.85,
|
|
415
|
-
ScoreBreakdown: { Vector: 0.8, FullText: 0.9 },
|
|
416
|
-
Tags: tags,
|
|
417
|
-
SourceIcon: 'fa-solid fa-database',
|
|
418
|
-
MatchedAt: new Date()
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
function makeClientResultItem(id, title) {
|
|
422
|
-
return {
|
|
423
|
-
ID: id,
|
|
424
|
-
EntityName: 'Contacts',
|
|
425
|
-
RecordID: `rec-${id}`,
|
|
426
|
-
SourceType: 'entity',
|
|
427
|
-
Title: title,
|
|
428
|
-
Snippet: `snippet for ${id}`,
|
|
429
|
-
Score: 0.91,
|
|
430
|
-
ScoreBreakdown: { Vector: 0.9, FullText: 0.92 },
|
|
431
|
-
Tags: ['streaming'],
|
|
432
|
-
EntityIcon: 'fa-solid fa-database',
|
|
433
|
-
RecordName: title,
|
|
434
|
-
MatchedAt: new Date().toISOString(),
|
|
435
|
-
ResultType: 'entity-record',
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
//# sourceMappingURL=search.service.test.js.map
|