@internetarchive/collection-browser 1.6.0 → 1.7.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.
@@ -590,6 +590,98 @@ export const getMockSuccessExtraQuotedHref: () => Result<
590
590
  },
591
591
  });
592
592
 
593
+ export const getMockSuccessWithDefaultSort: () => Result<
594
+ SearchResponse,
595
+ SearchServiceError
596
+ > = () => ({
597
+ success: {
598
+ request: {
599
+ kind: 'hits',
600
+ clientParameters: {
601
+ user_query: 'default-sort',
602
+ sort: [],
603
+ },
604
+ backendRequests: {
605
+ primary: {
606
+ kind: 'hits',
607
+ finalized_parameters: {
608
+ user_query: 'default-sort',
609
+ sort: ['titleSorter', 'identifier'],
610
+ },
611
+ },
612
+ },
613
+ },
614
+ rawResponse: {},
615
+ response: {
616
+ totalResults: 1,
617
+ returnedCount: 1,
618
+ results: [
619
+ new ItemHit({
620
+ fields: {
621
+ identifier: 'foo',
622
+ title: 'Foo',
623
+ },
624
+ }),
625
+ ],
626
+ collectionExtraInfo: {
627
+ public_metadata: {
628
+ 'sort-by': 'titleSorter',
629
+ },
630
+ },
631
+ },
632
+ responseHeader: {
633
+ succeeded: true,
634
+ query_time: 0,
635
+ },
636
+ },
637
+ });
638
+
639
+ export const getMockSuccessWithConciseDefaultSort: () => Result<
640
+ SearchResponse,
641
+ SearchServiceError
642
+ > = () => ({
643
+ success: {
644
+ request: {
645
+ kind: 'hits',
646
+ clientParameters: {
647
+ user_query: 'default-sort-concise',
648
+ sort: [],
649
+ },
650
+ backendRequests: {
651
+ primary: {
652
+ kind: 'hits',
653
+ finalized_parameters: {
654
+ user_query: 'default-sort-concise',
655
+ sort: ['addeddate:desc', 'identifier'],
656
+ },
657
+ },
658
+ },
659
+ },
660
+ rawResponse: {},
661
+ response: {
662
+ totalResults: 1,
663
+ returnedCount: 1,
664
+ results: [
665
+ new ItemHit({
666
+ fields: {
667
+ identifier: 'foo',
668
+ title: 'Foo',
669
+ },
670
+ }),
671
+ ],
672
+ collectionExtraInfo: {
673
+ public_metadata: {
674
+ 'sort-by': '-addeddate',
675
+ },
676
+ },
677
+ },
678
+ responseHeader: {
679
+ succeeded: true,
680
+ query_time: 0,
681
+ },
682
+ },
683
+ });
684
+
593
685
  export const getMockErrorResult: () => Result<
594
686
  SearchResponse,
595
687
  SearchServiceError
@@ -22,6 +22,8 @@ import {
22
22
  getMockSuccessWithCollectionTitles,
23
23
  getMockSuccessWithCollectionAggregations,
24
24
  getMockSuccessExtraQuotedHref,
25
+ getMockSuccessWithDefaultSort,
26
+ getMockSuccessWithConciseDefaultSort,
25
27
  } from './mock-search-responses';
26
28
 
27
29
  const responses: Record<
@@ -39,6 +41,8 @@ const responses: Record<
39
41
  'collection-titles': getMockSuccessWithCollectionTitles,
40
42
  'collection-aggregations': getMockSuccessWithCollectionAggregations,
41
43
  'extra-quoted-href': getMockSuccessExtraQuotedHref,
44
+ 'default-sort': getMockSuccessWithDefaultSort,
45
+ 'default-sort-concise': getMockSuccessWithConciseDefaultSort,
42
46
  error: getMockErrorResult,
43
47
  malformed: getMockMalformedResult,
44
48
  };
@@ -78,8 +82,10 @@ export class MockSearchService implements SearchServiceInterface {
78
82
  });
79
83
  }
80
84
 
85
+ const responseKey =
86
+ (this.searchParams.query || this.searchParams.pageTarget) ?? '';
81
87
  const resultFn: () => Result<SearchResponse, SearchServiceError> =
82
- responses[this.searchParams.query] ?? getMockSuccessMultipleResults;
88
+ responses[responseKey] ?? getMockSuccessMultipleResults;
83
89
  let result = resultFn();
84
90
 
85
91
  // with-sort query has special handling