@internetarchive/collection-browser 0.4.15-alpha.8 → 0.4.15
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/src/app-root.js +5 -2
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +10 -0
- package/dist/src/collection-browser.js +61 -49
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/restoration-state-handler.js +3 -15
- package/dist/src/restoration-state-handler.js.map +1 -1
- package/dist/test/collection-browser.test.js +77 -10
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/mocks/mock-search-responses.d.ts +11 -9
- package/dist/test/mocks/mock-search-responses.js +26 -19
- package/dist/test/mocks/mock-search-responses.js.map +1 -1
- package/dist/test/mocks/mock-search-service.d.ts +3 -1
- package/dist/test/mocks/mock-search-service.js +26 -24
- package/dist/test/mocks/mock-search-service.js.map +1 -1
- package/dist/test/restoration-state-handler.test.js +1 -9
- package/dist/test/restoration-state-handler.test.js.map +1 -1
- package/package.json +1 -1
- package/src/app-root.ts +6 -2
- package/src/collection-browser.ts +68 -50
- package/src/restoration-state-handler.ts +3 -16
- package/test/collection-browser.test.ts +109 -10
- package/test/mocks/mock-search-responses.ts +42 -27
- package/test/mocks/mock-search-service.ts +50 -32
- package/test/restoration-state-handler.test.ts +1 -12
|
@@ -7,18 +7,36 @@ import type {
|
|
|
7
7
|
SearchType,
|
|
8
8
|
} from '@internetarchive/search-service';
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
getMockSuccessSingleResult,
|
|
11
|
+
getMockSuccessMultipleResults,
|
|
12
12
|
getMockSuccessSingleResultWithSort,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
getMockSuccessLoggedInResult,
|
|
14
|
+
getMockSuccessNoPreviewResult,
|
|
15
|
+
getMockSuccessLoggedInAndNoPreviewResult,
|
|
16
|
+
getMockSuccessWithYearHistogramAggs,
|
|
17
|
+
getMockSuccessMultiLineDescription,
|
|
18
|
+
getMockSuccessFirstTitleResult,
|
|
19
|
+
getMockSuccessFirstCreatorResult,
|
|
20
|
+
getMockErrorResult,
|
|
21
|
+
getMockMalformedResult,
|
|
20
22
|
} from './mock-search-responses';
|
|
21
23
|
|
|
24
|
+
const responses: Record<
|
|
25
|
+
string,
|
|
26
|
+
() => Result<SearchResponse, SearchServiceError>
|
|
27
|
+
> = {
|
|
28
|
+
'single-result': getMockSuccessSingleResult,
|
|
29
|
+
years: getMockSuccessWithYearHistogramAggs,
|
|
30
|
+
'multi-line-description': getMockSuccessMultiLineDescription,
|
|
31
|
+
loggedin: getMockSuccessLoggedInResult,
|
|
32
|
+
'no-preview': getMockSuccessNoPreviewResult,
|
|
33
|
+
'loggedin-no-preview': getMockSuccessLoggedInAndNoPreviewResult,
|
|
34
|
+
'first-title': getMockSuccessFirstTitleResult,
|
|
35
|
+
'first-creator': getMockSuccessFirstCreatorResult,
|
|
36
|
+
error: getMockErrorResult,
|
|
37
|
+
malformed: getMockMalformedResult,
|
|
38
|
+
};
|
|
39
|
+
|
|
22
40
|
export class MockSearchService implements SearchServiceInterface {
|
|
23
41
|
searchParams?: SearchParams;
|
|
24
42
|
|
|
@@ -26,10 +44,17 @@ export class MockSearchService implements SearchServiceInterface {
|
|
|
26
44
|
|
|
27
45
|
asyncResponse: boolean;
|
|
28
46
|
|
|
47
|
+
asyncResponseDelay: number;
|
|
48
|
+
|
|
29
49
|
resultsSpy: Function;
|
|
30
50
|
|
|
31
|
-
constructor({
|
|
51
|
+
constructor({
|
|
52
|
+
asyncResponse = false,
|
|
53
|
+
asyncResponseDelay = 0,
|
|
54
|
+
resultsSpy = () => {},
|
|
55
|
+
} = {}) {
|
|
32
56
|
this.asyncResponse = asyncResponse;
|
|
57
|
+
this.asyncResponseDelay = asyncResponseDelay;
|
|
33
58
|
this.resultsSpy = resultsSpy;
|
|
34
59
|
}
|
|
35
60
|
|
|
@@ -43,31 +68,24 @@ export class MockSearchService implements SearchServiceInterface {
|
|
|
43
68
|
if (this.asyncResponse) {
|
|
44
69
|
// Add an artificial 1-tick delay
|
|
45
70
|
await new Promise(res => {
|
|
46
|
-
setTimeout(res,
|
|
71
|
+
setTimeout(res, this.asyncResponseDelay);
|
|
47
72
|
});
|
|
48
73
|
}
|
|
49
74
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return mockSuccessLoggedInAndNoPreviewResult;
|
|
63
|
-
case 'first-title':
|
|
64
|
-
return mockSuccessFirstTitleResult;
|
|
65
|
-
case 'first-creator':
|
|
66
|
-
return mockSuccessFirstCreatorResult;
|
|
67
|
-
case 'with-sort':
|
|
68
|
-
return getMockSuccessSingleResultWithSort(this.resultsSpy);
|
|
69
|
-
default:
|
|
70
|
-
return mockSuccessMultipleResults;
|
|
75
|
+
const resultFn: () => Result<SearchResponse, SearchServiceError> =
|
|
76
|
+
responses[this.searchParams.query] ?? getMockSuccessMultipleResults;
|
|
77
|
+
let result = resultFn();
|
|
78
|
+
|
|
79
|
+
// with-sort query has special handling
|
|
80
|
+
if (this.searchParams.query === 'with-sort') {
|
|
81
|
+
result = getMockSuccessSingleResultWithSort(this.resultsSpy);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Apply any uid param from the request
|
|
85
|
+
if (result.success) {
|
|
86
|
+
(result.success.request.clientParameters as any).uid = params.uid;
|
|
71
87
|
}
|
|
88
|
+
|
|
89
|
+
return result;
|
|
72
90
|
}
|
|
73
91
|
}
|
|
@@ -15,24 +15,13 @@ describe('Restoration state handler', () => {
|
|
|
15
15
|
expect(restorationState.baseQuery).to.equal('boop');
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
it('should
|
|
18
|
+
it('should restore metadata search type from URL without valid sin', async () => {
|
|
19
19
|
const handler = new RestorationStateHandler({ context: 'search' });
|
|
20
20
|
|
|
21
21
|
const url = new URL(window.location.href);
|
|
22
22
|
url.search = '?sin=foo';
|
|
23
23
|
window.history.replaceState({ path: url.href }, '', url.href);
|
|
24
24
|
|
|
25
|
-
const restorationState = handler.getRestorationState();
|
|
26
|
-
expect(restorationState.searchType).to.not.exist;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should restore metadata search type if sin explicitly empty in URL', async () => {
|
|
30
|
-
const handler = new RestorationStateHandler({ context: 'search' });
|
|
31
|
-
|
|
32
|
-
const url = new URL(window.location.href);
|
|
33
|
-
url.search = '?sin=';
|
|
34
|
-
window.history.replaceState({ path: url.href }, '', url.href);
|
|
35
|
-
|
|
36
25
|
const restorationState = handler.getRestorationState();
|
|
37
26
|
expect(restorationState.searchType).to.equal(SearchType.METADATA);
|
|
38
27
|
});
|