|
1 | 1 | /* globals jsdom */ |
| 2 | +import qs from 'qs'; |
2 | 3 | import instantsearch from '../main'; |
3 | 4 | import RoutingManager from '../RoutingManager'; |
4 | 5 | import historyRouter from '../routers/history'; |
@@ -585,4 +586,73 @@ describe('RoutingManager', () => { |
585 | 586 | setWindowTitle.mockRestore(); |
586 | 587 | }); |
587 | 588 | }); |
| 589 | + |
| 590 | + describe('parseURL', () => { |
| 591 | + const createFakeUrlWithRefinements = ({ length }) => |
| 592 | + [ |
| 593 | + 'https://website.com/', |
| 594 | + Array.from( |
| 595 | + { length }, |
| 596 | + (_v, i) => `refinementList[brand][${i}]=brand-${i}` |
| 597 | + ).join('&'), |
| 598 | + ].join('?'); |
| 599 | + |
| 600 | + test('should parse refinements with more than 20 filters per category as array', () => { |
| 601 | + jsdom.reconfigure({ |
| 602 | + url: createFakeUrlWithRefinements({ length: 22 }), |
| 603 | + }); |
| 604 | + |
| 605 | + const router = historyRouter(); |
| 606 | + const parsedUrl = router.parseURL({ |
| 607 | + qsModule: qs, |
| 608 | + location: window.location, |
| 609 | + }); |
| 610 | + |
| 611 | + expect(parsedUrl.refinementList.brand).toBeInstanceOf(Array); |
| 612 | + expect(parsedUrl).toMatchInlineSnapshot(` |
| 613 | + Object { |
| 614 | + "refinementList": Object { |
| 615 | + "brand": Array [ |
| 616 | + "brand-0", |
| 617 | + "brand-1", |
| 618 | + "brand-2", |
| 619 | + "brand-3", |
| 620 | + "brand-4", |
| 621 | + "brand-5", |
| 622 | + "brand-6", |
| 623 | + "brand-7", |
| 624 | + "brand-8", |
| 625 | + "brand-9", |
| 626 | + "brand-10", |
| 627 | + "brand-11", |
| 628 | + "brand-12", |
| 629 | + "brand-13", |
| 630 | + "brand-14", |
| 631 | + "brand-15", |
| 632 | + "brand-16", |
| 633 | + "brand-17", |
| 634 | + "brand-18", |
| 635 | + "brand-19", |
| 636 | + "brand-20", |
| 637 | + "brand-21", |
| 638 | + ], |
| 639 | + }, |
| 640 | + } |
| 641 | + `); |
| 642 | + }); |
| 643 | + |
| 644 | + test('should support returning 100 refinements as array', () => { |
| 645 | + jsdom.reconfigure({ |
| 646 | + url: createFakeUrlWithRefinements({ length: 100 }), |
| 647 | + }); |
| 648 | + |
| 649 | + const router = historyRouter(); |
| 650 | + const parsedUrl = router.parseURL({ |
| 651 | + qsModule: qs, |
| 652 | + location: window.location, |
| 653 | + }); |
| 654 | + |
| 655 | + expect(parsedUrl.refinementList.brand).toBeInstanceOf(Array); |
| 656 | + }); |
| 657 | + }); |
588 | 658 | }); |
0 commit comments