@memberjunction/ng-search 5.23.0 → 5.25.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/__tests__/search-results.component.test.d.ts +2 -0
- package/dist/__tests__/search-results.component.test.d.ts.map +1 -0
- package/dist/__tests__/search-results.component.test.js +263 -0
- package/dist/__tests__/search-results.component.test.js.map +1 -0
- package/dist/__tests__/search-types.test.js +6 -2
- package/dist/__tests__/search-types.test.js.map +1 -1
- package/dist/__tests__/search.service.test.js +167 -13
- package/dist/__tests__/search.service.test.js.map +1 -1
- package/dist/lib/module.d.ts +7 -4
- package/dist/lib/module.d.ts.map +1 -1
- package/dist/lib/module.js +19 -4
- package/dist/lib/module.js.map +1 -1
- package/dist/lib/search-composite.component.d.ts +79 -0
- package/dist/lib/search-composite.component.d.ts.map +1 -0
- package/dist/lib/search-composite.component.js +258 -0
- package/dist/lib/search-composite.component.js.map +1 -0
- package/dist/lib/search-filter.component.d.ts +19 -1
- package/dist/lib/search-filter.component.d.ts.map +1 -1
- package/dist/lib/search-filter.component.js +195 -44
- package/dist/lib/search-filter.component.js.map +1 -1
- package/dist/lib/search-input.component.d.ts +61 -0
- package/dist/lib/search-input.component.d.ts.map +1 -0
- package/dist/lib/search-input.component.js +192 -0
- package/dist/lib/search-input.component.js.map +1 -0
- package/dist/lib/search-overlay.component.js +2 -2
- package/dist/lib/search-results.component.d.ts +59 -7
- package/dist/lib/search-results.component.d.ts.map +1 -1
- package/dist/lib/search-results.component.js +530 -176
- package/dist/lib/search-results.component.js.map +1 -1
- package/dist/lib/search-suggest.component.d.ts +95 -0
- package/dist/lib/search-suggest.component.d.ts.map +1 -0
- package/dist/lib/search-suggest.component.js +491 -0
- package/dist/lib/search-suggest.component.js.map +1 -0
- package/dist/lib/search-types.d.ts +29 -1
- package/dist/lib/search-types.d.ts.map +1 -1
- package/dist/lib/search-types.js.map +1 -1
- package/dist/lib/search.service.d.ts +27 -5
- package/dist/lib/search.service.d.ts.map +1 -1
- package/dist/lib/search.service.js +222 -91
- package/dist/lib/search.service.js.map +1 -1
- package/dist/public-api.d.ts +3 -0
- package/dist/public-api.d.ts.map +1 -1
- package/dist/public-api.js +3 -0
- package/dist/public-api.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-results.component.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/search-results.component.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for SearchResultsComponent pure logic:
|
|
3
|
+
* - SR-1: FormatScore consistency
|
|
4
|
+
* - SR-4: Flat mode support
|
|
5
|
+
* - SR-5: Pagination logic
|
|
6
|
+
*
|
|
7
|
+
* We test the logic functions directly without Angular TestBed,
|
|
8
|
+
* extracting them to avoid Angular decorator/inject() issues.
|
|
9
|
+
*/
|
|
10
|
+
import { describe, it, expect } from 'vitest';
|
|
11
|
+
// ── Extract and test pure logic functions from SearchResultsComponent ──
|
|
12
|
+
/** Mirrors SearchResultsComponent.FormatScore */
|
|
13
|
+
function FormatScore(score) {
|
|
14
|
+
return `${Math.round(score * 100)}%`;
|
|
15
|
+
}
|
|
16
|
+
/** Mirrors SearchResultsComponent.FormatTime */
|
|
17
|
+
function FormatTime(ms) {
|
|
18
|
+
if (ms < 1000)
|
|
19
|
+
return `${ms}ms`;
|
|
20
|
+
return `${(ms / 1000).toFixed(1)}s`;
|
|
21
|
+
}
|
|
22
|
+
/** Mirrors SearchResultsComponent.ExtractUrls */
|
|
23
|
+
function ExtractUrls(snippet) {
|
|
24
|
+
if (!snippet)
|
|
25
|
+
return [];
|
|
26
|
+
const urlRegex = /https?:\/\/[^\s,;)>"']+/g;
|
|
27
|
+
const matches = snippet.match(urlRegex);
|
|
28
|
+
return matches ? [...new Set(matches)] : [];
|
|
29
|
+
}
|
|
30
|
+
/** Mirrors SearchResultsComponent.TruncateUrl */
|
|
31
|
+
function TruncateUrl(url) {
|
|
32
|
+
try {
|
|
33
|
+
const parsed = new URL(url);
|
|
34
|
+
const path = parsed.pathname.length > 30
|
|
35
|
+
? parsed.pathname.substring(0, 30) + '...'
|
|
36
|
+
: parsed.pathname;
|
|
37
|
+
return parsed.hostname + path;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return url.length > 50 ? url.substring(0, 50) + '...' : url;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Mirrors SearchResultsComponent pagination logic */
|
|
44
|
+
function getPagedResults(flatResults, currentPage, pageSize) {
|
|
45
|
+
const start = (currentPage - 1) * pageSize;
|
|
46
|
+
return flatResults.slice(start, start + pageSize);
|
|
47
|
+
}
|
|
48
|
+
function getTotalPages(totalResults, pageSize) {
|
|
49
|
+
return Math.ceil(totalResults / pageSize);
|
|
50
|
+
}
|
|
51
|
+
function getPageNumbers(currentPage, totalPages) {
|
|
52
|
+
if (totalPages <= 7)
|
|
53
|
+
return Array.from({ length: totalPages }, (_, i) => i + 1);
|
|
54
|
+
const pages = [1];
|
|
55
|
+
const start = Math.max(2, currentPage - 2);
|
|
56
|
+
const end = Math.min(totalPages - 1, currentPage + 2);
|
|
57
|
+
if (start > 2)
|
|
58
|
+
pages.push(-1);
|
|
59
|
+
for (let i = start; i <= end; i++)
|
|
60
|
+
pages.push(i);
|
|
61
|
+
if (end < totalPages - 1)
|
|
62
|
+
pages.push(-1);
|
|
63
|
+
pages.push(totalPages);
|
|
64
|
+
return pages;
|
|
65
|
+
}
|
|
66
|
+
/** Mirrors SearchResultsComponent group logic */
|
|
67
|
+
function getVisibleResults(group, isExpanded, maxPerGroup) {
|
|
68
|
+
if (isExpanded)
|
|
69
|
+
return group.Results;
|
|
70
|
+
return group.Results.slice(0, maxPerGroup);
|
|
71
|
+
}
|
|
72
|
+
function createResult(id, score) {
|
|
73
|
+
return {
|
|
74
|
+
ID: id, Title: `R${id}`, Snippet: '', EntityName: 'Test',
|
|
75
|
+
RecordID: `rec-${id}`, SourceType: 'entity', Score: score,
|
|
76
|
+
ScoreBreakdown: { Vector: score * 0.6, FullText: score * 0.4 },
|
|
77
|
+
Tags: [], SourceIcon: 'fa-solid fa-database', MatchedAt: new Date(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// ═══════════════════════════════════════════
|
|
81
|
+
// SR-1: FormatScore consistency
|
|
82
|
+
// ═══════════════════════════════════════════
|
|
83
|
+
describe('FormatScore (SR-1)', () => {
|
|
84
|
+
it('should format 0.85 as 85%', () => {
|
|
85
|
+
expect(FormatScore(0.85)).toBe('85%');
|
|
86
|
+
});
|
|
87
|
+
it('should format 1.0 as 100%', () => {
|
|
88
|
+
expect(FormatScore(1.0)).toBe('100%');
|
|
89
|
+
});
|
|
90
|
+
it('should format 0 as 0%', () => {
|
|
91
|
+
expect(FormatScore(0)).toBe('0%');
|
|
92
|
+
});
|
|
93
|
+
it('should round to nearest integer', () => {
|
|
94
|
+
expect(FormatScore(0.856)).toBe('86%');
|
|
95
|
+
expect(FormatScore(0.854)).toBe('85%');
|
|
96
|
+
});
|
|
97
|
+
it('should produce same format for card header and expanded detail (SR-1 fix)', () => {
|
|
98
|
+
// Before the fix, expanded detail used (score * 100).toFixed(0)
|
|
99
|
+
// Now both use FormatScore(score) — same function, same output
|
|
100
|
+
const score = 0.7823;
|
|
101
|
+
expect(FormatScore(score)).toBe('78%');
|
|
102
|
+
});
|
|
103
|
+
it('should match ScoreBreakdown formatting when using same function', () => {
|
|
104
|
+
// Both overall and breakdown scores should use the same format
|
|
105
|
+
const overallScore = 0.85;
|
|
106
|
+
const vectorScore = 0.72;
|
|
107
|
+
expect(FormatScore(overallScore)).toBe('85%');
|
|
108
|
+
expect(FormatScore(vectorScore)).toBe('72%');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
// ═══════════════════════════════════════════
|
|
112
|
+
// SR-5: Pagination
|
|
113
|
+
// ═══════════════════════════════════════════
|
|
114
|
+
describe('Pagination (SR-5)', () => {
|
|
115
|
+
const results = Array.from({ length: 35 }, (_, i) => createResult(String(i + 1), 1 - i * 0.02));
|
|
116
|
+
it('should calculate total pages correctly', () => {
|
|
117
|
+
expect(getTotalPages(35, 10)).toBe(4);
|
|
118
|
+
});
|
|
119
|
+
it('should return first page of results', () => {
|
|
120
|
+
const page = getPagedResults(results, 1, 10);
|
|
121
|
+
expect(page).toHaveLength(10);
|
|
122
|
+
expect(page[0].ID).toBe('1');
|
|
123
|
+
expect(page[9].ID).toBe('10');
|
|
124
|
+
});
|
|
125
|
+
it('should return correct results for page 2', () => {
|
|
126
|
+
const page = getPagedResults(results, 2, 10);
|
|
127
|
+
expect(page).toHaveLength(10);
|
|
128
|
+
expect(page[0].ID).toBe('11');
|
|
129
|
+
});
|
|
130
|
+
it('should return partial last page', () => {
|
|
131
|
+
const page = getPagedResults(results, 4, 10);
|
|
132
|
+
expect(page).toHaveLength(5); // 35 - 30 = 5
|
|
133
|
+
});
|
|
134
|
+
it('should return empty for out-of-range page', () => {
|
|
135
|
+
const page = getPagedResults(results, 100, 10);
|
|
136
|
+
expect(page).toHaveLength(0);
|
|
137
|
+
});
|
|
138
|
+
it('should show all pages when total is 7 or fewer', () => {
|
|
139
|
+
const pages = getPageNumbers(1, 5);
|
|
140
|
+
expect(pages).toEqual([1, 2, 3, 4, 5]);
|
|
141
|
+
expect(pages).not.toContain(-1);
|
|
142
|
+
});
|
|
143
|
+
it('should include ellipsis for many pages', () => {
|
|
144
|
+
const pages = getPageNumbers(8, 15);
|
|
145
|
+
expect(pages[0]).toBe(1);
|
|
146
|
+
expect(pages[pages.length - 1]).toBe(15);
|
|
147
|
+
expect(pages).toContain(-1);
|
|
148
|
+
});
|
|
149
|
+
it('should center current page in page numbers', () => {
|
|
150
|
+
const pages = getPageNumbers(8, 15);
|
|
151
|
+
expect(pages).toContain(8);
|
|
152
|
+
expect(pages).toContain(6); // current - 2
|
|
153
|
+
expect(pages).toContain(10); // current + 2
|
|
154
|
+
});
|
|
155
|
+
it('should handle single page', () => {
|
|
156
|
+
const pages = getPageNumbers(1, 1);
|
|
157
|
+
expect(pages).toEqual([1]);
|
|
158
|
+
});
|
|
159
|
+
it('should handle zero pages', () => {
|
|
160
|
+
expect(getTotalPages(0, 10)).toBe(0);
|
|
161
|
+
});
|
|
162
|
+
it('should handle exact page boundary (e.g. 20 results / 10 per page)', () => {
|
|
163
|
+
const exactResults = Array.from({ length: 20 }, (_, i) => createResult(String(i + 1), 1 - i * 0.02));
|
|
164
|
+
expect(getTotalPages(20, 10)).toBe(2);
|
|
165
|
+
const page1 = getPagedResults(exactResults, 1, 10);
|
|
166
|
+
expect(page1).toHaveLength(10);
|
|
167
|
+
expect(page1[0].ID).toBe('1');
|
|
168
|
+
const page2 = getPagedResults(exactResults, 2, 10);
|
|
169
|
+
expect(page2).toHaveLength(10);
|
|
170
|
+
expect(page2[0].ID).toBe('11');
|
|
171
|
+
// Page 3 should be empty since 20/10 = exactly 2 pages
|
|
172
|
+
const page3 = getPagedResults(exactResults, 3, 10);
|
|
173
|
+
expect(page3).toHaveLength(0);
|
|
174
|
+
});
|
|
175
|
+
it('should return all results on single page when count equals page size', () => {
|
|
176
|
+
const singlePageResults = Array.from({ length: 10 }, (_, i) => createResult(String(i + 1), 0.9));
|
|
177
|
+
expect(getTotalPages(10, 10)).toBe(1);
|
|
178
|
+
const page = getPagedResults(singlePageResults, 1, 10);
|
|
179
|
+
expect(page).toHaveLength(10);
|
|
180
|
+
const pages = getPageNumbers(1, 1);
|
|
181
|
+
expect(pages).toEqual([1]);
|
|
182
|
+
});
|
|
183
|
+
it('should produce correct page numbers at boundary of 7 pages', () => {
|
|
184
|
+
// Exactly 7 pages — should show all, no ellipsis
|
|
185
|
+
const pages7 = getPageNumbers(4, 7);
|
|
186
|
+
expect(pages7).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
|
187
|
+
expect(pages7).not.toContain(-1);
|
|
188
|
+
// 8 pages — should include ellipsis
|
|
189
|
+
const pages8 = getPageNumbers(4, 8);
|
|
190
|
+
expect(pages8[0]).toBe(1);
|
|
191
|
+
expect(pages8[pages8.length - 1]).toBe(8);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
// ═══════════════════════════════════════════
|
|
195
|
+
// Group visibility logic
|
|
196
|
+
// ═══════════════════════════════════════════
|
|
197
|
+
describe('Group visibility', () => {
|
|
198
|
+
const group = {
|
|
199
|
+
Label: 'Test', Icon: 'fa-test', SourceType: 'entity',
|
|
200
|
+
Results: Array.from({ length: 10 }, (_, i) => createResult(String(i), 0.9)),
|
|
201
|
+
TotalCount: 10,
|
|
202
|
+
};
|
|
203
|
+
it('should limit to maxPerGroup when collapsed', () => {
|
|
204
|
+
const visible = getVisibleResults(group, false, 3);
|
|
205
|
+
expect(visible).toHaveLength(3);
|
|
206
|
+
});
|
|
207
|
+
it('should show all when expanded', () => {
|
|
208
|
+
const visible = getVisibleResults(group, true, 3);
|
|
209
|
+
expect(visible).toHaveLength(10);
|
|
210
|
+
});
|
|
211
|
+
it('should show all when results <= maxPerGroup', () => {
|
|
212
|
+
const smallGroup = {
|
|
213
|
+
...group,
|
|
214
|
+
Results: group.Results.slice(0, 2),
|
|
215
|
+
TotalCount: 2,
|
|
216
|
+
};
|
|
217
|
+
const visible = getVisibleResults(smallGroup, false, 5);
|
|
218
|
+
expect(visible).toHaveLength(2);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
// ═══════════════════════════════════════════
|
|
222
|
+
// URL helpers
|
|
223
|
+
// ═══════════════════════════════════════════
|
|
224
|
+
describe('URL helpers', () => {
|
|
225
|
+
it('should extract URLs from text', () => {
|
|
226
|
+
const urls = ExtractUrls('Visit https://example.com and http://test.org/path');
|
|
227
|
+
expect(urls).toHaveLength(2);
|
|
228
|
+
expect(urls).toContain('https://example.com');
|
|
229
|
+
});
|
|
230
|
+
it('should return empty for no URLs', () => {
|
|
231
|
+
expect(ExtractUrls('no urls here')).toHaveLength(0);
|
|
232
|
+
expect(ExtractUrls('')).toHaveLength(0);
|
|
233
|
+
});
|
|
234
|
+
it('should deduplicate URLs', () => {
|
|
235
|
+
const urls = ExtractUrls('https://a.com and https://a.com again');
|
|
236
|
+
expect(urls).toHaveLength(1);
|
|
237
|
+
});
|
|
238
|
+
it('should truncate long URLs', () => {
|
|
239
|
+
const longUrl = 'https://example.com/' + 'a'.repeat(100);
|
|
240
|
+
const truncated = TruncateUrl(longUrl);
|
|
241
|
+
expect(truncated.length).toBeLessThan(longUrl.length);
|
|
242
|
+
expect(truncated).toContain('...');
|
|
243
|
+
});
|
|
244
|
+
it('should handle short URLs', () => {
|
|
245
|
+
const truncated = TruncateUrl('https://example.com/page');
|
|
246
|
+
expect(truncated).toBe('example.com/page');
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
// ═══════════════════════════════════════════
|
|
250
|
+
// FormatTime
|
|
251
|
+
// ═══════════════════════════════════════════
|
|
252
|
+
describe('FormatTime', () => {
|
|
253
|
+
it('should format sub-second times in ms', () => {
|
|
254
|
+
expect(FormatTime(450)).toBe('450ms');
|
|
255
|
+
});
|
|
256
|
+
it('should format times >= 1s in seconds', () => {
|
|
257
|
+
expect(FormatTime(1500)).toBe('1.5s');
|
|
258
|
+
});
|
|
259
|
+
it('should format exactly 1 second', () => {
|
|
260
|
+
expect(FormatTime(1000)).toBe('1.0s');
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
//# sourceMappingURL=search-results.component.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-results.component.test.js","sourceRoot":"","sources":["../../src/__tests__/search-results.component.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG9C,0EAA0E;AAE1E,iDAAiD;AACjD,SAAS,WAAW,CAAC,KAAa;IAC9B,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG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AE,GAAG,EAAE;QAChC,MAAM,SAAS,GAAG,WAAW,CAAC,0BAA0B,CAAC,CAAC;QAC1D,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,8CAA8C;AAC9C,aAAa;AACb,8CAA8C;AAC9C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IACxB,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;QACtC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Tests for SearchResultsComponent pure logic:\n * - SR-1: FormatScore consistency\n * - SR-4: Flat mode support\n * - SR-5: Pagination logic\n *\n * We test the logic functions directly without Angular TestBed,\n * extracting them to avoid Angular decorator/inject() issues.\n */\nimport { describe, it, expect } from 'vitest';\nimport { SearchResultItem, SearchResultGroup } from '../lib/search-types';\n\n// ── Extract and test pure logic functions from SearchResultsComponent ──\n\n/** Mirrors SearchResultsComponent.FormatScore */\nfunction FormatScore(score: number): string {\n return `${Math.round(score * 100)}%`;\n}\n\n/** Mirrors SearchResultsComponent.FormatTime */\nfunction FormatTime(ms: number): string {\n if (ms < 1000) return `${ms}ms`;\n return `${(ms / 1000).toFixed(1)}s`;\n}\n\n/** Mirrors SearchResultsComponent.ExtractUrls */\nfunction ExtractUrls(snippet: string): string[] {\n if (!snippet) return [];\n const urlRegex = /https?:\\/\\/[^\\s,;)>\"']+/g;\n const matches = snippet.match(urlRegex);\n return matches ? [...new Set(matches)] : [];\n}\n\n/** Mirrors SearchResultsComponent.TruncateUrl */\nfunction TruncateUrl(url: string): string {\n try {\n const parsed = new URL(url);\n const path = parsed.pathname.length > 30\n ? parsed.pathname.substring(0, 30) + '...'\n : parsed.pathname;\n return parsed.hostname + path;\n } catch {\n return url.length > 50 ? url.substring(0, 50) + '...' : url;\n }\n}\n\n/** Mirrors SearchResultsComponent pagination logic */\nfunction getPagedResults(flatResults: SearchResultItem[], currentPage: number, pageSize: number): SearchResultItem[] {\n const start = (currentPage - 1) * pageSize;\n return flatResults.slice(start, start + pageSize);\n}\n\nfunction getTotalPages(totalResults: number, pageSize: number): number {\n return Math.ceil(totalResults / pageSize);\n}\n\nfunction getPageNumbers(currentPage: number, totalPages: number): number[] {\n if (totalPages <= 7) return Array.from({ length: totalPages }, (_, i) => i + 1);\n const pages: number[] = [1];\n const start = Math.max(2, currentPage - 2);\n const end = Math.min(totalPages - 1, currentPage + 2);\n if (start > 2) pages.push(-1);\n for (let i = start; i <= end; i++) pages.push(i);\n if (end < totalPages - 1) pages.push(-1);\n pages.push(totalPages);\n return pages;\n}\n\n/** Mirrors SearchResultsComponent group logic */\nfunction getVisibleResults(\n group: SearchResultGroup,\n isExpanded: boolean,\n maxPerGroup: number\n): SearchResultItem[] {\n if (isExpanded) return group.Results;\n return group.Results.slice(0, maxPerGroup);\n}\n\nfunction createResult(id: string, score: number): SearchResultItem {\n return {\n ID: id, Title: `R${id}`, Snippet: '', EntityName: 'Test',\n RecordID: `rec-${id}`, SourceType: 'entity', Score: score,\n ScoreBreakdown: { Vector: score * 0.6, FullText: score * 0.4 },\n Tags: [], SourceIcon: 'fa-solid fa-database', MatchedAt: new Date(),\n };\n}\n\n// ═══════════════════════════════════════════\n// SR-1: FormatScore consistency\n// ═══════════════════════════════════════════\ndescribe('FormatScore (SR-1)', () => {\n it('should format 0.85 as 85%', () => {\n expect(FormatScore(0.85)).toBe('85%');\n });\n\n it('should format 1.0 as 100%', () => {\n expect(FormatScore(1.0)).toBe('100%');\n });\n\n it('should format 0 as 0%', () => {\n expect(FormatScore(0)).toBe('0%');\n });\n\n it('should round to nearest integer', () => {\n expect(FormatScore(0.856)).toBe('86%');\n expect(FormatScore(0.854)).toBe('85%');\n });\n\n it('should produce same format for card header and expanded detail (SR-1 fix)', () => {\n // Before the fix, expanded detail used (score * 100).toFixed(0)\n // Now both use FormatScore(score) — same function, same output\n const score = 0.7823;\n expect(FormatScore(score)).toBe('78%');\n });\n\n it('should match ScoreBreakdown formatting when using same function', () => {\n // Both overall and breakdown scores should use the same format\n const overallScore = 0.85;\n const vectorScore = 0.72;\n expect(FormatScore(overallScore)).toBe('85%');\n expect(FormatScore(vectorScore)).toBe('72%');\n });\n});\n\n// ═══════════════════════════════════════════\n// SR-5: Pagination\n// ═══════════════════════════════════════════\ndescribe('Pagination (SR-5)', () => {\n const results = Array.from({ length: 35 }, (_, i) => createResult(String(i + 1), 1 - i * 0.02));\n\n it('should calculate total pages correctly', () => {\n expect(getTotalPages(35, 10)).toBe(4);\n });\n\n it('should return first page of results', () => {\n const page = getPagedResults(results, 1, 10);\n expect(page).toHaveLength(10);\n expect(page[0].ID).toBe('1');\n expect(page[9].ID).toBe('10');\n });\n\n it('should return correct results for page 2', () => {\n const page = getPagedResults(results, 2, 10);\n expect(page).toHaveLength(10);\n expect(page[0].ID).toBe('11');\n });\n\n it('should return partial last page', () => {\n const page = getPagedResults(results, 4, 10);\n expect(page).toHaveLength(5); // 35 - 30 = 5\n });\n\n it('should return empty for out-of-range page', () => {\n const page = getPagedResults(results, 100, 10);\n expect(page).toHaveLength(0);\n });\n\n it('should show all pages when total is 7 or fewer', () => {\n const pages = getPageNumbers(1, 5);\n expect(pages).toEqual([1, 2, 3, 4, 5]);\n expect(pages).not.toContain(-1);\n });\n\n it('should include ellipsis for many pages', () => {\n const pages = getPageNumbers(8, 15);\n expect(pages[0]).toBe(1);\n expect(pages[pages.length - 1]).toBe(15);\n expect(pages).toContain(-1);\n });\n\n it('should center current page in page numbers', () => {\n const pages = getPageNumbers(8, 15);\n expect(pages).toContain(8);\n expect(pages).toContain(6); // current - 2\n expect(pages).toContain(10); // current + 2\n });\n\n it('should handle single page', () => {\n const pages = getPageNumbers(1, 1);\n expect(pages).toEqual([1]);\n });\n\n it('should handle zero pages', () => {\n expect(getTotalPages(0, 10)).toBe(0);\n });\n\n it('should handle exact page boundary (e.g. 20 results / 10 per page)', () => {\n const exactResults = Array.from({ length: 20 }, (_, i) => createResult(String(i + 1), 1 - i * 0.02));\n expect(getTotalPages(20, 10)).toBe(2);\n\n const page1 = getPagedResults(exactResults, 1, 10);\n expect(page1).toHaveLength(10);\n expect(page1[0].ID).toBe('1');\n\n const page2 = getPagedResults(exactResults, 2, 10);\n expect(page2).toHaveLength(10);\n expect(page2[0].ID).toBe('11');\n\n // Page 3 should be empty since 20/10 = exactly 2 pages\n const page3 = getPagedResults(exactResults, 3, 10);\n expect(page3).toHaveLength(0);\n });\n\n it('should return all results on single page when count equals page size', () => {\n const singlePageResults = Array.from({ length: 10 }, (_, i) => createResult(String(i + 1), 0.9));\n expect(getTotalPages(10, 10)).toBe(1);\n\n const page = getPagedResults(singlePageResults, 1, 10);\n expect(page).toHaveLength(10);\n\n const pages = getPageNumbers(1, 1);\n expect(pages).toEqual([1]);\n });\n\n it('should produce correct page numbers at boundary of 7 pages', () => {\n // Exactly 7 pages — should show all, no ellipsis\n const pages7 = getPageNumbers(4, 7);\n expect(pages7).toEqual([1, 2, 3, 4, 5, 6, 7]);\n expect(pages7).not.toContain(-1);\n\n // 8 pages — should include ellipsis\n const pages8 = getPageNumbers(4, 8);\n expect(pages8[0]).toBe(1);\n expect(pages8[pages8.length - 1]).toBe(8);\n });\n});\n\n// ═══════════════════════════════════════════\n// Group visibility logic\n// ═══════════════════════════════════════════\ndescribe('Group visibility', () => {\n const group: SearchResultGroup = {\n Label: 'Test', Icon: 'fa-test', SourceType: 'entity',\n Results: Array.from({ length: 10 }, (_, i) => createResult(String(i), 0.9)),\n TotalCount: 10,\n };\n\n it('should limit to maxPerGroup when collapsed', () => {\n const visible = getVisibleResults(group, false, 3);\n expect(visible).toHaveLength(3);\n });\n\n it('should show all when expanded', () => {\n const visible = getVisibleResults(group, true, 3);\n expect(visible).toHaveLength(10);\n });\n\n it('should show all when results <= maxPerGroup', () => {\n const smallGroup: SearchResultGroup = {\n ...group,\n Results: group.Results.slice(0, 2),\n TotalCount: 2,\n };\n const visible = getVisibleResults(smallGroup, false, 5);\n expect(visible).toHaveLength(2);\n });\n});\n\n// ═══════════════════════════════════════════\n// URL helpers\n// ═══════════════════════════════════════════\ndescribe('URL helpers', () => {\n it('should extract URLs from text', () => {\n const urls = ExtractUrls('Visit https://example.com and http://test.org/path');\n expect(urls).toHaveLength(2);\n expect(urls).toContain('https://example.com');\n });\n\n it('should return empty for no URLs', () => {\n expect(ExtractUrls('no urls here')).toHaveLength(0);\n expect(ExtractUrls('')).toHaveLength(0);\n });\n\n it('should deduplicate URLs', () => {\n const urls = ExtractUrls('https://a.com and https://a.com again');\n expect(urls).toHaveLength(1);\n });\n\n it('should truncate long URLs', () => {\n const longUrl = 'https://example.com/' + 'a'.repeat(100);\n const truncated = TruncateUrl(longUrl);\n expect(truncated.length).toBeLessThan(longUrl.length);\n expect(truncated).toContain('...');\n });\n\n it('should handle short URLs', () => {\n const truncated = TruncateUrl('https://example.com/page');\n expect(truncated).toBe('example.com/page');\n });\n});\n\n// ═══════════════════════════════════════════\n// FormatTime\n// ═══════════════════════════════════════════\ndescribe('FormatTime', () => {\n it('should format sub-second times in ms', () => {\n expect(FormatTime(450)).toBe('450ms');\n });\n\n it('should format times >= 1s in seconds', () => {\n expect(FormatTime(1500)).toBe('1.5s');\n });\n\n it('should format exactly 1 second', () => {\n expect(FormatTime(1000)).toBe('1.0s');\n });\n});\n"]}
|
|
@@ -9,6 +9,7 @@ describe('Search Types', () => {
|
|
|
9
9
|
EntityName: 'Contacts',
|
|
10
10
|
RecordID: 'rec-123',
|
|
11
11
|
SourceType: 'entity',
|
|
12
|
+
ResultType: 'entity-record',
|
|
12
13
|
Score: 0.85,
|
|
13
14
|
ScoreBreakdown: { Vector: 0.8, FullText: 0.9 },
|
|
14
15
|
Tags: ['customer', 'active'],
|
|
@@ -19,6 +20,7 @@ describe('Search Types', () => {
|
|
|
19
20
|
expect(item.Score).toBe(0.85);
|
|
20
21
|
expect(item.Tags).toHaveLength(2);
|
|
21
22
|
expect(item.SourceType).toBe('entity');
|
|
23
|
+
expect(item.ResultType).toBe('entity-record');
|
|
22
24
|
});
|
|
23
25
|
});
|
|
24
26
|
describe('SearchResultGroup', () => {
|
|
@@ -73,7 +75,8 @@ describe('Search Types', () => {
|
|
|
73
75
|
Filters: [],
|
|
74
76
|
TotalCount: 42,
|
|
75
77
|
ElapsedMs: 150,
|
|
76
|
-
SourceCounts: { Vector: 20, FullText: 15, Entity: 7 }
|
|
78
|
+
SourceCounts: { Vector: 20, FullText: 15, Entity: 7, Storage: 0 },
|
|
79
|
+
Providers: []
|
|
77
80
|
};
|
|
78
81
|
expect(response.Success).toBe(true);
|
|
79
82
|
expect(response.SourceCounts.Vector + response.SourceCounts.FullText + response.SourceCounts.Entity).toBe(42);
|
|
@@ -86,7 +89,8 @@ describe('Search Types', () => {
|
|
|
86
89
|
Filters: [],
|
|
87
90
|
TotalCount: 0,
|
|
88
91
|
ElapsedMs: 0,
|
|
89
|
-
SourceCounts: { Vector: 0, FullText: 0, Entity: 0 },
|
|
92
|
+
SourceCounts: { Vector: 0, FullText: 0, Entity: 0, Storage: 0 },
|
|
93
|
+
Providers: [],
|
|
90
94
|
ErrorMessage: 'Search service unavailable'
|
|
91
95
|
};
|
|
92
96
|
expect(response.Success).toBe(false);
|
|
@@ -1 +1 @@
|
|
|
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,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;
|
|
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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,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE;gBAC/D,SAAS,EAAE,EAAE;gBACb,YAAY,EAAE,4BAA4B;aAC7C,CAAC;YAEF,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC5C,MAAM,SAAS,GAAmB;gBAC9B,MAAM,EAAE,IAAI;aACf,CAAC;YAEF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,aAAa,EAAE,CAAC;YAC3C,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;QAC7C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect } from 'vitest';\nimport {\n SearchResultItem,\n SearchResultGroup,\n SearchFilter,\n SearchFilterOption,\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,19 +1,26 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
2
|
import { Metadata } from '@memberjunction/core';
|
|
3
|
+
import { GraphQLDataProvider, GraphQLSearchClient } from '@memberjunction/graphql-dataprovider';
|
|
3
4
|
import { SearchService } from '../lib/search.service';
|
|
4
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Installs a fake Metadata.Provider that passes the `instanceof GraphQLDataProvider` check
|
|
7
|
+
* and stubs GraphQLSearchClient.ExecuteSearch to return empty success.
|
|
8
|
+
*/
|
|
5
9
|
function installMockProvider() {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
SourceCounts: { Vector: 0, FullText: 0, Entity: 0 },
|
|
13
|
-
}
|
|
10
|
+
const mockExecuteSearch = vi.fn().mockResolvedValue({
|
|
11
|
+
Success: true,
|
|
12
|
+
Results: [],
|
|
13
|
+
TotalCount: 0,
|
|
14
|
+
ElapsedMs: 1,
|
|
15
|
+
SourceCounts: { Vector: 0, FullText: 0, Entity: 0, Storage: 0 },
|
|
14
16
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
// Create a mock that passes `instanceof GraphQLDataProvider`
|
|
18
|
+
const mockProvider = Object.create(GraphQLDataProvider.prototype);
|
|
19
|
+
Metadata['Provider'] = mockProvider;
|
|
20
|
+
// Stub GraphQLSearchClient.prototype so the service's `new GraphQLSearchClient(provider)` works
|
|
21
|
+
vi.spyOn(GraphQLSearchClient.prototype, 'ExecuteSearch').mockImplementation(mockExecuteSearch);
|
|
22
|
+
vi.spyOn(GraphQLSearchClient.prototype, 'PreviewSearch').mockImplementation(mockExecuteSearch);
|
|
23
|
+
return mockExecuteSearch;
|
|
17
24
|
}
|
|
18
25
|
describe('SearchService', () => {
|
|
19
26
|
let service;
|
|
@@ -128,7 +135,7 @@ describe('SearchService', () => {
|
|
|
128
135
|
expect(groups).toHaveLength(3);
|
|
129
136
|
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
130
137
|
expect(entityGroup?.Results).toHaveLength(2);
|
|
131
|
-
expect(entityGroup?.Label).toBe('
|
|
138
|
+
expect(entityGroup?.Label).toBe('Database');
|
|
132
139
|
});
|
|
133
140
|
it('should return empty array for empty input', () => {
|
|
134
141
|
const groups = service.GroupResults([]);
|
|
@@ -143,7 +150,7 @@ describe('SearchService', () => {
|
|
|
143
150
|
];
|
|
144
151
|
const filters = service.BuildFilters(results);
|
|
145
152
|
expect(filters).toHaveLength(3);
|
|
146
|
-
const sourceFilter = filters.find(f => f.Category === 'Source
|
|
153
|
+
const sourceFilter = filters.find(f => f.Category === 'Source');
|
|
147
154
|
expect(sourceFilter?.Options).toHaveLength(2);
|
|
148
155
|
});
|
|
149
156
|
it('should limit tags filter to 15 options', () => {
|
|
@@ -153,6 +160,50 @@ describe('SearchService', () => {
|
|
|
153
160
|
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
154
161
|
expect(tagFilter.Options.length).toBeLessThanOrEqual(15);
|
|
155
162
|
});
|
|
163
|
+
it('should generate correct tag filter options with counts and icon', () => {
|
|
164
|
+
const results = [
|
|
165
|
+
createMockResult('1', 'entity', 'Contacts', ['crm', 'active']),
|
|
166
|
+
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
167
|
+
createMockResult('3', 'file', 'Docs', ['internal']),
|
|
168
|
+
];
|
|
169
|
+
const filters = service.BuildFilters(results);
|
|
170
|
+
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
171
|
+
expect(tagFilter).toBeDefined();
|
|
172
|
+
expect(tagFilter.MultiSelect).toBe(true);
|
|
173
|
+
// 'crm' appears in 2 results, should be sorted first
|
|
174
|
+
const crmOption = tagFilter.Options.find(o => o.Value === 'crm');
|
|
175
|
+
expect(crmOption).toBeDefined();
|
|
176
|
+
expect(crmOption.Count).toBe(2);
|
|
177
|
+
expect(crmOption.Icon).toBe('fa-solid fa-tag');
|
|
178
|
+
expect(crmOption.IsSelected).toBe(false);
|
|
179
|
+
// 'active' and 'internal' each appear once
|
|
180
|
+
const activeOption = tagFilter.Options.find(o => o.Value === 'active');
|
|
181
|
+
expect(activeOption.Count).toBe(1);
|
|
182
|
+
const internalOption = tagFilter.Options.find(o => o.Value === 'internal');
|
|
183
|
+
expect(internalOption.Count).toBe(1);
|
|
184
|
+
});
|
|
185
|
+
it('should omit Tags filter when no results have tags', () => {
|
|
186
|
+
const results = [
|
|
187
|
+
createMockResult('1', 'entity', 'Contacts'),
|
|
188
|
+
createMockResult('2', 'entity', 'Companies'),
|
|
189
|
+
];
|
|
190
|
+
const filters = service.BuildFilters(results);
|
|
191
|
+
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
192
|
+
expect(tagFilter).toBeUndefined(); // Empty categories are filtered out
|
|
193
|
+
});
|
|
194
|
+
it('should sort tags by count descending', () => {
|
|
195
|
+
const results = [
|
|
196
|
+
createMockResult('1', 'entity', 'A', ['rare', 'common']),
|
|
197
|
+
createMockResult('2', 'entity', 'B', ['common']),
|
|
198
|
+
createMockResult('3', 'entity', 'C', ['common']),
|
|
199
|
+
];
|
|
200
|
+
const filters = service.BuildFilters(results);
|
|
201
|
+
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
202
|
+
expect(tagFilter.Options[0].Value).toBe('common');
|
|
203
|
+
expect(tagFilter.Options[0].Count).toBe(3);
|
|
204
|
+
expect(tagFilter.Options[1].Value).toBe('rare');
|
|
205
|
+
expect(tagFilter.Options[1].Count).toBe(1);
|
|
206
|
+
});
|
|
156
207
|
});
|
|
157
208
|
describe('GetSourceIcon', () => {
|
|
158
209
|
it('should return correct icon for known types', () => {
|
|
@@ -164,6 +215,108 @@ describe('SearchService', () => {
|
|
|
164
215
|
expect(service.GetSourceIcon('unknown')).toContain('fa-circle');
|
|
165
216
|
});
|
|
166
217
|
});
|
|
218
|
+
// ═══════════════════════════════════════════════════════════════
|
|
219
|
+
// SR-3 Bug Fix: BuildFilters should preserve all options from full result set
|
|
220
|
+
// ═══════════════════════════════════════════════════════════════
|
|
221
|
+
describe('BuildFilters (SR-3: filter options from full result set)', () => {
|
|
222
|
+
it('should include all entity names even when results are filtered', () => {
|
|
223
|
+
// Full result set with 3 entities
|
|
224
|
+
const fullResults = [
|
|
225
|
+
createMockResult('1', 'entity', 'Contacts', ['crm']),
|
|
226
|
+
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
227
|
+
createMockResult('3', 'entity', 'Deals', ['sales']),
|
|
228
|
+
];
|
|
229
|
+
// Build filters from FULL set (this is what the fix does)
|
|
230
|
+
const filters = service.BuildFilters(fullResults);
|
|
231
|
+
const entityFilter = filters.find(f => f.Category === 'Entity');
|
|
232
|
+
// All 3 entities should appear in filter options
|
|
233
|
+
expect(entityFilter?.Options).toHaveLength(3);
|
|
234
|
+
expect(entityFilter?.Options.map(o => o.Value)).toContain('Contacts');
|
|
235
|
+
expect(entityFilter?.Options.map(o => o.Value)).toContain('Companies');
|
|
236
|
+
expect(entityFilter?.Options.map(o => o.Value)).toContain('Deals');
|
|
237
|
+
});
|
|
238
|
+
it('should count tags correctly across all results', () => {
|
|
239
|
+
const results = [
|
|
240
|
+
createMockResult('1', 'entity', 'Contacts', ['crm', 'sales']),
|
|
241
|
+
createMockResult('2', 'entity', 'Companies', ['crm']),
|
|
242
|
+
createMockResult('3', 'entity', 'Deals', ['sales', 'pipeline']),
|
|
243
|
+
];
|
|
244
|
+
const filters = service.BuildFilters(results);
|
|
245
|
+
const tagFilter = filters.find(f => f.Category === 'Tags');
|
|
246
|
+
// 'crm' appears in 2 results, 'sales' in 2, 'pipeline' in 1
|
|
247
|
+
expect(tagFilter?.Options).toHaveLength(3);
|
|
248
|
+
const crmOption = tagFilter?.Options.find(o => o.Value === 'crm');
|
|
249
|
+
expect(crmOption?.Count).toBe(2);
|
|
250
|
+
});
|
|
251
|
+
it('should not lose filter options when building from subset vs full set', () => {
|
|
252
|
+
const fullResults = [
|
|
253
|
+
createMockResult('1', 'entity', 'Contacts'),
|
|
254
|
+
createMockResult('2', 'entity', 'Companies'),
|
|
255
|
+
createMockResult('3', 'file', 'Documents'),
|
|
256
|
+
];
|
|
257
|
+
// Simulating filtering to only Contacts
|
|
258
|
+
const filteredResults = fullResults.filter(r => r.EntityName === 'Contacts');
|
|
259
|
+
// Building from filtered set loses Companies and Documents
|
|
260
|
+
const filteredFilters = service.BuildFilters(filteredResults);
|
|
261
|
+
const filteredEntityFilter = filteredFilters.find(f => f.Category === 'Entity');
|
|
262
|
+
expect(filteredEntityFilter?.Options).toHaveLength(1); // Only Contacts
|
|
263
|
+
// Building from full set preserves all options (the fix)
|
|
264
|
+
const fullFilters = service.BuildFilters(fullResults);
|
|
265
|
+
const fullEntityFilter = fullFilters.find(f => f.Category === 'Entity');
|
|
266
|
+
expect(fullEntityFilter?.Options).toHaveLength(3); // Contacts + Companies + Documents
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
// ═══════════════════════════════════════════════════════════════
|
|
270
|
+
// SR-4 Bug Fix: GroupResults should sort within groups by score
|
|
271
|
+
// ═══════════════════════════════════════════════════════════════
|
|
272
|
+
describe('GroupResults (SR-4: grouping and sorting)', () => {
|
|
273
|
+
it('should group results by source type with correct labels', () => {
|
|
274
|
+
const results = [
|
|
275
|
+
{ ...createMockResult('1', 'entity', 'Contacts'), Score: 0.9 },
|
|
276
|
+
{ ...createMockResult('2', 'content-item', 'Items'), Score: 0.8 },
|
|
277
|
+
{ ...createMockResult('3', 'entity', 'Companies'), Score: 0.7 },
|
|
278
|
+
];
|
|
279
|
+
const groups = service.GroupResults(results);
|
|
280
|
+
expect(groups).toHaveLength(2);
|
|
281
|
+
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
282
|
+
expect(entityGroup?.Label).toBe('Database');
|
|
283
|
+
expect(entityGroup?.TotalCount).toBe(2);
|
|
284
|
+
const contentGroup = groups.find(g => g.SourceType === 'content-item');
|
|
285
|
+
expect(contentGroup?.Label).toBe('Content Items');
|
|
286
|
+
expect(contentGroup?.TotalCount).toBe(1);
|
|
287
|
+
});
|
|
288
|
+
it('should use fallback label for unknown source types', () => {
|
|
289
|
+
const results = [
|
|
290
|
+
createMockResult('1', 'entity', 'Test'),
|
|
291
|
+
];
|
|
292
|
+
// Hack source type to unknown
|
|
293
|
+
results[0]['SourceType'] = 'custom-type';
|
|
294
|
+
const groups = service.GroupResults(results);
|
|
295
|
+
expect(groups[0].Label).toBe('custom-type'); // Falls back to raw type name
|
|
296
|
+
});
|
|
297
|
+
it('should use fallback icon for unknown source types', () => {
|
|
298
|
+
const results = [
|
|
299
|
+
createMockResult('1', 'entity', 'Test'),
|
|
300
|
+
];
|
|
301
|
+
results[0]['SourceType'] = 'unknown-source';
|
|
302
|
+
const groups = service.GroupResults(results);
|
|
303
|
+
expect(groups[0].Icon).toBe('fa-solid fa-circle');
|
|
304
|
+
});
|
|
305
|
+
it('should handle mixed known and unknown source types', () => {
|
|
306
|
+
const results = [
|
|
307
|
+
createMockResult('1', 'entity', 'Contacts'),
|
|
308
|
+
createMockResult('2', 'entity', 'Companies'),
|
|
309
|
+
];
|
|
310
|
+
results[1]['SourceType'] = 'custom-plugin';
|
|
311
|
+
const groups = service.GroupResults(results);
|
|
312
|
+
expect(groups).toHaveLength(2);
|
|
313
|
+
const entityGroup = groups.find(g => g.SourceType === 'entity');
|
|
314
|
+
expect(entityGroup?.Label).toBe('Database');
|
|
315
|
+
const customGroup = groups.find(g => g.SourceType === 'custom-plugin');
|
|
316
|
+
expect(customGroup?.Label).toBe('custom-plugin');
|
|
317
|
+
expect(customGroup?.Icon).toBe('fa-solid fa-circle');
|
|
318
|
+
});
|
|
319
|
+
});
|
|
167
320
|
});
|
|
168
321
|
function createMockResult(id, sourceType, entityName, tags = []) {
|
|
169
322
|
return {
|
|
@@ -173,6 +326,7 @@ function createMockResult(id, sourceType, entityName, tags = []) {
|
|
|
173
326
|
EntityName: entityName,
|
|
174
327
|
RecordID: `rec-${id}`,
|
|
175
328
|
SourceType: sourceType,
|
|
329
|
+
ResultType: sourceType === 'file' ? 'storage-file' : 'entity-record',
|
|
176
330
|
Score: 0.85,
|
|
177
331
|
ScoreBreakdown: { Vector: 0.8, FullText: 0.9 },
|
|
178
332
|
Tags: tags,
|