|
1 | 1 | import { newSpecPage } from '@stencil/core/testing'; |
| 2 | +import * as helpers from '@utils/helpers'; |
2 | 3 | import * as logging from '@utils/logging'; |
3 | 4 |
|
4 | 5 | import { Gallery } from './gallery'; |
@@ -42,6 +43,21 @@ describe('gallery', () => { |
42 | 43 | jest.restoreAllMocks(); |
43 | 44 | }); |
44 | 45 | describe('gallery: columns', () => { |
| 46 | + describe('onColumnsOrGapChanged()', () => { |
| 47 | + it('should call syncResponsiveLayout when columns or gap change', () => { |
| 48 | + const syncResponsiveLayoutSpy = jest.spyOn(sharedGallery as any, 'syncResponsiveLayout'); |
| 49 | + const warnUnusedOrderSpy = jest.spyOn(sharedGallery as any, 'warnUnusedOrder'); |
| 50 | + |
| 51 | + (sharedGallery as any).onColumnsOrGapChanged(); |
| 52 | + |
| 53 | + expect(syncResponsiveLayoutSpy).toHaveBeenCalledTimes(1); |
| 54 | + expect(warnUnusedOrderSpy).not.toHaveBeenCalled(); |
| 55 | + |
| 56 | + syncResponsiveLayoutSpy.mockRestore(); |
| 57 | + warnUnusedOrderSpy.mockRestore(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
45 | 61 | describe('sanitizeColumns()', () => { |
46 | 62 | it('should return undefined for invalid values', () => { |
47 | 63 | const invalidValues = [undefined, NaN, Infinity, '0', '-1', '0.5', 'invalid', '', ' ', 0, -1, 0.5]; |
@@ -673,15 +689,24 @@ describe('gallery', () => { |
673 | 689 | }); |
674 | 690 | }); |
675 | 691 |
|
676 | | - describe('propertiesChanged()', () => { |
677 | | - it('should update responsive styles and schedule masonry resize when layout changes', () => { |
678 | | - const updateResponsiveStylesSpy = jest.spyOn(sharedGallery as any, 'updateResponsiveStyles'); |
679 | | - const scheduleMasonryResizeSpy = jest.spyOn(sharedGallery as any, 'scheduleMasonryResize'); |
| 692 | + describe('onLayoutOrOrderChanged()', () => { |
| 693 | + it('should call syncResponsiveLayout and warnUnusedOrder when layout or order change', () => { |
| 694 | + const syncResponsiveLayoutSpy = jest.spyOn(sharedGallery as any, 'syncResponsiveLayout'); |
| 695 | + const warnUnusedOrderSpy = jest.spyOn(sharedGallery as any, 'warnUnusedOrder'); |
| 696 | + const rafSpy = jest.spyOn(helpers, 'raf').mockImplementation((cb) => { |
| 697 | + cb(0); |
| 698 | + return 0; |
| 699 | + }); |
680 | 700 |
|
681 | | - (sharedGallery as any).propertiesChanged(); |
| 701 | + (sharedGallery as any).onLayoutOrOrderChanged(); |
682 | 702 |
|
683 | | - expect(updateResponsiveStylesSpy).toHaveBeenCalledWith(true); |
684 | | - expect(scheduleMasonryResizeSpy).toHaveBeenCalled(); |
| 703 | + expect(syncResponsiveLayoutSpy).toHaveBeenCalledTimes(1); |
| 704 | + expect(rafSpy).toHaveBeenCalledTimes(1); |
| 705 | + expect(warnUnusedOrderSpy).toHaveBeenCalledTimes(1); |
| 706 | + |
| 707 | + syncResponsiveLayoutSpy.mockRestore(); |
| 708 | + warnUnusedOrderSpy.mockRestore(); |
| 709 | + rafSpy.mockRestore(); |
685 | 710 | }); |
686 | 711 | }); |
687 | 712 |
|
|
0 commit comments