@internetarchive/collection-browser 0.2.21 → 0.2.22
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.d.ts +1 -0
- package/dist/src/app-root.js +34 -4
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/assets/img/icons/arrow-left.d.ts +2 -0
- package/dist/src/assets/img/icons/arrow-left.js +10 -0
- package/dist/src/assets/img/icons/arrow-left.js.map +1 -0
- package/dist/src/assets/img/icons/arrow-right.d.ts +2 -0
- package/dist/src/assets/img/icons/arrow-right.js +10 -0
- package/dist/src/assets/img/icons/arrow-right.js.map +1 -0
- package/dist/src/collection-browser.d.ts +2 -0
- package/dist/src/collection-browser.js +10 -2
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/facets-template.d.ts +16 -0
- package/dist/src/collection-facets/facets-template.js +266 -0
- package/dist/src/collection-facets/facets-template.js.map +1 -0
- package/dist/src/collection-facets/facets-util.d.ts +10 -0
- package/dist/src/collection-facets/facets-util.js +20 -0
- package/dist/src/collection-facets/facets-util.js.map +1 -0
- package/dist/src/collection-facets/more-facets-content.d.ts +83 -0
- package/dist/src/collection-facets/more-facets-content.js +475 -0
- package/dist/src/collection-facets/more-facets-content.js.map +1 -0
- package/dist/src/collection-facets/more-facets-pagination.d.ts +36 -0
- package/dist/src/collection-facets/more-facets-pagination.js +267 -0
- package/dist/src/collection-facets/more-facets-pagination.js.map +1 -0
- package/dist/src/collection-facets.d.ts +19 -5
- package/dist/src/collection-facets.js +138 -239
- package/dist/src/collection-facets.js.map +1 -1
- package/dist/src/models.d.ts +4 -1
- package/dist/src/models.js +24 -0
- package/dist/src/models.js.map +1 -1
- package/dist/src/restoration-state-handler.js +5 -6
- package/dist/src/restoration-state-handler.js.map +1 -1
- package/dist/src/tiles/collection-browser-loading-tile.js +2 -5
- package/dist/src/tiles/collection-browser-loading-tile.js.map +1 -1
- package/dist/test/collection-browser.test.js +5 -3
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/collection-facets/facets-template.test.d.ts +1 -0
- package/dist/test/collection-facets/facets-template.test.js +75 -0
- package/dist/test/collection-facets/facets-template.test.js.map +1 -0
- package/dist/test/collection-facets/facets-util.test.d.ts +1 -0
- package/dist/test/collection-facets/facets-util.test.js +13 -0
- package/dist/test/collection-facets/facets-util.test.js.map +1 -0
- package/dist/test/collection-facets/more-facets-content.test.d.ts +1 -0
- package/dist/test/collection-facets/more-facets-content.test.js +104 -0
- package/dist/test/collection-facets/more-facets-content.test.js.map +1 -0
- package/dist/test/collection-facets/more-facets-pagination.test.d.ts +1 -0
- package/dist/test/collection-facets/more-facets-pagination.test.js +133 -0
- package/dist/test/collection-facets/more-facets-pagination.test.js.map +1 -0
- package/dist/test/collection-facets.test.d.ts +1 -0
- package/dist/test/collection-facets.test.js +98 -33
- package/dist/test/collection-facets.test.js.map +1 -1
- package/package.json +11 -4
- package/src/app-root.ts +34 -4
- package/src/assets/img/icons/arrow-left.ts +10 -0
- package/src/assets/img/icons/arrow-right.ts +10 -0
- package/src/collection-browser.ts +9 -2
- package/src/collection-facets/facets-template.ts +284 -0
- package/src/collection-facets/facets-util.ts +22 -0
- package/src/collection-facets/more-facets-content.ts +529 -0
- package/src/collection-facets/more-facets-pagination.ts +297 -0
- package/src/collection-facets.ts +175 -261
- package/src/models.ts +28 -1
- package/src/restoration-state-handler.ts +7 -6
- package/src/tiles/collection-browser-loading-tile.ts +2 -5
- package/test/collection-browser.test.ts +6 -3
- package/test/collection-facets/facets-template.test.ts +103 -0
- package/test/collection-facets/facets-util.test.ts +18 -0
- package/test/collection-facets/more-facets-content.test.ts +146 -0
- package/test/collection-facets/more-facets-pagination.test.ts +202 -0
- package/test/collection-facets.test.ts +127 -44
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { expect, fixture } from '@open-wc/testing';
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import type { FacetsTemplate } from '../../src/collection-facets/facets-template';
|
|
4
|
+
import '../../src/collection-facets/facets-template';
|
|
5
|
+
|
|
6
|
+
const facetGroup = {
|
|
7
|
+
title: 'Media Type',
|
|
8
|
+
key: 'mediatype',
|
|
9
|
+
buckets: [
|
|
10
|
+
{ displayText: 'audio', key: 'audio', count: 1001, state: 'none' },
|
|
11
|
+
{ displayText: 'movies', key: 'movies', count: 901, state: 'none' },
|
|
12
|
+
{ displayText: 'texts', key: 'texts', count: 2101, state: 'none' },
|
|
13
|
+
{ displayText: 'data', key: 'data', count: 230, state: 'none' },
|
|
14
|
+
{ displayText: 'web', key: 'web', count: 453, state: 'none' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('Render facets', () => {
|
|
19
|
+
it('should render more facets template', async () => {
|
|
20
|
+
const el = await fixture<FacetsTemplate>(
|
|
21
|
+
html`<facets-template .facetGroup=${facetGroup}></facets-template>`
|
|
22
|
+
);
|
|
23
|
+
await el.updateComplete;
|
|
24
|
+
|
|
25
|
+
expect(el.shadowRoot?.querySelector('.facet-row')).to.exist;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('facets render on page', async () => {
|
|
29
|
+
const el = await fixture<FacetsTemplate>(
|
|
30
|
+
html`<facets-template
|
|
31
|
+
.facetGroup=${facetGroup}
|
|
32
|
+
.renderOn=${'page'}
|
|
33
|
+
></facets-template>`
|
|
34
|
+
);
|
|
35
|
+
await el.updateComplete;
|
|
36
|
+
|
|
37
|
+
expect(el.shadowRoot?.querySelector('.facets-on-page')).to.exist;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('facets render on modal', async () => {
|
|
41
|
+
const el = await fixture<FacetsTemplate>(
|
|
42
|
+
html`<facets-template
|
|
43
|
+
.facetGroup=${facetGroup}
|
|
44
|
+
.renderOn=${'modal'}
|
|
45
|
+
></facets-template>`
|
|
46
|
+
);
|
|
47
|
+
await el.updateComplete;
|
|
48
|
+
|
|
49
|
+
expect(el.shadowRoot?.querySelector('.facets-on-modal')).to.exist;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('find facet-title and facet-count for perticular facet group', async () => {
|
|
53
|
+
const el = await fixture<FacetsTemplate>(
|
|
54
|
+
html`<facets-template .facetGroup=${facetGroup}></facets-template>`
|
|
55
|
+
);
|
|
56
|
+
await el.updateComplete;
|
|
57
|
+
|
|
58
|
+
const facetInfo = el.shadowRoot?.querySelector('.facet-info-display');
|
|
59
|
+
expect(facetInfo?.querySelector('.facet-title')?.textContent).equal(
|
|
60
|
+
'audio'
|
|
61
|
+
);
|
|
62
|
+
expect(facetInfo?.querySelector('.facet-count')?.textContent).equal('1001');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('find the hidden facet item', async () => {
|
|
66
|
+
const selectedFacets = { ...facetGroup };
|
|
67
|
+
selectedFacets.buckets[2].state = 'hidden'; // hide 'texts' mediatype
|
|
68
|
+
|
|
69
|
+
const el = await fixture<FacetsTemplate>(
|
|
70
|
+
html`<facets-template
|
|
71
|
+
.facetGroup=${facetGroup}
|
|
72
|
+
.selectedFacets=${selectedFacets}
|
|
73
|
+
></facets-template>`
|
|
74
|
+
);
|
|
75
|
+
await el.updateComplete;
|
|
76
|
+
|
|
77
|
+
const hiddenFacet = el.shadowRoot?.querySelectorAll('.hide-facet-icon')[0];
|
|
78
|
+
|
|
79
|
+
// check title attribute for 'texts' mediatype
|
|
80
|
+
expect(hiddenFacet?.getAttribute('title')).equal('Unhide mediatype: texts');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('find the selected facet item', async () => {
|
|
84
|
+
const selectedFacets = { ...facetGroup };
|
|
85
|
+
selectedFacets.buckets[1].state = 'selected'; // select 'movies' mediatype
|
|
86
|
+
|
|
87
|
+
const el = await fixture<FacetsTemplate>(
|
|
88
|
+
html`<facets-template
|
|
89
|
+
.facetGroup=${facetGroup}
|
|
90
|
+
.selectedFacets=${selectedFacets}
|
|
91
|
+
></facets-template>`
|
|
92
|
+
);
|
|
93
|
+
await el.updateComplete;
|
|
94
|
+
|
|
95
|
+
const selectedFacet =
|
|
96
|
+
el.shadowRoot?.querySelectorAll('.hide-facet-icon')[0];
|
|
97
|
+
|
|
98
|
+
// check title attribute for 'movies' mediatype
|
|
99
|
+
expect(selectedFacet?.getAttribute('title')).equal(
|
|
100
|
+
'Hide mediatype: movies'
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { expect } from '@open-wc/testing';
|
|
2
|
+
import { getFacetOptionFromKey } from '../../src/collection-facets/facets-util';
|
|
3
|
+
|
|
4
|
+
describe('formatCount', () => {
|
|
5
|
+
// for mediatype aggregate key
|
|
6
|
+
it('Parse the aggregate key title into the human readable title', () => {
|
|
7
|
+
expect(
|
|
8
|
+
getFacetOptionFromKey('user_aggs__terms__field:mediatypeSorter__size:6')
|
|
9
|
+
).to.equal('mediatype');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// for collection aggregate key
|
|
13
|
+
it('Parse the aggregate key title into the human readable title', () => {
|
|
14
|
+
expect(
|
|
15
|
+
getFacetOptionFromKey('ser_aggs__terms__field:collection__size:12')
|
|
16
|
+
).to.equal('collection');
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/* eslint-disable import/no-duplicates */
|
|
2
|
+
import { expect, fixture, oneEvent } from '@open-wc/testing';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import type { Aggregation } from '@internetarchive/search-service';
|
|
5
|
+
import type { MoreFacetsContent } from '../../src/collection-facets/more-facets-content';
|
|
6
|
+
import '../../src/collection-facets/more-facets-content';
|
|
7
|
+
import { MockSearchService } from '../mocks/mock-search-service';
|
|
8
|
+
|
|
9
|
+
const selectedFacetsGroup = {
|
|
10
|
+
title: 'Media Type',
|
|
11
|
+
key: 'mediatype',
|
|
12
|
+
buckets: [
|
|
13
|
+
{ displayText: 'audio', key: 'audio', count: 1001, state: 'none' },
|
|
14
|
+
{ displayText: 'movies', key: 'movies', count: 901, state: 'none' },
|
|
15
|
+
{ displayText: 'texts', key: 'texts', count: 2101, state: 'none' },
|
|
16
|
+
{ displayText: 'data', key: 'data', count: 230, state: 'none' },
|
|
17
|
+
{ displayText: 'web', key: 'web', count: 453, state: 'none' },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const aggregation: Record<string, Aggregation> = {
|
|
22
|
+
'user_aggs__terms__field:collectionSorter__size:1': {
|
|
23
|
+
buckets: [
|
|
24
|
+
{
|
|
25
|
+
key: 'foo',
|
|
26
|
+
doc_count: 5,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe('More facets content', () => {
|
|
33
|
+
it('should render more facets template', async () => {
|
|
34
|
+
const el = await fixture<MoreFacetsContent>(
|
|
35
|
+
html`<more-facets-content></more-facets-content>`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
el.facetsLoading = false;
|
|
39
|
+
await el.updateComplete;
|
|
40
|
+
|
|
41
|
+
expect(el.shadowRoot?.querySelector('.facets-content')).to.exist;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should render more facets loader template', async () => {
|
|
45
|
+
const el = await fixture<MoreFacetsContent>(
|
|
46
|
+
html`<more-facets-content></more-facets-content>`
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
el.facetsLoading = true;
|
|
50
|
+
await el.updateComplete;
|
|
51
|
+
|
|
52
|
+
expect(el.shadowRoot?.querySelector('.facets-loader')).to.exist;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should render pagination for more facets', async () => {
|
|
56
|
+
const searchService = new MockSearchService();
|
|
57
|
+
|
|
58
|
+
const el = await fixture<MoreFacetsContent>(
|
|
59
|
+
html`<more-facets-content
|
|
60
|
+
.searchService=${searchService}
|
|
61
|
+
></more-facets-content>`
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
el.facetKey = 'mediatype';
|
|
65
|
+
el.facetsLoading = false;
|
|
66
|
+
el.paginationSize = 6;
|
|
67
|
+
await el.updateComplete;
|
|
68
|
+
|
|
69
|
+
expect(el.shadowRoot?.querySelectorAll('more-facets-pagination')).to.exist;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('query for more facets content using search service', async () => {
|
|
73
|
+
const searchService = new MockSearchService();
|
|
74
|
+
|
|
75
|
+
const el = await fixture<MoreFacetsContent>(
|
|
76
|
+
html`<more-facets-content
|
|
77
|
+
.searchService=${searchService}
|
|
78
|
+
></more-facets-content>`
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
el.facetKey = 'collection';
|
|
82
|
+
el.fullQuery = 'title:hello';
|
|
83
|
+
await el.updateComplete;
|
|
84
|
+
|
|
85
|
+
expect(searchService.searchParams?.query).to.equal('title:hello');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('filter raw selectedFacets object', async () => {
|
|
89
|
+
const searchService = new MockSearchService();
|
|
90
|
+
|
|
91
|
+
const el = await fixture<MoreFacetsContent>(
|
|
92
|
+
html`<more-facets-content
|
|
93
|
+
.searchService=${searchService}
|
|
94
|
+
.selectedFacets=${selectedFacetsGroup}
|
|
95
|
+
></more-facets-content>`
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
el.facetKey = 'collection';
|
|
99
|
+
el.fullQuery = 'title:hello';
|
|
100
|
+
await el.updateComplete;
|
|
101
|
+
|
|
102
|
+
expect(searchService.searchParams?.query).to.equal('title:hello');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('combine selectedFacets and aggregationFacets and render on modal', async () => {
|
|
106
|
+
const searchService = new MockSearchService();
|
|
107
|
+
|
|
108
|
+
const el = await fixture<MoreFacetsContent>(
|
|
109
|
+
html`<more-facets-content
|
|
110
|
+
.searchService=${searchService}
|
|
111
|
+
.selectedFacets=${selectedFacetsGroup}
|
|
112
|
+
.aggregations=${aggregation}
|
|
113
|
+
></more-facets-content>`
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await el.updateComplete;
|
|
117
|
+
|
|
118
|
+
expect(el.facetGroupTitle).to.equal('Collection');
|
|
119
|
+
|
|
120
|
+
const facetGroup = el.facetGroup?.shift();
|
|
121
|
+
expect(facetGroup?.key).to.equal('collection');
|
|
122
|
+
expect(facetGroup?.title).to.equal('Collection');
|
|
123
|
+
|
|
124
|
+
const bucket = facetGroup?.buckets[0];
|
|
125
|
+
expect(bucket?.key).to.equal('foo');
|
|
126
|
+
expect(bucket?.count).to.equal(5);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('page number clicked event', async () => {
|
|
130
|
+
const searchService = new MockSearchService();
|
|
131
|
+
|
|
132
|
+
const el = await fixture<MoreFacetsContent>(
|
|
133
|
+
html`<more-facets-content
|
|
134
|
+
.searchService=${searchService}
|
|
135
|
+
></more-facets-content>`
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
setTimeout(() =>
|
|
139
|
+
el.dispatchEvent(
|
|
140
|
+
new CustomEvent('pageNumberClicked', { detail: { page: 15 } })
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
const { detail } = await oneEvent(el, 'pageNumberClicked');
|
|
144
|
+
expect(detail?.page).to.equal(15);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/* eslint-disable import/no-duplicates */
|
|
2
|
+
import { expect, fixture, oneEvent } from '@open-wc/testing';
|
|
3
|
+
import { html } from 'lit';
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import '../../src/collection-facets/more-facets-pagination';
|
|
6
|
+
import type { MoreFacetsPagination } from '../../src/collection-facets/more-facets-pagination';
|
|
7
|
+
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
sinon.restore();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('More facets pagination', () => {
|
|
13
|
+
describe('5 pages or less', () => {
|
|
14
|
+
it('shows all pages', async () => {
|
|
15
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
16
|
+
html`<more-facets-pagination .size=${5}></more-facets-pagination>`
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
await el.updateComplete;
|
|
20
|
+
|
|
21
|
+
const pageButtons = el.shadowRoot?.querySelectorAll(
|
|
22
|
+
'button[data-page]'
|
|
23
|
+
) as NodeList;
|
|
24
|
+
expect(pageButtons.length).to.greaterThan(0);
|
|
25
|
+
|
|
26
|
+
pageButtons.forEach((button, index) => {
|
|
27
|
+
expect(button.textContent).to.contain(index + 1);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should render pagination template', async () => {
|
|
33
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
34
|
+
html`<more-facets-pagination .size=${10}></more-facets-pagination>`
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
await el.updateComplete;
|
|
38
|
+
|
|
39
|
+
expect(el.shadowRoot?.querySelector('.facets-pagination')).to.exist;
|
|
40
|
+
expect(el.shadowRoot?.querySelector('.arrow-icon')).to.exist;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should render page numbers', async () => {
|
|
44
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
45
|
+
html`<more-facets-pagination .size=${3}></more-facets-pagination>`
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await el.updateComplete;
|
|
49
|
+
|
|
50
|
+
const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');
|
|
51
|
+
expect(pageNumberElement).to.exist;
|
|
52
|
+
expect(pageNumberElement?.querySelectorAll('button').length).to.equal(3);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('check current page and total pages', async () => {
|
|
56
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
57
|
+
html`<more-facets-pagination
|
|
58
|
+
.size=${4}
|
|
59
|
+
.currentPage=${2}
|
|
60
|
+
></more-facets-pagination>`
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await el.updateComplete;
|
|
64
|
+
|
|
65
|
+
const pageNumberElement = el.shadowRoot?.querySelector('.page-numbers');
|
|
66
|
+
expect(pageNumberElement).to.exist;
|
|
67
|
+
expect(
|
|
68
|
+
pageNumberElement
|
|
69
|
+
?.querySelectorAll('button')[1]
|
|
70
|
+
.classList.contains('current')
|
|
71
|
+
).to.be.true;
|
|
72
|
+
expect(el.pages?.length).to.equal(4);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('get page numbers based of size and currentPage', async () => {
|
|
76
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
77
|
+
html`<more-facets-pagination
|
|
78
|
+
.size=${4}
|
|
79
|
+
.currentPage=${2}
|
|
80
|
+
></more-facets-pagination>`
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
await el.updateComplete;
|
|
84
|
+
|
|
85
|
+
expect(el.pages?.length).to.equal(4);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('Selecting a page', () => {
|
|
89
|
+
it('fires event', async () => {
|
|
90
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
91
|
+
html`<more-facets-pagination></more-facets-pagination>`
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await el.updateComplete;
|
|
95
|
+
|
|
96
|
+
setTimeout(() =>
|
|
97
|
+
el.dispatchEvent(
|
|
98
|
+
new CustomEvent('pageNumberClicked', { detail: { page: 15 } })
|
|
99
|
+
)
|
|
100
|
+
);
|
|
101
|
+
const { detail } = await oneEvent(el, 'pageNumberClicked');
|
|
102
|
+
expect(detail?.page).to.equal(15);
|
|
103
|
+
});
|
|
104
|
+
it('sets off side effects with `onChange`', async () => {
|
|
105
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
106
|
+
html`<more-facets-pagination
|
|
107
|
+
.size=${'10'}
|
|
108
|
+
.currentPage=${2}
|
|
109
|
+
></more-facets-pagination>`
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(el.currentPage).to.equal(2); // confirm current page
|
|
113
|
+
|
|
114
|
+
const fake1 = sinon.fake();
|
|
115
|
+
const fake2 = sinon.fake();
|
|
116
|
+
el.observePageCount = fake1;
|
|
117
|
+
el.emitPageClick = fake2;
|
|
118
|
+
|
|
119
|
+
// select first page button
|
|
120
|
+
const pageButton = el.shadowRoot?.querySelector(
|
|
121
|
+
'.page-numbers > button'
|
|
122
|
+
) as HTMLButtonElement;
|
|
123
|
+
// confirm button isn't selected
|
|
124
|
+
expect(pageButton.classList.contains('current')).to.be.false;
|
|
125
|
+
pageButton.click();
|
|
126
|
+
|
|
127
|
+
await el.updateComplete;
|
|
128
|
+
|
|
129
|
+
expect(fake1.callCount).to.equal(1);
|
|
130
|
+
expect(fake2.callCount).to.equal(1);
|
|
131
|
+
expect(el.currentPage).to.equal(1); // brings us back to currentPage
|
|
132
|
+
// confirm button is selected
|
|
133
|
+
expect(pageButton.classList.contains('current')).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('Using Arrows', () => {
|
|
138
|
+
it('going backwards', async () => {
|
|
139
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
140
|
+
html`<more-facets-pagination
|
|
141
|
+
.size=${'10'}
|
|
142
|
+
.currentPage=${2}
|
|
143
|
+
></more-facets-pagination>`
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(el.currentPage).to.equal(2); // confirm current page
|
|
147
|
+
|
|
148
|
+
const fake1 = sinon.fake();
|
|
149
|
+
const fake2 = sinon.fake();
|
|
150
|
+
el.observePageCount = fake1;
|
|
151
|
+
el.emitPageClick = fake2;
|
|
152
|
+
|
|
153
|
+
// select first page button
|
|
154
|
+
const rewindButton = el.shadowRoot?.querySelector(
|
|
155
|
+
'.facets-pagination > button.rewind'
|
|
156
|
+
) as HTMLButtonElement;
|
|
157
|
+
rewindButton.click();
|
|
158
|
+
|
|
159
|
+
await el.updateComplete;
|
|
160
|
+
|
|
161
|
+
expect(fake1.callCount).to.equal(1);
|
|
162
|
+
expect(fake2.callCount).to.equal(1);
|
|
163
|
+
expect(el.currentPage).to.equal(1); // brings us back 1 page
|
|
164
|
+
// confirm button is selected
|
|
165
|
+
expect(
|
|
166
|
+
(
|
|
167
|
+
el.shadowRoot?.querySelector(
|
|
168
|
+
'.page-numbers > button[data-page="1"]'
|
|
169
|
+
) as HTMLButtonElement
|
|
170
|
+
).classList.contains('current')
|
|
171
|
+
).to.be.true;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('going forwards', async () => {
|
|
175
|
+
const el = await fixture<MoreFacetsPagination>(
|
|
176
|
+
html`<more-facets-pagination
|
|
177
|
+
.size=${'10'}
|
|
178
|
+
.currentPage=${5}
|
|
179
|
+
></more-facets-pagination>`
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(el.currentPage).to.equal(5); // confirm current page
|
|
183
|
+
|
|
184
|
+
const fake1 = sinon.fake();
|
|
185
|
+
const fake2 = sinon.fake();
|
|
186
|
+
el.observePageCount = fake1;
|
|
187
|
+
el.emitPageClick = fake2;
|
|
188
|
+
|
|
189
|
+
// select first page button
|
|
190
|
+
const forwardButton = el.shadowRoot?.querySelector(
|
|
191
|
+
'.facets-pagination > button.forward'
|
|
192
|
+
) as HTMLButtonElement;
|
|
193
|
+
forwardButton.click();
|
|
194
|
+
|
|
195
|
+
await el.updateComplete;
|
|
196
|
+
|
|
197
|
+
expect(fake1.callCount).to.equal(1);
|
|
198
|
+
expect(fake2.callCount).to.equal(1);
|
|
199
|
+
expect(el.currentPage).to.equal(6); // brings us forward 1 page
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
/* eslint-disable import/no-duplicates */
|
|
2
2
|
import { expect, fixture } from '@open-wc/testing';
|
|
3
|
+
import sinon from 'sinon';
|
|
3
4
|
import { html } from 'lit';
|
|
4
5
|
import type { Aggregation } from '@internetarchive/search-service';
|
|
6
|
+
import {
|
|
7
|
+
ModalManager,
|
|
8
|
+
ModalManagerInterface,
|
|
9
|
+
} from '@internetarchive/modal-manager';
|
|
5
10
|
import type { CollectionFacets } from '../src/collection-facets';
|
|
11
|
+
import '@internetarchive/modal-manager';
|
|
6
12
|
import '../src/collection-facets';
|
|
13
|
+
import type { FacetOption } from '../src/models';
|
|
7
14
|
|
|
8
15
|
describe('Collection Facets', () => {
|
|
16
|
+
it('has loader', async () => {
|
|
17
|
+
const el = await fixture<CollectionFacets>(
|
|
18
|
+
html`<collection-facets ?facetsLoading=${true}></collection-facets>`
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(
|
|
22
|
+
el.shadowRoot?.querySelector('#container')?.classList.contains('loading')
|
|
23
|
+
).to.be.true;
|
|
24
|
+
|
|
25
|
+
el.facetsLoading = false;
|
|
26
|
+
await el.updateComplete;
|
|
27
|
+
|
|
28
|
+
expect(
|
|
29
|
+
el.shadowRoot?.querySelector('#container')?.classList.contains('loading')
|
|
30
|
+
).to.be.false;
|
|
31
|
+
});
|
|
9
32
|
it('renders aggregations as facets', async () => {
|
|
10
33
|
const el = await fixture<CollectionFacets>(
|
|
11
34
|
html`<collection-facets></collection-facets>`
|
|
@@ -24,15 +47,16 @@ describe('Collection Facets', () => {
|
|
|
24
47
|
|
|
25
48
|
el.aggregations = aggs;
|
|
26
49
|
await el.updateComplete;
|
|
27
|
-
|
|
28
50
|
const facetGroups = el.shadowRoot?.querySelectorAll('.facet-group');
|
|
29
51
|
expect(facetGroups?.length).to.equal(1);
|
|
30
52
|
|
|
31
53
|
const titleFacetGroup = facetGroups?.[0];
|
|
32
54
|
const facetGroupHeader = titleFacetGroup?.querySelector('h1');
|
|
33
55
|
expect(facetGroupHeader?.textContent?.trim()).to.equal('Subject');
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
const titleFacetRow = titleFacetGroup
|
|
57
|
+
?.querySelector('facets-template')
|
|
58
|
+
?.shadowRoot?.querySelector('.facet-row');
|
|
59
|
+
console.log(titleFacetGroup?.querySelector('facets-template'));
|
|
36
60
|
expect(titleFacetRow?.textContent?.trim()).to.satisfy((text: string) =>
|
|
37
61
|
/^foo\s*5$/.test(text)
|
|
38
62
|
);
|
|
@@ -88,9 +112,9 @@ describe('Collection Facets', () => {
|
|
|
88
112
|
el.aggregations = aggs;
|
|
89
113
|
await el.updateComplete;
|
|
90
114
|
|
|
91
|
-
const collectionName = el.shadowRoot
|
|
92
|
-
'
|
|
93
|
-
|
|
115
|
+
const collectionName = el.shadowRoot
|
|
116
|
+
?.querySelector('facets-template')
|
|
117
|
+
?.shadowRoot?.querySelector('async-collection-name');
|
|
94
118
|
expect(collectionName?.parentElement).to.be.instanceOf(HTMLAnchorElement);
|
|
95
119
|
expect(collectionName?.parentElement?.getAttribute('href')).to.equal(
|
|
96
120
|
'/details/foo'
|
|
@@ -116,48 +140,107 @@ describe('Collection Facets', () => {
|
|
|
116
140
|
el.aggregations = aggs;
|
|
117
141
|
await el.updateComplete;
|
|
118
142
|
|
|
119
|
-
const collectionName = el.shadowRoot
|
|
120
|
-
'
|
|
121
|
-
|
|
143
|
+
const collectionName = el.shadowRoot
|
|
144
|
+
?.querySelector('facets-template')
|
|
145
|
+
?.shadowRoot?.querySelector('async-collection-name');
|
|
122
146
|
expect(collectionName?.parentElement).to.not.be.instanceOf(
|
|
123
147
|
HTMLAnchorElement
|
|
124
148
|
);
|
|
125
149
|
});
|
|
126
150
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
'.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
151
|
+
describe('More Facets', () => {
|
|
152
|
+
it('Does not render < allowedFacetCount', async () => {
|
|
153
|
+
const el = await fixture<CollectionFacets>(
|
|
154
|
+
html`<collection-facets></collection-facets>`
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const aggs: Record<string, Aggregation> = {
|
|
158
|
+
'user_aggs__terms__field:subjectSorter__size:1': {
|
|
159
|
+
buckets: [
|
|
160
|
+
{
|
|
161
|
+
key: 'foo',
|
|
162
|
+
doc_count: 5,
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
el.aggregations = aggs;
|
|
169
|
+
await el.updateComplete;
|
|
170
|
+
|
|
171
|
+
const moreLink = el.shadowRoot?.querySelector('.more-link');
|
|
172
|
+
expect(moreLink).to.be.null;
|
|
173
|
+
});
|
|
174
|
+
it('Render More Facets', async () => {
|
|
175
|
+
const el = await fixture<CollectionFacets>(
|
|
176
|
+
html`<collection-facets
|
|
177
|
+
.modalManager=${new ModalManager()}
|
|
178
|
+
></collection-facets>`
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const aggs: Record<string, Aggregation> = {
|
|
182
|
+
'user_aggs__terms__field:subjectSorter__size:1': {
|
|
183
|
+
buckets: [
|
|
184
|
+
{
|
|
185
|
+
key: 'foo',
|
|
186
|
+
doc_count: 5,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
key: 'fi',
|
|
190
|
+
doc_count: 5,
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: 'fum',
|
|
194
|
+
doc_count: 5,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
key: 'flee',
|
|
198
|
+
doc_count: 5,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
key: 'wheee',
|
|
202
|
+
doc_count: 5,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
key: 'whooo',
|
|
206
|
+
doc_count: 5,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
key: 'boop',
|
|
210
|
+
doc_count: 5,
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
el.aggregations = aggs;
|
|
217
|
+
await el.updateComplete;
|
|
218
|
+
|
|
219
|
+
let eventCaught = false;
|
|
220
|
+
let eventFacet = '';
|
|
221
|
+
el.addEventListener('showMoreFacets', e => {
|
|
222
|
+
eventFacet = (e as CustomEvent).detail;
|
|
223
|
+
eventCaught = true;
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const moreLink = el.shadowRoot?.querySelector(
|
|
227
|
+
'.more-link'
|
|
228
|
+
) as HTMLButtonElement;
|
|
229
|
+
expect(moreLink).to.exist; // has link
|
|
230
|
+
|
|
231
|
+
const showModalSpy = sinon.spy(
|
|
232
|
+
el.modalManager as ModalManagerInterface,
|
|
233
|
+
'showModal'
|
|
234
|
+
);
|
|
235
|
+
// let's pop up modal
|
|
236
|
+
moreLink?.click();
|
|
237
|
+
await el.updateComplete;
|
|
238
|
+
|
|
239
|
+
expect(showModalSpy.callCount).to.equal(1);
|
|
240
|
+
expect(el.modalManager?.classList.contains('more-search-facets')).to.be
|
|
241
|
+
.true;
|
|
242
|
+
expect(eventCaught).to.be.true;
|
|
243
|
+
expect(eventFacet).to.equal('subject' as FacetOption);
|
|
244
|
+
});
|
|
162
245
|
});
|
|
163
246
|
});
|