@internetarchive/histogram-date-range 1.4.0 → 1.4.1

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.
@@ -3,31 +3,31 @@ import { html, fixture, expect, oneEvent, aTimeout } from '@open-wc/testing';
3
3
  import '../src/histogram-date-range';
4
4
  const SLIDER_WIDTH = 10;
5
5
  const WIDTH = 200;
6
- const subject = html `
7
- <histogram-date-range
8
- width="${WIDTH}"
9
- tooltipWidth="140"
10
- height="50"
11
- dateFormat="M/D/YYYY"
12
- minDate="1900"
13
- maxDate="12/4/2020"
14
- bins="[33, 1, 100]"
15
- >
16
- </histogram-date-range>
6
+ const subject = html `
7
+ <histogram-date-range
8
+ width="${WIDTH}"
9
+ tooltipWidth="140"
10
+ height="50"
11
+ dateFormat="M/D/YYYY"
12
+ minDate="1900"
13
+ maxDate="12/4/2020"
14
+ bins="[33, 1, 100]"
15
+ >
16
+ </histogram-date-range>
17
17
  `;
18
18
  async function createCustomElementInHTMLContainer() {
19
- document.head.insertAdjacentHTML('beforeend', `<style>
20
- html {
21
- font-size:10px;
22
- }
23
- .container {
24
- width: 400px;
25
- height: 400px;
26
- display: flex;
27
- background: #FFF6E1;
28
- justify-content: center;
29
- align-items: center;
30
- }
19
+ document.head.insertAdjacentHTML('beforeend', `<style>
20
+ html {
21
+ font-size:10px;
22
+ }
23
+ .container {
24
+ width: 400px;
25
+ height: 400px;
26
+ display: flex;
27
+ background: #FFF6E1;
28
+ justify-content: center;
29
+ align-items: center;
30
+ }
31
31
  </style>`);
32
32
  // https://open-wc.org/docs/testing/helpers/#customize-the-fixture-container
33
33
  const parentNode = document.createElement('div');
@@ -384,15 +384,15 @@ describe('HistogramDateRange', () => {
384
384
  });
