Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@wordpress/icons": "11.5.0",
"@wordpress/interactivity": "6.37.0",
"embla-carousel": "8.6.0",
"embla-carousel-auto-scroll": "8.6.0",
"embla-carousel-autoplay": "8.6.0",
"embla-carousel-fade": "8.6.0",
"react": "^18.3.1",
Expand Down
16 changes: 16 additions & 0 deletions src/blocks/carousel/__tests__/edit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ const createAttributes = (): CarouselAttributes => ( {
ariaLabel: 'Carousel',
slidesToScroll: '1',
slideGap: 0,
autoScroll: false,
autoScrollSpeed: 2,
autoScrollDirection: 'forward' as const,
autoScrollStartDelay: 1000,
autoScrollStopOnInteraction: true,
autoScrollStopOnMouseEnter: false,
} );

describe( 'Carousel Edit setup flow', () => {
Expand Down Expand Up @@ -220,6 +226,16 @@ describe( 'Carousel Edit setup flow', () => {
}
} );

it( 'should have correct default autoScroll attributes', () => {
const attributes = createAttributes();
expect( attributes.autoScroll ).toBe( false );
expect( attributes.autoScrollSpeed ).toBe( 2 );
expect( attributes.autoScrollDirection ).toBe( 'forward' );
expect( attributes.autoScrollStartDelay ).toBe( 1000 );
expect( attributes.autoScrollStopOnInteraction ).toBe( true );
expect( attributes.autoScrollStopOnMouseEnter ).toBe( false );
} );

it( 'renders a Transition select and hides slide-only controls when fade is active', () => {
render(
<Edit
Expand Down
28 changes: 28 additions & 0 deletions src/blocks/carousel/__tests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe( 'CarouselAttributes Type', () => {
ariaLabel: 'Image carousel',
slideGap: 16,
slidesToScroll: '1',
autoScroll: false,
autoScrollSpeed: 2,
autoScrollDirection: 'forward',
autoScrollStartDelay: 1000,
autoScrollStopOnInteraction: true,
autoScrollStopOnMouseEnter: false,
};

expect( attributes ).toBeDefined();
Expand All @@ -60,6 +66,12 @@ describe( 'CarouselAttributes Type', () => {
ariaLabel: '',
slideGap: 0,
slidesToScroll: 'auto',
autoScroll: false,
autoScrollSpeed: 2,
autoScrollDirection: 'forward',
autoScrollStartDelay: 1000,
autoScrollStopOnInteraction: true,
autoScrollStopOnMouseEnter: false,
};

// Verify all keys exist
Expand Down Expand Up @@ -268,6 +280,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 2,
ariaLabelPattern: 'Go to slide %d',
autoScroll: false,
};

expect( context.autoplay ).toBe( false );
Expand Down Expand Up @@ -295,6 +308,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0.5,
slideCount: 3,
ariaLabelPattern: 'Slide %d of 3',
autoScroll: false,
};

expect( context.autoplay ).not.toBe( false );
Expand Down Expand Up @@ -323,6 +337,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 3,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.selectedIndex ).toBe( 0 );
Expand All @@ -344,6 +359,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0.5,
slideCount: 3,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.selectedIndex ).toBe( 1 );
Expand All @@ -365,6 +381,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 1,
slideCount: 3,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.selectedIndex ).toBe( 2 );
Expand All @@ -386,6 +403,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 1,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.scrollSnaps ).toHaveLength( 1 );
Expand All @@ -409,6 +427,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 1,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.timerIterationId ).toBe( 5 );
Expand All @@ -432,6 +451,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.timerIterationId ).toBe( 0 );
Expand All @@ -456,6 +476,7 @@ describe( 'CarouselContext Type', () => {
slideCount: 0,
ariaLabelPattern: 'Slide %d',
ref: element,
autoScroll: false,
};

expect( context.ref ).toBe( element );
Expand All @@ -477,6 +498,7 @@ describe( 'CarouselContext Type', () => {
slideCount: 0,
ariaLabelPattern: 'Slide %d',
ref: null,
autoScroll: false,
};

expect( context.ref ).toBeNull();
Expand All @@ -496,6 +518,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.ref ).toBeUndefined();
Expand All @@ -520,6 +543,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.options.slidesToScroll ).toBe( 2 );
Expand All @@ -542,6 +566,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.options.slidesToScroll ).toBe( 'auto' );
Expand Down Expand Up @@ -571,6 +596,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: pattern,
autoScroll: false,
};

expect( context.ariaLabelPattern ).toBe( pattern );
Expand All @@ -593,6 +619,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 0,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.scrollSnaps ).toHaveLength( 0 );
Expand Down Expand Up @@ -620,6 +647,7 @@ describe( 'CarouselContext Type', () => {
scrollProgress: 0,
slideCount: 5,
ariaLabelPattern: 'Slide %d',
autoScroll: false,
};

expect( context.scrollSnaps ).toHaveLength( 5 );
Expand Down
31 changes: 31 additions & 0 deletions src/blocks/carousel/__tests__/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const createMockContext = (
scrollProgress: 0,
slideCount: 3,
ariaLabelPattern: 'Go to slide %d',
autoScroll: false,
...overrides,
} );

Expand Down Expand Up @@ -1094,4 +1095,34 @@ describe( 'Edge Cases and Error Handling', () => {
expect( mockContext.scrollSnaps ).toHaveLength( 100 );
expect( mockContext.selectedIndex ).toBe( 50 );
} );

it( 'should handle autoScroll configuration', () => {
const mockContextWithAutoScroll = createMockContext( {
autoScroll: {
speed: 3,
direction: 'forward',
startDelay: 500,
stopOnInteraction: false,
stopOnMouseEnter: true,
stopOnFocusIn: false,
},
} );

expect( mockContextWithAutoScroll.autoScroll ).toEqual( {
speed: 3,
direction: 'forward',
startDelay: 500,
stopOnInteraction: false,
stopOnMouseEnter: true,
stopOnFocusIn: false,
} );
} );

it( 'should handle autoScroll disabled', () => {
const mockContext = createMockContext( {
autoScroll: false,
} );

expect( mockContext.autoScroll ).toBe( false );
} );
} );
25 changes: 25 additions & 0 deletions src/blocks/carousel/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@
"slidesToScroll": {
"type": "string",
"default": "1"
},
"autoScroll": {
"type": "boolean",
"default": false
},
"autoScrollSpeed": {
"type": "number",
"default": 2
},
"autoScrollDirection": {
"type": "string",
"default": "forward",
"enum": ["forward", "backward"]
},
"autoScrollStartDelay": {
"type": "number",
"default": 1000
},
"autoScrollStopOnInteraction": {
"type": "boolean",
"default": true
},
"autoScrollStopOnMouseEnter": {
"type": "boolean",
"default": false
}
},
"editorScript": "file:./index.js",
Expand Down
Loading