385
385
  it('allows range to be pre-selected', async () => {
386
386
  var _a, _b;
387
- const el = await fixture(html `
388
- <histogram-date-range
389
- minDate="1900"
390
- maxDate="Dec 4, 2020"
391
- minSelectedDate="2012"
392
- maxSelectedDate="2019"
393
- bins="[33, 1, 100]"
394
- >
395
- </histogram-date-range>
387
+ const el = await fixture(html `
388
+ <histogram-date-range
389
+ minDate="1900"
390
+ maxDate="Dec 4, 2020"
391
+ minSelectedDate="2012"
392
+ maxSelectedDate="2019"
393
+ bins="[33, 1, 100]"
394
+ >
395
+ </histogram-date-range>
396
396
  `);
397
397
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
398
398
  expect(minDateInput.value).to.eq('2012');
@@ -401,15 +401,15 @@ describe('HistogramDateRange', () => {
401
401
  });
402
402
  it('extends the selected range when the histogram is clicked outside of the current range', async () => {
403
403
  var _a, _b;
404
- const el = await fixture(html `
405
- <histogram-date-range
406
- minDate="1900"
407
- maxDate="2020"
408
- minSelectedDate="1950"
409
- maxSelectedDate="1955"
410
- bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
411
- >
412
- </histogram-date-range>
404
+ const el = await fixture(html `
405
+ <histogram-date-range
406
+ minDate="1900"
407
+ maxDate="2020"
408
+ minSelectedDate="1950"
409
+ maxSelectedDate="1955"
410
+ bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
411
+ >
412
+ </histogram-date-range>
413
413
  `);
414
414
  const leftBarToClick = Array.from((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target'))[1]; // click on second bar to the left
415
415
  leftBarToClick.dispatchEvent(new Event('click'));
@@ -421,15 +421,15 @@ describe('HistogramDateRange', () => {
421
421
  });
422
422
  it('narrows the selected range when the histogram is clicked inside of the current range', async () => {
423
423
  var _a, _b;
424
- const el = await fixture(html `
425
- <histogram-date-range
426
- minDate="1900"
427
- maxDate="2020"
428
- minSelectedDate="1900"
429
- maxSelectedDate="2020"
430
- bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
431
- >
432
- </histogram-date-range>
424
+ const el = await fixture(html `
425
+ <histogram-date-range
426
+ minDate="1900"
427
+ maxDate="2020"
428
+ minSelectedDate="1900"
429
+ maxSelectedDate="2020"
430
+ bins="[33, 1, 1, 1, 10, 10, 1, 1, 1, 50, 100]"
431
+ >
432
+ </histogram-date-range>
433
433
  `);
434
434
  ///////////////////////////////////////////////
435
435
  // NB: the slider nearest the clicked bar moves
@@ -443,15 +443,15 @@ describe('HistogramDateRange', () => {
443
443
  });
444
444
  it('handles invalid pre-selected range by defaulting to overall max and min', async () => {
445
445
  var _a, _b;
446
- const el = await fixture(html `
447
- <histogram-date-range
448
- minDate="1900"
449
- maxDate="2020"
450
- minSelectedDate="2000xyz"
451
- maxSelectedDate="5000"
452
- bins="[33, 1, 100]"
453
- >
454
- </histogram-date-range>
446
+ const el = await fixture(html `
447
+ <histogram-date-range
448
+ minDate="1900"
449
+ maxDate="2020"
450
+ minSelectedDate="2000xyz"
451
+ maxSelectedDate="5000"
452
+ bins="[33, 1, 100]"
453
+ >
454
+ </histogram-date-range>
455
455
  `);
456
456
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
457
457
  // malformed min date defaults to overall min
@@ -462,16 +462,16 @@ describe('HistogramDateRange', () => {
462
462
  });
463
463
  it('handles year values less than 1000 correctly', async () => {
464
464
  var _a, _b;
465
- const el = await fixture(html `
466
- <histogram-date-range
467
- dateFormat="M/D/YYYY"
468
- minDate="-2000"
469
- maxDate="2000"
470
- minSelectedDate="-500"
471
- maxSelectedDate="500"
472
- bins="[33, 1, 100]"
473
- >
474
- </histogram-date-range>
465
+ const el = await fixture(html `
466
+ <histogram-date-range
467
+ dateFormat="M/D/YYYY"
468
+ minDate="-2000"
469
+ maxDate="2000"
470
+ minSelectedDate="-500"
471
+ maxSelectedDate="500"
472
+ bins="[33, 1, 100]"
473
+ >
474
+ </histogram-date-range>
475
475
  `);
476
476
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
477
477
  expect(minDateInput.value).to.eq('1/1/-500');
@@ -480,23 +480,23 @@ describe('HistogramDateRange', () => {
480
480
  });
481
481
  it('handles missing data', async () => {
482
482
  var _a, _b;
483
- let el = await fixture(html `<histogram-date-range>
484
- minDate="1900" maxDate="2020" bins=""
483
+ let el = await fixture(html `<histogram-date-range>
484
+ minDate="1900" maxDate="2020" bins=""
485
485
  </histogram-date-range>`);
486
486
  expect((_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.innerHTML).to.contain('no data');
487
- el = await fixture(html `<histogram-date-range
488
- minDate="1900"
489
- maxDate="2020"
490
- bins="[]"
491
- missingDataMessage="no data available"
487
+ el = await fixture(html `<histogram-date-range
488
+ minDate="1900"
489
+ maxDate="2020"
490
+ bins="[]"
491
+ missingDataMessage="no data available"
492
492
  ></histogram-date-range>`);
493
493
  expect((_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.innerHTML).to.contain('no data available');
494
494
  });
495
495
  it('correctly displays data consisting of a single bin', async () => {
496
496
  var _a;
497
- const el = await fixture(html `
498
- <histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
499
- </histogram-date-range>
497
+ const el = await fixture(html `
498
+ <histogram-date-range minDate="2020" maxDate="2020" bins="[50]">
499
+ </histogram-date-range>
500
500
  `);
501
501
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
502
502
  const heights = Array.from(bars, b => b.height.baseVal.value);
@@ -504,9 +504,9 @@ describe('HistogramDateRange', () => {
504
504
  });
505
505
  it('correctly displays small diff between max and min values', async () => {
506
506
  var _a;
507
- const el = await fixture(html `
508
- <histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
509
- </histogram-date-range>
507
+ const el = await fixture(html `
508
+ <histogram-date-range bins="[1519,2643,1880,2041,1638,1441]">
509
+ </histogram-date-range>
510
510
  `);
511
511
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar');
512
512
  const heights = Array.from(bars, b => b.height.baseVal.value);
@@ -514,15 +514,15 @@ describe('HistogramDateRange', () => {
514
514
  });
515
515
  it('correctly aligns bins to exact month boundaries when binSnapping=month', async () => {
516
516
  var _a;
517
- const el = await fixture(html `
518
- <histogram-date-range
519
- binSnapping="month"
520
- dateFormat="YYYY-MM"
521
- tooltipDateFormat="MMM YYYY"
522
- minDate="2020-01"
523
- maxDate="2021-12"
524
- bins="[10,20,30,40,50,60,70,80]"
525
- ></histogram-date-range>
517
+ const el = await fixture(html `
518
+ <histogram-date-range
519
+ binSnapping="month"
520
+ dateFormat="YYYY-MM"
521
+ tooltipDateFormat="MMM YYYY"
522
+ minDate="2020-01"
523
+ maxDate="2021-12"
524
+ bins="[10,20,30,40,50,60,70,80]"
525
+ ></histogram-date-range>
526
526
  `);
527
527
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
528
528
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -539,15 +539,15 @@ describe('HistogramDateRange', () => {
539
539
  });
540
540
  it('correctly handles month snapping for years 0-99', async () => {
541
541
  var _a;
542
- const el = await fixture(html `
543
- <histogram-date-range
544
- binSnapping="month"
545
- dateFormat="YYYY-MM"
546
- tooltipDateFormat="MMM YYYY"
547
- minDate="0050-01"
548
- maxDate="0065-12"
549
- bins="[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]"
550
- ></histogram-date-range>
542
+ const el = await fixture(html `
543
+ <histogram-date-range
544
+ binSnapping="month"
545
+ dateFormat="YYYY-MM"
546
+ tooltipDateFormat="MMM YYYY"
547
+ minDate="0050-01"
548
+ maxDate="0065-12"
549
+ bins="[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]"
550
+ ></histogram-date-range>
551
551
  `);
552
552
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
553
553
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -588,13 +588,13 @@ describe('HistogramDateRange', () => {
588
588
  });
589
589
  it('correctly aligns bins to exact year boundaries when binSnapping=year', async () => {
590
590
  var _a;
591
- const el = await fixture(html `
592
- <histogram-date-range
593
- binSnapping="year"
594
- minDate="2000"
595
- maxDate="2019"
596
- bins="[10,20,30,40,50,60,70,80,90,100]"
597
- ></histogram-date-range>
591
+ const el = await fixture(html `
592
+ <histogram-date-range
593
+ binSnapping="year"
594
+ minDate="2000"
595
+ maxDate="2019"
596
+ bins="[10,20,30,40,50,60,70,80,90,100]"
597
+ ></histogram-date-range>
598
598
  `);
599
599
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
600
600
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -613,14 +613,14 @@ describe('HistogramDateRange', () => {
613
613
  });
614
614
  it('correctly handles year snapping for years 0-99', async () => {
615
615
  var _a;
616
- const el = await fixture(html `
617
- <histogram-date-range
618
- binSnapping="year"
619
- dateFormat="YYYY"
620
- minDate="0020"
621
- maxDate="0025"
622
- bins="[1,2,3,4,5,6]"
623
- ></histogram-date-range>
616
+ const el = await fixture(html `
617
+ <histogram-date-range
618
+ binSnapping="year"
619
+ dateFormat="YYYY"
620
+ minDate="0020"
621
+ maxDate="0025"
622
+ bins="[1,2,3,4,5,6]"
623
+ ></histogram-date-range>
624
624
  `);
625
625
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
626
626
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -628,14 +628,14 @@ describe('HistogramDateRange', () => {
628
628
  });
629
629
  it('does not duplicate start/end date in tooltips when representing a single year', async () => {
630
630
  var _a;
631
- const el = await fixture(html `
632
- <histogram-date-range
633
- binSnapping="year"
634
- dateFormat="YYYY"
635
- minDate="2001"
636
- maxDate="2005"
637
- bins="[10,20,30,40,50]"
638
- ></histogram-date-range>
631
+ const el = await fixture(html `
632
+ <histogram-date-range
633
+ binSnapping="year"
634
+ dateFormat="YYYY"
635
+ minDate="2001"
636
+ maxDate="2005"
637
+ bins="[10,20,30,40,50]"
638
+ ></histogram-date-range>
639
639
  `);
640
640
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
641
641
  const tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -643,13 +643,13 @@ describe('HistogramDateRange', () => {
643
643
  });
644
644
  it('falls back to default date format for tooltips if no tooltip date format provided', async () => {
645
645
  var _a;
646
- const el = await fixture(html `
647
- <histogram-date-range
648
- binSnapping="year"
649
- minDate="2001"
650
- maxDate="2005"
651
- bins="[10,20,30,40,50]"
652
- ></histogram-date-range>
646
+ const el = await fixture(html `
647
+ <histogram-date-range
648
+ binSnapping="year"
649
+ minDate="2001"
650
+ maxDate="2005"
651
+ bins="[10,20,30,40,50]"
652
+ ></histogram-date-range>
653
653
  `);
654
654
  const bars = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.bar-pointer-target');
655
655
  let tooltips = Array.from(bars, b => b.dataset.tooltip);
@@ -684,14 +684,14 @@ describe('HistogramDateRange', () => {
684
684
  });
685
685
  it('has a disabled state', async () => {
686
686
  var _a, _b, _c;
687
- const el = await fixture(html `
688
- <histogram-date-range
689
- minDate="1900"
690
- maxDate="2020"
691
- disabled
692
- bins="[33, 1, 100]"
693
- >
694
- </histogram-date-range>
687
+ const el = await fixture(html `
688
+ <histogram-date-range
689
+ minDate="1900"
690
+ maxDate="2020"
691
+ disabled
692
+ bins="[33, 1, 100]"
693
+ >
694
+ </histogram-date-range>
695
695
  `);
696
696
  expect((_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.inner-container')) === null || _b === void 0 ? void 0 : _b.classList.contains('disabled')).to.eq(true);
697
697
  const minSlider = (_c = el.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelector('#slider-min');
@@ -709,33 +709,81 @@ describe('HistogramDateRange', () => {
709
709
  });
710
710
  it('has a loading state with an activity indicator', async () => {
711
711
  var _a, _b, _c, _d;
712
- const el = await fixture(html `
713
- <histogram-date-range
714
- minDate="1900"
715
- maxDate="2020"
716
- loading
717
- bins="[33, 1, 100]"
718
- >
719
- </histogram-date-range>
712
+ const el = await fixture(html `
713
+ <histogram-date-range
714
+ minDate="1900"
715
+ maxDate="2020"
716
+ loading
717
+ bins="[33, 1, 100]"
718
+ >
719
+ </histogram-date-range>
720
720
  `);
721
721
  expect((_d = (_c = (_b = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('ia-activity-indicator')) === null || _b === void 0 ? void 0 : _b.attributes) === null || _c === void 0 ? void 0 : _c.getNamedItem('mode')) === null || _d === void 0 ? void 0 : _d.value).to.eq('processing');
722
722
  });
723
723
  it('can use LitElement bound properties', async () => {
724
724
  var _a, _b;
725
- const el = await fixture(html `
726
- <histogram-date-range
727
- .minDate=${1900}
728
- .maxDate=${'Dec 4, 2020'}
729
- .minSelectedDate=${2012}
730
- .maxSelectedDate=${2019}
731
- .bins=${[33, 1, 100]}
732
- >
733
- </histogram-date-range>
725
+ const el = await fixture(html `
726
+ <histogram-date-range
727
+ .minDate=${1900}
728
+ .maxDate=${'Dec 4, 2020'}
729
+ .minSelectedDate=${2012}
730
+ .maxSelectedDate=${2019}
731
+ .bins=${[33, 1, 100]}
732
+ >
733
+ </histogram-date-range>
734
734
  `);
735
735
  const minDateInput = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('#date-min');
736
736
  expect(minDateInput.value).to.eq('2012');
737
737
  const maxDateInput = (_b = el.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector('#date-max');
738
738
  expect(maxDateInput.value).to.eq('2019');
739
739
  });
740
+ it('SVG accessbility - dynamic title for MIN and MAX date', async () => {
741
+ var _a, _b;
742
+ const el = await fixture(html `
743
+ <histogram-date-range
744
+ minDate="1900"
745
+ maxDate="2020"
746
+ .bins=${[33, 1, 100]}
747
+ >
748
+ </histogram-date-range>
749
+ `);
750
+ const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
751
+ expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates from 1900 to 2020');
752
+ });
753
+ it('SVG accessbility - dynamic title for MIN date', async () => {
754
+ var _a, _b;
755
+ const el = await fixture(html `
756
+ <histogram-date-range minDate="1900" .bins=${[33, 1, 100]}>
757
+ </histogram-date-range>
758
+ `);
759
+ const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
760
+ expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates from 1900');
761
+ });
762
+ it('SVG accessbility - dynamic title for MAX date', async () => {
763
+ var _a, _b;
764
+ const el = await fixture(html `
765
+ <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
766
+ </histogram-date-range>
767
+ `);
768
+ const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
769
+ expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates up to 2020');
770
+ });
771
+ it('SVG accessbility - dynamic title for all dates', async () => {
772
+ var _a, _b;
773
+ const el = await fixture(html `
774
+ <histogram-date-range .bins=${[33, 1, 100]}> </histogram-date-range>
775
+ `);
776
+ const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
777
+ expect((_b = svg.querySelector('title')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('Filter results for dates');
778
+ });
779
+ it('SVG accessibility - dynamic desc', async () => {
780
+ var _a, _b;
781
+ const el = await fixture(html `
782
+ <histogram-date-range maxDate="2020" .bins=${[33, 1, 100]}>
783
+ </histogram-date-range>
784
+ `);
785
+ const svg = (_a = el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
786
+ expect((_b = svg.querySelector('desc')) === null || _b === void 0 ? void 0 : _b.textContent).to.equal('This histogram shows the distribution of dates up to 2020');
787
+ });
740
788
  });
741
789
  //# sourceMappingURL=histogram-date-range.test.js.map